diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
index 1d8e320b..c91ebe6e 100644
--- a/fs/proc/Kconfig
+++ b/fs/proc/Kconfig
@@ -4,3 +4,8 @@ config FS_PROC
depends on FS_VFS
help
Answer Y to enable LiteOS support proc filesystem.
+
+config PROC_PROCESS_DIR
+ bool "Enable Process mount directory"
+ default n
+ depends on FS_PROC
diff --git a/fs/proc/include/internal.h b/fs/proc/include/internal.h
index 0cf4b35a..70464f85 100644
--- a/fs/proc/include/internal.h
+++ b/fs/proc/include/internal.h
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -45,6 +45,12 @@ extern "C" {
extern spinlock_t procfsLock;
extern bool procfsInit;
+#ifdef LOSCFG_PROC_PROCESS_DIR
+int ProcCreateProcessDir(UINT32 pid, uintptr_t process);
+
+void ProcFreeProcessDir(struct ProcDirEntry *processDir);
+#endif
+
void ProcPmInit(void);
void ProcVmmInit(void);
diff --git a/fs/proc/include/proc_fs.h b/fs/proc/include/proc_fs.h
index ee8fafd1..89e55671 100644
--- a/fs/proc/include/proc_fs.h
+++ b/fs/proc/include/proc_fs.h
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -82,6 +82,7 @@ typedef unsigned short fmode_t;
#define FMODE_READ ((fmode_t)0x1)
struct ProcFile;
+struct ProcDirEntry;
struct ProcFileOperations {
char *name;
@@ -89,6 +90,7 @@ struct ProcFileOperations {
int (*open)(struct Vnode *vnode, struct ProcFile *pf);
int (*release)(struct Vnode *vnode, struct ProcFile *pf);
int (*read)(struct SeqBuf *m, void *v);
+ ssize_t (*readLink)(struct ProcDirEntry *pde, char *buf, size_t bufLen);
};
struct ProcDirEntry {
@@ -244,6 +246,35 @@ extern struct ProcDirEntry *ProcMkdir(const char *name, struct ProcDirEntry *par
extern struct ProcDirEntry *ProcCreate(const char *name, mode_t mode,
struct ProcDirEntry *parent, const struct ProcFileOperations *procFops);
+/**
+ * @ingroup procfs
+ * @brief create a proc node
+ *
+ * @par Description:
+ * This API is used to create the node by 'name' and parent vnode,
+ * And assignment operation function
+ *
+ * @attention
+ *
+ * - This interface should be called after system initialization.
+ * - The parameter name should be a valid string.
+ *
+ *
+ * @param name [IN] Type #const char * The name of the node to be created.
+ * @param mode [IN] Type #mode_t the mode of create's node.
+ * @param parent [IN] Type #struct ProcDirEntry * the parent node of the node to be created.
+ * @param procFops [IN] Type #const struct ProcFileOperations * operation function of the node.
+ * @param data [IN] Type #void * data of the node.
+ *
+ * @retval #NULL Create failed.
+ * @retval #ProcDirEntry* Create successfully.
+ * @par Dependency:
+ * - proc_fs.h: the header file that contains the API declaration.
+ * @see
+ *
+ */
+extern struct ProcDirEntry *ProcCreateData(const char *name, mode_t mode, struct ProcDirEntry *parent,
+ const struct ProcFileOperations *procFileOps, void *data);
/**
* @ingroup procfs
* @brief init proc fs
diff --git a/fs/proc/os_adapt/proc_vfs.c b/fs/proc/os_adapt/proc_vfs.c
index 3876967c..fb404073 100644
--- a/fs/proc/os_adapt/proc_vfs.c
+++ b/fs/proc/os_adapt/proc_vfs.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2021-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -278,8 +278,10 @@ int VfsProcfsOpendir(struct Vnode *node, struct fs_dirent_s *dir)
return -EINVAL;
}
pde->pdirCurrent = pde->subdir;
+ if (pde->pf == NULL) {
+ return -EINVAL;
+ }
pde->pf->fPos = 0;
-
return LOS_OK;
}
@@ -335,6 +337,20 @@ int VfsProcfsClosedir(struct Vnode *vp, struct fs_dirent_s *dir)
return LOS_OK;
}
+ssize_t VfsProcfsReadlink(struct Vnode *vnode, char *buffer, size_t bufLen)
+{
+ int result = -EINVAL;
+ if (vnode == NULL) {
+ return result;
+ }
+
+ struct ProcDirEntry *pde = VnodeToEntry(vnode);
+ if ((pde->procFileOps != NULL) && (pde->procFileOps->readLink != NULL)) {
+ result = pde->procFileOps->readLink(pde, buffer, bufLen);
+ }
+ return result;
+}
+
const struct MountOps procfs_operations = {
.Mount = VfsProcfsMount,
.Unmount = NULL,
@@ -347,7 +363,8 @@ static struct VnodeOps g_procfsVops = {
.Readdir = VfsProcfsReaddir,
.Opendir = VfsProcfsOpendir,
.Closedir = VfsProcfsClosedir,
- .Truncate = VfsProcfsTruncate
+ .Truncate = VfsProcfsTruncate,
+ .Readlink = VfsProcfsReadlink,
};
static struct file_operations_vfs g_procfsFops = {
diff --git a/fs/proc/os_adapt/process_proc.c b/fs/proc/os_adapt/process_proc.c
index 65fe78bb..9ec05974 100644
--- a/fs/proc/os_adapt/process_proc.c
+++ b/fs/proc/os_adapt/process_proc.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -32,8 +32,186 @@
#include
#include
#include "proc_fs.h"
+#include "internal.h"
#include "los_process_pri.h"
+#ifdef LOSCFG_PROC_PROCESS_DIR
+typedef enum {
+ PROC_PID,
+} ProcessDataType;
+
+struct ProcProcess {
+ char *name;
+ mode_t mode;
+ int type;
+ const struct ProcFileOperations *fileOps;
+};
+
+struct ProcessData {
+ uintptr_t process;
+ unsigned int type;
+};
+
+#define PROC_PID_PRIVILEGE 7
+#define PROC_PID_DIR_LEN 100
+#ifdef LOSCFG_KERNEL_CONTAINER
+static ssize_t ProcessContainerLink(unsigned int containerID, ContainerType type, char *buffer, size_t bufLen)
+{
+ ssize_t count = -1;
+ if (type == PID_CONTAINER) {
+ count = snprintf_s(buffer, bufLen, bufLen - 1, "'pid:[%u]'", containerID);
+ } else if (type == UTS_CONTAINER) {
+ count = snprintf_s(buffer, bufLen, bufLen - 1, "'uts:[%u]'", containerID);
+ }
+
+ if (count < 0) {
+ return -EBADF;
+ }
+ return count;
+}
+
+static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer, size_t bufLen)
+{
+ ssize_t count;
+ unsigned int intSave;
+ if (entry == NULL) {
+ return -EINVAL;
+ }
+ struct ProcessData *data = (struct ProcessData *)entry->data;
+ if (data == NULL) {
+ return -EINVAL;
+ }
+ LosProcessCB *processCB = (LosProcessCB *)data->process;
+ SCHEDULER_LOCK(intSave);
+ UINT32 containerID = OsGetContainerID(processCB->container, (ContainerType)data->type);
+ SCHEDULER_UNLOCK(intSave);
+ if (containerID != OS_INVALID_VALUE) {
+ return ProcessContainerLink(containerID, (ContainerType)data->type, buffer, bufLen);
+ }
+ count = strlen("(unknown)");
+ if (memcpy_s(buffer, bufLen, "(unknown)", count + 1) != EOK) {
+ return -EBADF;
+ }
+ return count;
+}
+
+static const struct ProcFileOperations PID_CONTAINER_FOPS = {
+ .readLink = ProcessContainerReadLink,
+};
+#endif /* LOSCFG_KERNEL_CONTAINER */
+
+static int ProcProcessRead(struct SeqBuf *m, void *v)
+{
+ (void)m;
+ (void)v;
+ return -EINVAL;
+}
+
+static const struct ProcFileOperations PID_FOPS = {
+ .read = ProcProcessRead,
+};
+
+static struct ProcProcess g_procProcess[] = {
+ {
+ .name = NULL,
+ .mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH,
+ .type = PROC_PID,
+ .fileOps = &PID_FOPS
+
+ },
+#ifdef LOSCFG_KERNEL_CONTAINER
+ {
+ .name = "container",
+ .mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH,
+ .type = CONTAINER,
+ .fileOps = &PID_CONTAINER_FOPS
+
+ },
+#ifdef LOSCFG_PID_CONTAINER
+ {
+ .name = "container/pid",
+ .mode = S_IFLNK,
+ .type = PID_CONTAINER,
+ .fileOps = &PID_CONTAINER_FOPS
+ },
+#endif
+#ifdef LOSCFG_UTS_CONTAINER
+ {
+ .name = "container/uts",
+ .mode = S_IFLNK,
+ .type = UTS_CONTAINER,
+ .fileOps = &PID_CONTAINER_FOPS
+ },
+#endif
+#endif
+};
+
+void ProcFreeProcessDir(struct ProcDirEntry *processDir)
+{
+ if (processDir == NULL) {
+ return;
+ }
+ RemoveProcEntry(processDir->name, NULL);
+}
+
+static struct ProcDirEntry *ProcCreatePorcess(UINT32 pid, struct ProcProcess *porcess, uintptr_t processCB)
+{
+ int ret;
+ char pidName[PROC_PID_DIR_LEN] = {0};
+ struct ProcessData *data = (struct ProcessData *)malloc(sizeof(struct ProcessData));
+ if (data == NULL) {
+ return NULL;
+ }
+ if (porcess->name != NULL) {
+ ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u/%s", pid, porcess->name);
+ } else {
+ ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u", pid);
+ }
+ if (ret < 0) {
+ free(data);
+ return NULL;
+ }
+
+ data->process = processCB;
+ data->type = porcess->type;
+ struct ProcDirEntry *container = ProcCreateData(pidName, porcess->mode, NULL, porcess->fileOps, (void *)data);
+ if (container == NULL) {
+ free(data);
+ PRINT_ERR("create /proc/%s error!\n", pidName);
+ return NULL;
+ }
+ return container;
+}
+
+int ProcCreateProcessDir(UINT32 pid, uintptr_t process)
+{
+ unsigned int intSave;
+ struct ProcDirEntry *pidDir = NULL;
+ for (int index = 0; index < (sizeof(g_procProcess) / sizeof(struct ProcProcess)); index++) {
+ struct ProcProcess *procProcess = &g_procProcess[index];
+ struct ProcDirEntry *dir = ProcCreatePorcess(pid, procProcess, process);
+ if (dir == NULL) {
+ PRINT_ERR("create /proc/%s error!\n", procProcess->name);
+ goto CREATE_ERROR;
+ }
+ if (index == 0) {
+ pidDir = dir;
+ }
+ }
+
+ SCHEDULER_LOCK(intSave);
+ ((LosProcessCB *)process)->procDir = pidDir;
+ SCHEDULER_UNLOCK(intSave);
+ return 0;
+
+CREATE_ERROR:
+ if (pidDir != NULL) {
+ RemoveProcEntry(pidDir->name, NULL);
+ }
+ return -1;
+}
+#endif /* LOSCFG_PROC_PROCESS_DIR */
+
static int ProcessProcFill(struct SeqBuf *m, void *v)
{
(void)v;
@@ -52,7 +230,13 @@ void ProcProcessInit(void)
PRINT_ERR("create /proc/process error!\n");
return;
}
-
pde->procFileOps = &PROCESS_PROC_FOPS;
-}
+#ifdef LOSCFG_PROC_PROCESS_DIR
+ int ret = ProcCreateProcessDir(OS_USER_ROOT_PROCESS_ID, (uintptr_t)OsGetUserInitProcess());
+ if (ret < 0) {
+ PRINT_ERR("Create proc process %d dir failed!\n", OS_USER_ROOT_PROCESS_ID);
+ }
+#endif
+ return;
+}
diff --git a/fs/proc/src/proc_file.c b/fs/proc/src/proc_file.c
index e26283e4..750616a1 100644
--- a/fs/proc/src/proc_file.c
+++ b/fs/proc/src/proc_file.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -351,7 +351,11 @@ static struct ProcDirEntry *ProcCreateFile(struct ProcDirEntry *parent, const ch
}
pn->procFileOps = procFileOps;
- pn->type = VNODE_TYPE_REG;
+ if (S_ISLNK(mode)) {
+ pn->type = VNODE_TYPE_LNK;
+ } else {
+ pn->type = VNODE_TYPE_REG;
+ }
ret = ProcAddNode(parent, pn);
if (ret != 0) {
free(pn->pf);
@@ -383,6 +387,10 @@ static void FreeProcEntry(struct ProcDirEntry *entry)
free(entry->pf);
entry->pf = NULL;
}
+ if (entry->data != NULL) {
+ free(entry->data);
+ entry->data = NULL;
+ }
free(entry);
}
@@ -529,7 +537,7 @@ static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len)
if (sb->buf == NULL) {
// only read once to build the storage buffer
- if (pde->procFileOps->read(sb, NULL) != 0) {
+ if (pde->procFileOps->read(sb, pde->data) != 0) {
return PROC_ERROR;
}
}
diff --git a/fs/vfs/operation/vfs_other.c b/fs/vfs/operation/vfs_other.c
index 880caf65..8b87b607 100644
--- a/fs/vfs/operation/vfs_other.c
+++ b/fs/vfs/operation/vfs_other.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -482,7 +482,7 @@ exit_with_nomem:
return (char *)NULL;
}
-static void PrintFileInfo64(const struct stat64 *stat64Info, const char *name)
+static void PrintFileInfo64(const struct stat64 *stat64Info, const char *name, const char *linkName)
{
mode_t mode;
char str[UGO_NUMS][UGO_NUMS + 1] = {0};
@@ -504,11 +504,18 @@ static void PrintFileInfo64(const struct stat64 *stat64Info, const char *name)
dirFlag = '-';
}
- PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
- str[0], str[1], str[UGO_NUMS - 1], stat64Info->st_size, stat64Info->st_uid, stat64Info->st_gid, name);
+ if (S_ISLNK(stat64Info->st_mode)) {
+ PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s -> %s\n", dirFlag,
+ str[0], str[1], str[UGO_NUMS - 1], stat64Info->st_size,
+ stat64Info->st_uid, stat64Info->st_gid, name, linkName);
+ } else {
+ PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
+ str[0], str[1], str[UGO_NUMS - 1], stat64Info->st_size,
+ stat64Info->st_uid, stat64Info->st_gid, name);
+ }
}
-static void PrintFileInfo(const struct stat *statInfo, const char *name)
+static void PrintFileInfo(const struct stat *statInfo, const char *name, const char *linkName)
{
mode_t mode;
char str[UGO_NUMS][UGO_NUMS + 1] = {0};
@@ -530,19 +537,33 @@ static void PrintFileInfo(const struct stat *statInfo, const char *name)
dirFlag = '-';
}
- PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
- str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size, statInfo->st_uid, statInfo->st_gid, name);
+ if (S_ISLNK(statInfo->st_mode)) {
+ PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s -> %s\n", dirFlag,
+ str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size,
+ statInfo->st_uid, statInfo->st_gid, name, linkName);
+ } else {
+ PRINTK("%c%s%s%s %-8lld u:%-5d g:%-5d %-10s\n", dirFlag,
+ str[0], str[1], str[UGO_NUMS - 1], statInfo->st_size,
+ statInfo->st_uid, statInfo->st_gid, name);
+ }
}
int LsFile(const char *path)
{
struct stat64 stat64Info;
struct stat statInfo;
+ char linkName[NAME_MAX] = { 0 };
if (stat64(path, &stat64Info) == 0) {
- PrintFileInfo64(&stat64Info, path);
+ if (S_ISLNK(stat64Info.st_mode)) {
+ readlink(path, linkName, NAME_MAX);
+ }
+ PrintFileInfo64(&stat64Info, path, (const char *)linkName);
} else if (stat(path, &statInfo) == 0) {
- PrintFileInfo(&statInfo, path);
+ if (S_ISLNK(statInfo.st_mode)) {
+ readlink(path, linkName, NAME_MAX);
+ }
+ PrintFileInfo(&statInfo, path, (const char *)linkName);
} else {
return -1;
}
@@ -554,6 +575,7 @@ int LsDir(const char *path)
{
struct stat statInfo = { 0 };
struct stat64 stat64Info = { 0 };
+ char linkName[NAME_MAX] = { 0 };
DIR *d = NULL;
char *fullpath = NULL;
char *fullpath_bak = NULL;
@@ -569,28 +591,34 @@ int LsDir(const char *path)
pdirent = readdir(d);
if (pdirent == NULL) {
break;
- } else {
- if (!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, "..")) {
- continue;
- }
- (void)memset_s(&statInfo, sizeof(struct stat), 0, sizeof(struct stat));
- (void)memset_s(&stat64Info, sizeof(struct stat), 0, sizeof(struct stat));
- fullpath = ls_get_fullpath(path, pdirent);
- if (fullpath == NULL) {
- (void)closedir(d);
- return -1;
- }
-
- fullpath_bak = fullpath;
- if (stat64(fullpath, &stat64Info) == 0) {
- PrintFileInfo64(&stat64Info, pdirent->d_name);
- } else if (stat(fullpath, &statInfo) == 0) {
- PrintFileInfo(&statInfo, pdirent->d_name);
- } else {
- PRINTK("BAD file: %s\n", pdirent->d_name);
- }
- free(fullpath_bak);
}
+ if (!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, "..")) {
+ continue;
+ }
+ (void)memset_s(&statInfo, sizeof(struct stat), 0, sizeof(struct stat));
+ (void)memset_s(&stat64Info, sizeof(struct stat), 0, sizeof(struct stat));
+ (void)memset_s(&linkName, sizeof(linkName), 0, sizeof(linkName));
+ fullpath = ls_get_fullpath(path, pdirent);
+ if (fullpath == NULL) {
+ (void)closedir(d);
+ return -1;
+ }
+
+ fullpath_bak = fullpath;
+ if (stat64(fullpath, &stat64Info) == 0) {
+ if (S_ISLNK(stat64Info.st_mode)) {
+ readlink(fullpath, linkName, NAME_MAX);
+ }
+ PrintFileInfo64(&stat64Info, pdirent->d_name, linkName);
+ } else if (stat(fullpath, &statInfo) == 0) {
+ if (S_ISLNK(statInfo.st_mode)) {
+ readlink(fullpath, linkName, NAME_MAX);
+ }
+ PrintFileInfo(&statInfo, pdirent->d_name, linkName);
+ } else {
+ PRINTK("BAD file: %s\n", pdirent->d_name);
+ }
+ free(fullpath_bak);
} while (1);
(void)closedir(d);
@@ -729,4 +757,3 @@ mode_t SysUmask(mode_t mask)
SCHEDULER_UNLOCK(intSave);
return oldUmask;
}
-
diff --git a/kernel/base/container/los_container.c b/kernel/base/container/los_container.c
index c0d47300..40e43e7d 100644
--- a/kernel/base/container/los_container.c
+++ b/kernel/base/container/los_container.c
@@ -32,6 +32,12 @@
#ifdef LOSCFG_KERNEL_CONTAINER
STATIC Container g_rootContainer;
+STATIC Atomic g_containerCount = 0xF0000000U;
+
+UINT32 OsAllocContainerID(VOID)
+{
+ return LOS_AtomicIncRet(&g_containerCount);
+}
VOID OsContainerInitSystemProcess(LosProcessCB *processCB)
{
@@ -108,7 +114,7 @@ VOID OsContainersDestroy(LosProcessCB *processCB)
{
/* All processes in the container must be destroyed before the container is destroyed. */
#ifdef LOSCFG_PID_CONTAINER
- if (processCB->processID == 1) {
+ if (processCB->processID == OS_USER_ROOT_PROCESS_ID) {
OsPidContainersDestroyAllProcess(processCB);
}
#endif
@@ -125,4 +131,21 @@ VOID OsContainersDestroy(LosProcessCB *processCB)
}
#endif
}
+
+UINT32 OsGetContainerID(Container *container, ContainerType type)
+{
+ if (container == NULL) {
+ return OS_INVALID_VALUE;
+ }
+
+ switch (type) {
+ case PID_CONTAINER:
+ return OsGetPidContainerID(container->pidContainer);
+ case UTS_CONTAINER:
+ return OsGetUtsContainerID(container->utsContainer);
+ default:
+ break;
+ }
+ return OS_INVALID_VALUE;
+}
#endif
diff --git a/kernel/base/container/los_pid_container.c b/kernel/base/container/los_pid_container.c
index be78614b..d307def2 100644
--- a/kernel/base/container/los_pid_container.c
+++ b/kernel/base/container/los_pid_container.c
@@ -242,6 +242,7 @@ STATIC PidContainer *CreateNewPidContainer(PidContainer *parent)
}
(VOID)memset_s(newPidContainer, sizeof(PidContainer), 0, sizeof(PidContainer));
+ newPidContainer->containerID = OsAllocContainerID();
LOS_ListInit(&newPidContainer->pidFreeList);
for (index = 0; index < LOSCFG_BASE_CORE_PROCESS_LIMIT; index++) {
ProcessVid *vpid = &newPidContainer->pidArray[index];
@@ -392,6 +393,23 @@ UINT32 OsGetVpidFromCurrContainer(const LosProcessCB *processCB)
return OS_INVALID_VALUE;
}
+UINT32 OsGetVpidFromRootContainer(const LosProcessCB *processCB)
+{
+ UINT32 vpid = processCB->processID;
+ PidContainer *pidContainer = processCB->container->pidContainer;
+ while (pidContainer != NULL) {
+ ProcessVid *vid = &pidContainer->pidArray[vpid];
+ if (pidContainer->parent != NULL) {
+ vpid = vid->vpid;
+ pidContainer = pidContainer->parent;
+ continue;
+ }
+
+ return vid->vid;
+ }
+ return OS_INVALID_VALUE;
+}
+
UINT32 OsGetVtidFromCurrContainer(const LosTaskCB *taskCB)
{
UINT32 vtid = taskCB->taskID;
@@ -423,4 +441,12 @@ LosTaskCB *OsGetTCBFromVtid(UINT32 vtid)
return (LosTaskCB *)taskVid->cb;
}
+UINT32 OsGetPidContainerID(PidContainer *pidContainer)
+{
+ if (pidContainer == NULL) {
+ return OS_INVALID_VALUE;
+ }
+
+ return pidContainer->containerID;
+}
#endif
diff --git a/kernel/base/container/los_uts_container.c b/kernel/base/container/los_uts_container.c
index 7a8cbed6..c441423d 100644
--- a/kernel/base/container/los_uts_container.c
+++ b/kernel/base/container/los_uts_container.c
@@ -46,6 +46,7 @@ STATIC UINT32 CreateUtsContainer(UtsContainer **newUtsContainer)
}
(VOID)memset_s(utsContainer, sizeof(UtsContainer), 0, sizeof(UtsContainer));
+ utsContainer->containerID = OsAllocContainerID();
LOS_AtomicSet(&utsContainer->rc, 1);
SCHEDULER_LOCK(intSave);
@@ -158,4 +159,14 @@ struct utsname *OsGetCurrUtsName(VOID)
}
return &utsContainer->utsName;
}
+
+UINT32 OsGetUtsContainerID(UtsContainer *utsContainer)
+{
+ if (utsContainer == NULL) {
+ return OS_INVALID_VALUE;
+ }
+
+ return utsContainer->containerID;
+}
+
#endif
diff --git a/kernel/base/core/los_process.c b/kernel/base/core/los_process.c
index f35500bb..c9d0789b 100644
--- a/kernel/base/core/los_process.c
+++ b/kernel/base/core/los_process.c
@@ -40,6 +40,7 @@
#ifdef LOSCFG_FS_VFS
#include "fs/fd_table.h"
#include "fs/fs_operation.h"
+#include "internal.h"
#endif
#include "time.h"
#include "user_copy.h"
@@ -436,6 +437,11 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
(VOID)LOS_MemFree(m_aucSysMem1, processCpup);
#endif
+#ifdef LOSCFG_PROC_PROCESS_DIR
+ ProcFreeProcessDir(processCB->procDir);
+ processCB->procDir = NULL;
+#endif
+
#ifdef LOSCFG_KERNEL_CONTAINER
OsContainersDestroy(processCB);
#endif
@@ -1905,6 +1911,13 @@ STATIC UINT32 OsCopyFile(UINT32 flags, LosProcessCB *childProcessCB, LosProcessC
if (childProcessCB->files == NULL) {
return LOS_ENOMEM;
}
+#ifdef LOSCFG_PROC_PROCESS_DIR
+ INT32 ret = ProcCreateProcessDir(OsGetRootPid(childProcessCB), (UINTPTR)childProcessCB);
+ if (ret < 0) {
+ PRINT_ERR("ProcCreateProcessDir failed, pid = %u\n", childProcessCB->processID);
+ return LOS_EBADF;
+ }
+#endif
#endif
childProcessCB->consoleID = runProcessCB->consoleID;
diff --git a/kernel/base/include/los_container_pri.h b/kernel/base/include/los_container_pri.h
index 480077db..38d365f2 100644
--- a/kernel/base/include/los_container_pri.h
+++ b/kernel/base/include/los_container_pri.h
@@ -40,6 +40,12 @@
#include "los_uts_container_pri.h"
#endif
+typedef enum {
+ CONTAINER = 0,
+ PID_CONTAINER,
+ UTS_CONTAINER,
+} ContainerType;
+
typedef struct Container {
Atomic rc;
#ifdef LOSCFG_PID_CONTAINER
@@ -57,5 +63,9 @@ VOID OsInitRootContainer(VOID);
UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID);
VOID OsContainersDestroy(LosProcessCB *processCB);
+
+UINT32 OsAllocContainerID(VOID);
+
+UINT32 OsGetContainerID(Container *container, ContainerType type);
#endif
#endif /* _LOS_CONTAINER_PRI_H */
diff --git a/kernel/base/include/los_pid_container_pri.h b/kernel/base/include/los_pid_container_pri.h
index 36e4562c..c1fe98b2 100644
--- a/kernel/base/include/los_pid_container_pri.h
+++ b/kernel/base/include/los_pid_container_pri.h
@@ -51,6 +51,7 @@ typedef struct PidContainer {
Atomic rc;
Atomic level;
Atomic lock;
+ UINT32 containerID;
struct PidContainer *parent;
struct ProcessGroup *rootPGroup;
LOS_DL_LIST tidFreeList;
@@ -82,10 +83,14 @@ LosTaskCB *OsGetTCBFromVtid(UINT32 vtid);
UINT32 OsGetVpidFromCurrContainer(const LosProcessCB *processCB);
+UINT32 OsGetVpidFromRootContainer(const LosProcessCB *processCB);
+
UINT32 OsGetVtidFromCurrContainer(const LosTaskCB *taskCB);
VOID OsFreeVtid(LosTaskCB *taskCB);
UINT32 OsAllocVtid(LosTaskCB *taskCB, const LosProcessCB *processCB);
+UINT32 OsGetPidContainerID(PidContainer *pidContainer);
+
#endif /* _LOS_PID_CONTAINER_PRI_H */
diff --git a/kernel/base/include/los_process_pri.h b/kernel/base/include/los_process_pri.h
index 99e6cb67..8a1cc114 100644
--- a/kernel/base/include/los_process_pri.h
+++ b/kernel/base/include/los_process_pri.h
@@ -133,6 +133,9 @@ typedef struct ProcessCB {
#ifdef LOSCFG_KERNEL_CONTAINER
struct Container *container;
#endif
+#ifdef LOSCFG_PROC_PROCESS_DIR
+ struct ProcDirEntry *procDir;
+#endif
} LosProcessCB;
extern LosProcessCB *g_processCBArray;
@@ -443,6 +446,15 @@ STATIC INLINE UINT32 OsGetPid(const LosProcessCB *processCB)
return processCB->processID;
}
+STATIC INLINE UINT32 OsGetRootPid(const LosProcessCB *processCB)
+{
+#ifdef LOSCFG_PID_CONTAINER
+ return OsGetVpidFromRootContainer(processCB);
+#else
+ return processCB->processID;
+#endif
+}
+
/*
* return immediately if no child has exited.
*/
diff --git a/kernel/base/include/los_uts_container_pri.h b/kernel/base/include/los_uts_container_pri.h
index 8e874cac..a4a984b2 100644
--- a/kernel/base/include/los_uts_container_pri.h
+++ b/kernel/base/include/los_uts_container_pri.h
@@ -38,10 +38,10 @@
#ifdef LOSCFG_UTS_CONTAINER
typedef struct ProcessCB LosProcessCB;
-
typedef struct UtsContainer {
- Atomic rc;
- struct utsname utsName;
+ Atomic rc;
+ UINT32 containerID;
+ struct utsname utsName;
} UtsContainer;
UINT32 OsInitRootUtsContainer(UtsContainer **utsContainer);
@@ -52,5 +52,6 @@ VOID OsUtsContainersDestroy(LosProcessCB *curr);
struct utsname *OsGetCurrUtsName(VOID);
+UINT32 OsGetUtsContainerID(UtsContainer *utsContainer);
#endif
#endif /* _LOS_UTS_CONTAINER_PRI_H */
diff --git a/testsuites/unittest/BUILD.gn b/testsuites/unittest/BUILD.gn
index 56970762..69860d84 100644
--- a/testsuites/unittest/BUILD.gn
+++ b/testsuites/unittest/BUILD.gn
@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
-# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
@@ -135,10 +135,16 @@ group("unittest") {
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
deps += [ "process/basic:liteos_a_process_basic_unittest_door" ]
deps += [ "process/lock:liteos_a_process_lock_unittest_door" ]
+ if (LOSCFG_USER_TEST_PROCESS_FS == true) {
+ deps += [ "process/fs:liteos_a_process_fs_unittest_door" ]
+ }
}
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
deps += [ "process/basic:liteos_a_process_basic_unittest" ]
deps += [ "process/lock:liteos_a_process_lock_unittest" ]
+ if (LOSCFG_USER_TEST_PROCESS_FS == true) {
+ deps += [ "process/fs:liteos_a_process_fs_unittest" ]
+ }
}
}
diff --git a/testsuites/unittest/config.gni b/testsuites/unittest/config.gni
index b1240712..28697b16 100644
--- a/testsuites/unittest/config.gni
+++ b/testsuites/unittest/config.gni
@@ -126,6 +126,11 @@ LOSCFG_USER_TEST_SECURITY_CAPABILITY = true
LOSCFG_USER_TEST_SECURITY_REUGID = true
LOSCFG_USER_TEST_SECURITY_VID = true
+LOSCFG_USER_TEST_PROCESS_FS = false
+if (defined(LOSCFG_PROC_PROCESS_DIR)) {
+ LOSCFG_USER_TEST_PROCESS_FS = true
+}
+
########## container test ##########
LOSCFG_USER_TEST_CONTAINER = false
LOSCFG_USER_TEST_PID_CONTAINER = false
diff --git a/testsuites/unittest/process/fs/BUILD.gn b/testsuites/unittest/process/fs/BUILD.gn
new file mode 100644
index 00000000..fa74c551
--- /dev/null
+++ b/testsuites/unittest/process/fs/BUILD.gn
@@ -0,0 +1,58 @@
+# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be used
+# to endorse or promote products derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import("//build/lite/config/test.gni")
+import("//kernel/liteos_a/testsuites/unittest/config.gni")
+import("./config.gni")
+
+if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
+ unittest("liteos_a_process_fs_unittest_door") {
+ output_extension = "bin"
+ output_dir = "$root_out_dir/test/unittest/kernel"
+ include_dirs = common_include_dirs
+ sources = sources_entry
+ sources += sources_smoke
+ sources_full = []
+ sources += sources_full
+ configs = [ "../..:public_config_for_door" ]
+ deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
+ }
+}
+
+if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
+ unittest("liteos_a_process_fs_unittest") {
+ output_extension = "bin"
+ output_dir = "$root_out_dir/test/unittest/kernel"
+ include_dirs = common_include_dirs
+ sources = sources_entry
+ sources += sources_smoke
+ sources += sources_full
+ configs = [ "../..:public_config_for_all" ]
+ deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
+ }
+}
diff --git a/testsuites/unittest/process/fs/It_process_fs_test.h b/testsuites/unittest/process/fs/It_process_fs_test.h
new file mode 100644
index 00000000..974bc40a
--- /dev/null
+++ b/testsuites/unittest/process/fs/It_process_fs_test.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _IT_PROCESS_FS_TEST_H
+#define _IT_PROCESS_FS_TEST_H
+
+#include
+#include
+#include "osTest.h"
+
+extern VOID PrintTest(const CHAR *fmt, ...);
+
+extern std::string GenProcPidPath(int pid);
+extern std::string GenProcPidContainerPath(int pid, char *name);
+
+extern void ItProcessFs001(void);
+extern void ItProcessFs002(void);
+extern void ItProcessFs003(void);
+extern void ItProcessFs004(void);
+extern void ItProcessFs005(void);
+extern void ItProcessFs006(void);
+extern void ItProcessFs007(void);
+extern void ItProcessFs008(void);
+extern void ItProcessFs009(void);
+extern void ItProcessFs010(void);
+extern void ItProcessFs011(void);
+extern void ItProcessFs012(void);
+extern void ItProcessFs013(void);
+extern void ItProcessFs014(void);
+extern void ItProcessFs015(void);
+#endif
diff --git a/testsuites/unittest/process/fs/config.gni b/testsuites/unittest/process/fs/config.gni
new file mode 100644
index 00000000..8de233fe
--- /dev/null
+++ b/testsuites/unittest/process/fs/config.gni
@@ -0,0 +1,74 @@
+# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be used
+# to endorse or promote products derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import("//build/lite/config/test.gni")
+import("//kernel/liteos_a/testsuites/unittest/config.gni")
+
+common_include_dirs = [
+ "//third_party/googletest/googletest/include",
+ "../../common/include",
+]
+
+sources_entry = [ "../../common/osTest.cpp" ]
+
+sources_smoke = []
+
+sources_full = []
+
+process_fs_include_dirs = [ "$TEST_UNITTEST_DIR/process/fs" ]
+
+process_fs_sources_entry =
+ [ "$TEST_UNITTEST_DIR/process/fs/process_fs_test.cpp" ]
+
+process_fs_sources_smoke = [
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_001.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_002.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_003.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_004.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_005.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_006.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_007.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_008.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_009.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_010.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_011.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_012.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_013.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_014.cpp",
+ "$TEST_UNITTEST_DIR/process/fs/smoke/It_process_fs_015.cpp",
+]
+
+process_fs_sources_full = []
+
+# fs module
+if (LOSCFG_USER_TEST_PROCESS_FS == true) {
+ common_include_dirs += process_fs_include_dirs
+ sources_entry += process_fs_sources_entry
+ sources_smoke += process_fs_sources_smoke
+ sources_full += process_fs_sources_full
+}
diff --git a/testsuites/unittest/process/fs/process_fs_test.cpp b/testsuites/unittest/process/fs/process_fs_test.cpp
new file mode 100644
index 00000000..cb8bfd42
--- /dev/null
+++ b/testsuites/unittest/process/fs/process_fs_test.cpp
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include "It_process_fs_test.h"
+
+VOID PrintTest(const CHAR *fmt, ...)
+{
+#ifdef PRINT_TEST
+ va_list ap;
+ if (g_osLkHook != NULL) {
+ va_start(ap, fmt);
+ printf(fmt, ap);
+ va_end(ap);
+ }
+#endif
+}
+
+std::string GenProcPidPath(int pid)
+{
+ std::ostringstream buf;
+ buf << "/proc/" << pid;
+ return buf.str();
+}
+
+std::string GenProcPidContainerPath(int pid, char *name)
+{
+ std::ostringstream buf;
+ buf << "/proc/" << pid << "/container/" << name;
+ return buf.str();
+}
+
+
+using namespace testing::ext;
+namespace OHOS {
+class ProcessFsTest : public testing::Test {
+public:
+ static void SetUpTestCase(void) {}
+ static void TearDownTestCase(void) {}
+};
+
+#if defined(LOSCFG_USER_TEST_SMOKE)
+/**
+* @tc.name: Process_fs_Test_001
+* @tc.desc: Process mount directory test
+* @tc.type: FUNC
+* @tc.require: issueI6AEVV
+* @tc.author:
+*/
+HWTEST_F(ProcessFsTest, ItProcessFs001, TestSize.Level0)
+{
+ ItProcessFs001();
+}
+
+/**
+* @tc.name: Process_fs_Test_007
+* @tc.desc: Process mount directory test
+* @tc.type: FUNC
+* @tc.require: issueI6AEVV
+* @tc.author:
+*/
+HWTEST_F(ProcessFsTest, ItProcessFs007, TestSize.Level0)
+{
+ ItProcessFs007();
+}
+
+/**
+* @tc.name: Process_fs_Test_010
+* @tc.desc: Process mount directory test
+* @tc.type: FUNC
+* @tc.require: issueI6AEVV
+* @tc.author:
+*/
+HWTEST_F(ProcessFsTest, ItProcessFs010, TestSize.Level0)
+{
+ ItProcessFs010();
+}
+
+/**
+* @tc.name: Process_fs_Test_012
+* @tc.desc: Process mount directory test
+* @tc.type: FUNC
+* @tc.require: issueI6AEVV
+* @tc.author:
+*/
+HWTEST_F(ProcessFsTest, ItProcessFs012, TestSize.Level0)
+{
+ ItProcessFs012();
+}
+
+/**
+* @tc.name: Process_fs_Test_013
+* @tc.desc: Process mount directory test
+* @tc.type: FUNC
+* @tc.require: issueI6AEVV
+* @tc.author:
+*/
+HWTEST_F(ProcessFsTest, ItProcessFs013, TestSize.Level0)
+{
+ ItProcessFs013();
+}
+
+/**
+* @tc.name: Process_fs_Test_014
+* @tc.desc: Process mount directory test
+* @tc.type: FUNC
+* @tc.require: issueI6AEVV
+* @tc.author:
+*/
+HWTEST_F(ProcessFsTest, ItProcessFs014, TestSize.Level0)
+{
+ ItProcessFs014();
+}
+
+/**
+* @tc.name: Process_fs_Test_015
+* @tc.desc: Process mount directory test
+* @tc.type: FUNC
+* @tc.require: issueI6AEVV
+* @tc.author:
+*/
+HWTEST_F(ProcessFsTest, ItProcessFs015, TestSize.Level0)
+{
+ ItProcessFs015();
+}
+#endif
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_001.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_001.cpp
new file mode 100644
index 00000000..5bd1256e
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_001.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include
+#include
+#include "It_process_fs_test.h"
+
+void ItProcessFs001(void)
+{
+ auto path = GenProcPidPath(getpid());
+ DIR *dirp = opendir(path.data());
+ ASSERT_NE(dirp, nullptr);
+
+ (void)closedir(dirp);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_002.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_002.cpp
new file mode 100644
index 00000000..2b3bd3a6
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_002.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+using namespace std;
+
+void ItProcessFs002(void)
+{
+ const int LEN_BUFF = 512;
+ char szStatBuf[LEN_BUFF];
+ FILE *fp = fopen("/proc/meminfo", "rb");
+ ASSERT_NE(fp, nullptr);
+
+ int ret = fread(szStatBuf, 1, LEN_BUFF, fp);
+ PrintTest("cat /proc/meminfo\n");
+ PrintTest("%s\n", szStatBuf);
+ ASSERT_EQ(ret, strlen(szStatBuf));
+
+ char *res = strstr(szStatBuf, "UsedSize");
+ ASSERT_NE(res, nullptr);
+
+ (void)fclose(fp);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_003.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_003.cpp
new file mode 100644
index 00000000..90f6b89b
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_003.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+using namespace std;
+
+void ItProcessFs003(void)
+{
+ const int LEN_STAT = 512;
+ char szStatBuf[LEN_STAT];
+ FILE *fp = fopen("/proc/filesystems", "r");
+ ASSERT_NE(fp, nullptr);
+
+ (void)memset_s(szStatBuf, LEN_STAT, 0, LEN_STAT);
+ int readLen = fread(szStatBuf, 1, LEN_STAT, fp);
+
+ PrintTest("cat /proc/filesystems\n");
+ PrintTest("%s\n", szStatBuf);
+ ASSERT_EQ(readLen, strlen(szStatBuf));
+
+ char *res = strstr(szStatBuf, "procfs");
+ ASSERT_NE(res, nullptr);
+
+ (void)fclose(fp);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_004.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_004.cpp
new file mode 100644
index 00000000..55e6c748
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_004.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+static std::string gen_proc_pid_meminfo_path(int pid)
+{
+ std::ostringstream buf;
+ buf << "/proc/" << pid << "/meminfo";
+ return buf.str();
+}
+
+static void operPidMemInfo(std::string strFile)
+{
+ const int FILE_LEN = 1024;
+ char szStatBuf[FILE_LEN];
+ FILE *fp = fopen(strFile.c_str(), "rb");
+ ASSERT_NE(fp, nullptr);
+
+ (void)memset_s(szStatBuf, FILE_LEN, 0, FILE_LEN);
+ int ret = fread(szStatBuf, 1, FILE_LEN, fp);
+ PrintTest("cat %s\n", strFile.c_str());
+ PrintTest("%s\n", szStatBuf);
+ ASSERT_EQ(ret, strlen(szStatBuf));
+
+ char *res = strstr(szStatBuf, "VMSpaceSize");
+ ASSERT_NE(res, nullptr);
+
+ (void)fclose(fp);
+}
+
+void ItProcessFs004(void)
+{
+ auto path = gen_proc_pid_meminfo_path(getpid());
+ operPidMemInfo(path);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_005.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_005.cpp
new file mode 100644
index 00000000..1952a168
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_005.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+static std::string gen_proc_pid_cpup_path(int pid)
+{
+ std::ostringstream buf;
+ buf << "/proc/" << pid << "/cpup";
+ return buf.str();
+}
+
+static void operPidCpup(std::string strFile)
+{
+ const int PUP_LEN = 1024;
+ char szStatBuf[PUP_LEN];
+ FILE *fp = fopen(strFile.c_str(), "rb");
+ ASSERT_NE(fp, nullptr);
+
+ (void)memset_s(szStatBuf, PUP_LEN, 0, PUP_LEN);
+ int ret = fread(szStatBuf, 1, PUP_LEN, fp);
+ PrintTest("cat %s\n", strFile.c_str());
+
+ PrintTest("%s\n", szStatBuf);
+ ASSERT_EQ(ret, strlen(szStatBuf));
+
+ char *res = strstr(szStatBuf, "TotalRunningTime");
+ ASSERT_NE(res, nullptr);
+
+ (void)fclose(fp);
+}
+
+void ItProcessFs005(void)
+{
+ auto path = gen_proc_pid_cpup_path(getpid());
+ operPidCpup(path);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_006.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_006.cpp
new file mode 100644
index 00000000..fc3fc570
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_006.cpp
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+static int const maxContainerNum = 5;
+static int const configLen = 16;
+static int nInitArry[maxContainerNum] = {61, 54, 49, 44, 41};
+
+static std::string arryEntries[maxContainerNum] = {
+ "max_mnt_container",
+ "max_pid_container",
+ "max_user_container",
+ "max_net_container",
+ "max_uts_container"
+};
+
+static void WriteContainer(const char *filepath, int value)
+{
+ PrintTest("writeproc %d >> %s\n", value, filepath);
+ int fd = open(filepath, O_WRONLY);
+ ASSERT_EQ(fd, -1);
+ char buf[configLen];
+ size_t twd = sprintf_s(buf, configLen, "%d", value);
+ ASSERT_GT(twd, 0);
+ twd = write(fd, buf, (strlen(buf)+1));
+ ASSERT_EQ(twd, -1);
+ (void)close(fd);
+}
+
+static void ReadContainer(std::string strFile, int value)
+{
+ char szStatBuf[configLen];
+ FILE *fp = fopen(strFile.c_str(), "rb");
+ ASSERT_NE(fp, nullptr);
+
+ int ret;
+ (void)memset_s(szStatBuf, configLen, 0, configLen);
+ ret = fread(szStatBuf, 1, configLen, fp);
+ ASSERT_NE(ret, 0);
+ PrintTest("cat %s\n", strFile.c_str());
+
+ PrintTest("%s\n", szStatBuf);
+ ret = atoi(szStatBuf);
+ ASSERT_EQ(ret, value);
+
+ (void)fclose(fp);
+}
+
+static void ErrWriteContainer0(const char *filepath)
+{
+ int fd = open(filepath, O_WRONLY);
+ ASSERT_EQ(fd, -1);
+ char buf[configLen];
+ int invalidNum = 0;
+ size_t twd1 = sprintf_s(buf, configLen, "%d", invalidNum);
+ ASSERT_GT(twd1, 0);
+ PrintTest("writeproc %d >> %s\n", invalidNum, filepath);
+ twd1 = write(fd, buf, (strlen(buf)+1));
+ (void)close(fd);
+ ASSERT_EQ(twd1, -1);
+}
+
+static void ErrWriteContainer65(const char *filepath)
+{
+ int fd = open(filepath, O_WRONLY);
+ ASSERT_EQ(fd, -1);
+ char buf[configLen];
+ int invalidNum = 65;
+ size_t twd2 = sprintf_s(buf, configLen, "%d", invalidNum);
+ ASSERT_GT(twd2, 0);
+ PrintTest("writeproc %d >> %s\n", invalidNum, filepath);
+ twd2 = write(fd, buf, (strlen(buf)+1));
+ (void)close(fd);
+ ASSERT_EQ(twd2, -1);
+}
+
+void ItProcessFs006(void)
+{
+ const int CONFIG_FILE_LEN = 1024;
+ char szFile[CONFIG_FILE_LEN] = {0};
+ for (int i = 0; i < maxContainerNum; i++) {
+ size_t count = sprintf_s(szFile, CONFIG_FILE_LEN, "/proc/sys/user/%s", arryEntries[i].c_str());
+ ASSERT_GT(count, 0);
+ WriteContainer(szFile, nInitArry[i]);
+ ReadContainer(szFile, nInitArry[i]);
+ }
+
+ for (int i = 0; i < maxContainerNum; i++) {
+ size_t count = sprintf_s(szFile, CONFIG_FILE_LEN, "/proc/sys/user/%s", arryEntries[i].c_str());
+ ASSERT_GT(count, 0);
+ ErrWriteContainer0(szFile);
+
+ ErrWriteContainer65(szFile);
+ }
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_007.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_007.cpp
new file mode 100644
index 00000000..88ada66e
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_007.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "It_process_fs_test.h"
+
+void ItProcessFs007(void)
+{
+ auto path = GenProcPidContainerPath(getpid(), "uts");
+ std::vector buf(PATH_MAX);
+ auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
+ ASSERT_NE(nbytes, -1);
+
+ std::regex reg("'uts:\\[[0-9]+\\]'");
+ bool ret = std::regex_match(buf.data(), reg);
+ ASSERT_EQ(ret, true);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_008.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_008.cpp
new file mode 100644
index 00000000..176de0db
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_008.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "It_process_fs_test.h"
+
+void ItProcessFs008(void)
+{
+ auto path = GenProcPidContainerPath(getpid(), "mnt");
+ std::vector buf(PATH_MAX);
+ auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
+ ASSERT_NE(nbytes, -1);
+
+ std::regex reg("'mnt:\\[[0-9]+\\]'");
+ bool ret = std::regex_match(buf.data(), reg);
+ ASSERT_EQ(ret, true);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_009.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_009.cpp
new file mode 100644
index 00000000..9516e5bd
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_009.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "It_process_fs_test.h"
+
+void ItProcessFs009(void)
+{
+ auto path = GenProcPidContainerPath(getpid(), "user");
+ std::vector buf(PATH_MAX);
+ auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
+ ASSERT_NE(nbytes, -1);
+
+ std::regex reg("'user:\\[[0-9]+\\]'");
+ bool ret = std::regex_match(buf.data(), reg);
+ ASSERT_EQ(ret, true);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_010.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_010.cpp
new file mode 100644
index 00000000..eef710df
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_010.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "It_process_fs_test.h"
+
+void ItProcessFs010(void)
+{
+ auto path = GenProcPidContainerPath(getpid(), "pid");
+ std::vector buf(PATH_MAX);
+ auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
+ ASSERT_NE(nbytes, -1);
+
+ std::regex reg("'pid:\\[[0-9]+\\]'");
+ bool ret = std::regex_match(buf.data(), reg);
+ ASSERT_EQ(ret, true);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_011.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_011.cpp
new file mode 100644
index 00000000..49f26e62
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_011.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "It_process_fs_test.h"
+
+void ItProcessFs011(void)
+{
+ auto path = GenProcPidContainerPath(getpid(), "net");
+ std::vector buf(PATH_MAX);
+ auto nbytes = readlink(path.c_str(), buf.data(), PATH_MAX);
+ ASSERT_NE(nbytes, -1);
+
+ std::regex reg("'net:\\[[0-9]+\\]'");
+ bool ret = std::regex_match(buf.data(), reg);
+ ASSERT_EQ(ret, true);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_012.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_012.cpp
new file mode 100644
index 00000000..858a5edb
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_012.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include "It_process_fs_test.h"
+
+static const int STACK_SIZE = 1024 * 1024;
+static const int CHILD_FUNC_ARG = 0x2088;
+
+static int child_process(void *arg)
+{
+ (void)arg;
+ pid_t pid = getpid();
+ std::ostringstream buf;
+ buf << "/proc/" << pid;
+ DIR *dirp = opendir(buf.str().data());
+ if (dirp == nullptr) {
+ return 1;
+ }
+
+ (void)closedir(dirp);
+ return 0;
+}
+
+void ItProcessFs012(void)
+{
+ int ret = 0;
+ int status;
+ char *stack = (char *)mmap(nullptr, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
+ -1, 0);
+ ASSERT_NE(stack, nullptr);
+ char *stackTop = stack + STACK_SIZE;
+ int arg = CHILD_FUNC_ARG;
+ pid_t pid = clone(child_process, stackTop, SIGCHLD, &arg);
+ ASSERT_NE(pid, -1);
+
+ ret = waitpid(pid, &status, 0);
+ ASSERT_EQ(ret, pid);
+
+ ret = WIFEXITED(status);
+ int exitCode = WEXITSTATUS(status);
+ ASSERT_EQ(exitCode, 0);
+
+ std::ostringstream buf;
+ buf << "/proc/" << pid;
+ DIR *dirp = opendir(buf.str().data());
+ ASSERT_EQ(dirp, nullptr);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp
new file mode 100644
index 00000000..b4afdb09
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include "It_process_fs_test.h"
+
+static const int ini_process_max = 3;
+
+void ItProcessFs013(void)
+{
+ std::string path;
+ DIR *dirp = nullptr;
+ for (int i = 1; i <= ini_process_max; i++) {
+ if (i != 2) { /* 2: skip kernel process */
+ path = GenProcPidPath(i);
+ printf("path: %s\n", path.c_str());
+ dirp = opendir(path.data());
+ ASSERT_NE(dirp, nullptr);
+ (void)closedir(dirp);
+ };
+ }
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_014.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_014.cpp
new file mode 100644
index 00000000..4f34c907
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_014.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include "It_process_fs_test.h"
+
+void ItProcessFs014(void)
+{
+ std::string path = "/proc/100000";
+ DIR *dirp = nullptr;
+ dirp = opendir(path.c_str());
+ ASSERT_EQ(dirp, nullptr);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_015.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_015.cpp
new file mode 100644
index 00000000..ac5f155b
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_015.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include "It_process_fs_test.h"
+
+void ItProcessFs015(void)
+{
+ std::string path = "/proc/power";
+ DIR *dirp = nullptr;
+ dirp = opendir(path.c_str());
+ ASSERT_NE(dirp, nullptr);
+
+ (void)closedir(dirp);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_016.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_016.cpp
new file mode 100644
index 00000000..7fc6e261
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_016.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+static int const configLen = 16;
+static int const invalidNum = 2;
+static const int CHILD_FUNC_ARG = 0x2088;
+const int STACK_SIZE = (1024 * 1024);
+
+static int childFunc(void *arg)
+{
+ (void)arg;
+ sleep(2); /* 2: delay 2s */
+
+ return 0;
+}
+
+void ItProcessFs016(void)
+{
+ const int CONFIG_FILE_LEN = 1024;
+ char szFile[CONFIG_FILE_LEN] = {0};
+ std::string path = "/proc/sys/user/max_uts_container";
+ int fd = open(path.c_str(), O_WRONLY);
+ ASSERT_NE(fd, -1);
+
+ char buf[configLen];
+ (void)sprintf(buf, "%d", invalidNum);
+ size_t ret = write(fd, buf, (strlen(buf) + 1));
+ ASSERT_NE(ret, -1);
+
+ int arg = CHILD_FUNC_ARG;
+
+ char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
+ -1, 0);
+ ASSERT_NE(stack, NULL);
+ char *stackTop = stack + STACK_SIZE;
+
+ auto pid = clone(childFunc, stackTop, CLONE_NEWUTS, &arg);
+ ASSERT_NE(pid, -1);
+ pid = clone(childFunc, stackTop, CLONE_NEWUTS, &arg);
+ ASSERT_NE(pid, -1);
+
+ pid = clone(childFunc, stackTop, CLONE_NEWUTS, &arg);
+ ASSERT_EQ(pid, -1);
+
+ (void)close(fd);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_017.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_017.cpp
new file mode 100644
index 00000000..8831f378
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_017.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+static int const configLen = 16;
+static int const invalidNum = 2;
+static const int CHILD_FUNC_ARG = 0x2088;
+const int STACK_SIZE = (1024 * 1024);
+
+static int childFunc(void *arg)
+{
+ (void)arg;
+ sleep(2); /* 2: delay 2s */
+
+ return 0;
+}
+
+void ItProcessFs017(void)
+{
+ const int CONFIG_FILE_LEN = 1024;
+ char szFile[CONFIG_FILE_LEN] = {0};
+ std::string path = "/proc/sys/user/max_user_container";
+ int fd = open(path.c_str(), O_WRONLY);
+ ASSERT_NE(fd, -1);
+
+ char buf[configLen];
+ size_t ret = sprintf_s(buf, configLen, "%d", invalidNum);
+ ASSERT_GT(ret, 0);
+ ret = write(fd, buf, (strlen(buf) + 1));
+ ASSERT_NE(ret, -1);
+
+ int arg = CHILD_FUNC_ARG;
+
+ char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
+ -1, 0);
+ ASSERT_NE(stack, NULL);
+ char *stackTop = stack + STACK_SIZE;
+
+ auto pid = clone(childFunc, stackTop, CLONE_NEWUSER, &arg);
+ ASSERT_NE(pid, -1);
+ pid = clone(childFunc, stackTop, CLONE_NEWUSER, &arg);
+ ASSERT_NE(pid, -1);
+
+ pid = clone(childFunc, stackTop, CLONE_NEWUSER, &arg);
+ ASSERT_EQ(pid, -1);
+
+ (void)close(fd);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_018.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_018.cpp
new file mode 100644
index 00000000..6aba390d
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_018.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+static int const configLen = 16;
+static int const invalidNum = 2;
+static const int CHILD_FUNC_ARG = 0x2088;
+const int STACK_SIZE = (1024 * 1024);
+
+static int childFunc(void *arg)
+{
+ (void)arg;
+ sleep(2); /* 2: delay 2s */
+
+ return 0;
+}
+
+void ItProcessFs018(void)
+{
+ const int CONFIG_FILE_LEN = 1024;
+ char szFile[CONFIG_FILE_LEN] = {0};
+ std::string path = "/proc/sys/user/max_mnt_container";
+ int fd = open(path.c_str(), O_WRONLY);
+ ASSERT_NE(fd, -1);
+
+ char buf[configLen];
+ size_t ret = sprintf_s(buf, configLen, "%d", invalidNum);
+ ASSERT_GT(ret, 0);
+ ret = write(fd, buf, (strlen(buf) + 1));
+ ASSERT_NE(ret, -1);
+
+ int arg = CHILD_FUNC_ARG;
+
+ char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
+ -1, 0);
+ ASSERT_NE(stack, NULL);
+ char *stackTop = stack + STACK_SIZE;
+
+ auto pid = clone(childFunc, stackTop, CLONE_NEWNS, &arg);
+ ASSERT_NE(pid, -1);
+ pid = clone(childFunc, stackTop, CLONE_NEWNS, &arg);
+ ASSERT_NE(pid, -1);
+
+ pid = clone(childFunc, stackTop, CLONE_NEWNS, &arg);
+ ASSERT_EQ(pid, -1);
+
+ (void)close(fd);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_019.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_019.cpp
new file mode 100644
index 00000000..d230a6bb
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_019.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+static int const configLen = 16;
+static int const invalidNum = 2;
+static const int CHILD_FUNC_ARG = 0x2088;
+const int STACK_SIZE = (1024 * 1024);
+
+static int childFunc(void *arg)
+{
+ (void)arg;
+ sleep(2); /* 2: delay 2s */
+
+ return 0;
+}
+
+void ItProcessFs019(void)
+{
+ const int CONFIG_FILE_LEN = 1024;
+ char szFile[CONFIG_FILE_LEN] = {0};
+ std::string path = "/proc/sys/user/max_pid_container";
+ int fd = open(path.c_str(), O_WRONLY);
+ ASSERT_NE(fd, -1);
+
+ char buf[configLen];
+ size_t ret = sprintf_s(buf, configLen, "%d", invalidNum);
+ ASSERT_GT(ret, 0);
+ ret = write(fd, buf, (strlen(buf) + 1));
+ ASSERT_NE(ret, -1);
+
+ int arg = CHILD_FUNC_ARG;
+
+ char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
+ -1, 0);
+ ASSERT_NE(stack, NULL);
+ char *stackTop = stack + STACK_SIZE;
+
+ auto pid = clone(childFunc, stackTop, CLONE_NEWPID, &arg);
+ ASSERT_NE(pid, -1);
+ pid = clone(childFunc, stackTop, CLONE_NEWPID, &arg);
+ ASSERT_NE(pid, -1);
+
+ pid = clone(childFunc, stackTop, CLONE_NEWPID, &arg);
+ ASSERT_EQ(pid, -1);
+
+ (void)close(fd);
+}
diff --git a/testsuites/unittest/process/fs/smoke/It_process_fs_020.cpp b/testsuites/unittest/process/fs/smoke/It_process_fs_020.cpp
new file mode 100644
index 00000000..dcded33e
--- /dev/null
+++ b/testsuites/unittest/process/fs/smoke/It_process_fs_020.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "It_process_fs_test.h"
+
+static int const configLen = 16;
+static int const invalidNum = 2;
+static const int CHILD_FUNC_ARG = 0x2088;
+const int STACK_SIZE = (1024 * 1024);
+
+static int childFunc(void *arg)
+{
+ (void)arg;
+ sleep(2); /* 2: delay 2s */
+
+ return 0;
+}
+
+void ItProcessFs020(void)
+{
+ const int CONFIG_FILE_LEN = 1024;
+ char szFile[CONFIG_FILE_LEN] = {0};
+ std::string path = "/proc/sys/user/max_net_container";
+ int fd = open(path.c_str(), O_WRONLY);
+ ASSERT_NE(fd, -1);
+
+ char buf[configLen];
+ size_t ret = sprintf(buf, configLen, "%d", invalidNum);
+ ASSERT_GT(ret, 0);
+ ret = write(fd, buf, (strlen(buf) + 1));
+ ASSERT_NE(ret, -1);
+
+ int arg = CHILD_FUNC_ARG;
+
+ char *stack = (char *)mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
+ -1, 0);
+ ASSERT_NE(stack, NULL);
+ char *stackTop = stack + STACK_SIZE;
+
+ auto pid = clone(childFunc, stackTop, CLONE_NEWNET, &arg);
+ ASSERT_NE(pid, -1);
+ pid = clone(childFunc, stackTop, CLONE_NEWNET, &arg);
+ ASSERT_NE(pid, -1);
+
+ pid = clone(childFunc, stackTop, CLONE_NEWNET, &arg);
+ ASSERT_EQ(pid, -1);
+
+ (void)close(fd);
+}