Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
0c7dd0f9
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
461
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0c7dd0f9
编写于
1月 14, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 14, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1096 feat: 支持进程挂载目录和进程命名空间增强
Merge pull request !1096 from zhushengle/process_proc
上级
be9cee4c
41619f00
变更
41
隐藏空白更改
内联
并排
Showing
41 changed file
with
2018 addition
and
45 deletion
+2018
-45
fs/proc/Kconfig
fs/proc/Kconfig
+5
-0
fs/proc/include/internal.h
fs/proc/include/internal.h
+7
-1
fs/proc/include/proc_fs.h
fs/proc/include/proc_fs.h
+32
-1
fs/proc/os_adapt/proc_vfs.c
fs/proc/os_adapt/proc_vfs.c
+20
-3
fs/proc/os_adapt/process_proc.c
fs/proc/os_adapt/process_proc.c
+187
-3
fs/proc/src/proc_file.c
fs/proc/src/proc_file.c
+11
-3
fs/vfs/operation/vfs_other.c
fs/vfs/operation/vfs_other.c
+56
-29
kernel/base/container/los_container.c
kernel/base/container/los_container.c
+24
-1
kernel/base/container/los_pid_container.c
kernel/base/container/los_pid_container.c
+26
-0
kernel/base/container/los_uts_container.c
kernel/base/container/los_uts_container.c
+11
-0
kernel/base/core/los_process.c
kernel/base/core/los_process.c
+13
-0
kernel/base/include/los_container_pri.h
kernel/base/include/los_container_pri.h
+10
-0
kernel/base/include/los_pid_container_pri.h
kernel/base/include/los_pid_container_pri.h
+5
-0
kernel/base/include/los_process_pri.h
kernel/base/include/los_process_pri.h
+12
-0
kernel/base/include/los_uts_container_pri.h
kernel/base/include/los_uts_container_pri.h
+4
-3
testsuites/unittest/BUILD.gn
testsuites/unittest/BUILD.gn
+7
-1
testsuites/unittest/config.gni
testsuites/unittest/config.gni
+5
-0
testsuites/unittest/process/fs/BUILD.gn
testsuites/unittest/process/fs/BUILD.gn
+58
-0
testsuites/unittest/process/fs/It_process_fs_test.h
testsuites/unittest/process/fs/It_process_fs_test.h
+57
-0
testsuites/unittest/process/fs/config.gni
testsuites/unittest/process/fs/config.gni
+74
-0
testsuites/unittest/process/fs/process_fs_test.cpp
testsuites/unittest/process/fs/process_fs_test.cpp
+155
-0
testsuites/unittest/process/fs/smoke/It_process_fs_001.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_001.cpp
+44
-0
testsuites/unittest/process/fs/smoke/It_process_fs_002.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_002.cpp
+52
-0
testsuites/unittest/process/fs/smoke/It_process_fs_003.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_003.cpp
+54
-0
testsuites/unittest/process/fs/smoke/It_process_fs_004.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_004.cpp
+64
-0
testsuites/unittest/process/fs/smoke/It_process_fs_005.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_005.cpp
+65
-0
testsuites/unittest/process/fs/smoke/It_process_fs_006.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_006.cpp
+124
-0
testsuites/unittest/process/fs/smoke/It_process_fs_007.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_007.cpp
+49
-0
testsuites/unittest/process/fs/smoke/It_process_fs_008.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_008.cpp
+49
-0
testsuites/unittest/process/fs/smoke/It_process_fs_009.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_009.cpp
+49
-0
testsuites/unittest/process/fs/smoke/It_process_fs_010.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_010.cpp
+49
-0
testsuites/unittest/process/fs/smoke/It_process_fs_011.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_011.cpp
+49
-0
testsuites/unittest/process/fs/smoke/It_process_fs_012.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_012.cpp
+79
-0
testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp
+48
-0
testsuites/unittest/process/fs/smoke/It_process_fs_014.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_014.cpp
+39
-0
testsuites/unittest/process/fs/smoke/It_process_fs_015.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_015.cpp
+41
-0
testsuites/unittest/process/fs/smoke/It_process_fs_016.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_016.cpp
+76
-0
testsuites/unittest/process/fs/smoke/It_process_fs_017.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_017.cpp
+77
-0
testsuites/unittest/process/fs/smoke/It_process_fs_018.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_018.cpp
+77
-0
testsuites/unittest/process/fs/smoke/It_process_fs_019.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_019.cpp
+77
-0
testsuites/unittest/process/fs/smoke/It_process_fs_020.cpp
testsuites/unittest/process/fs/smoke/It_process_fs_020.cpp
+77
-0
未找到文件。
fs/proc/Kconfig
浏览文件 @
0c7dd0f9
...
...
@@ -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
fs/proc/include/internal.h
浏览文件 @
0c7dd0f9
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
1
Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
3
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
);
...
...
fs/proc/include/proc_fs.h
浏览文件 @
0c7dd0f9
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
1
Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
3
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
* <ul>
* <li>This interface should be called after system initialization.</li>
* <li>The parameter name should be a valid string.</li>
* </ul>
*
* @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:
* <ul><li>proc_fs.h: the header file that contains the API declaration.</li></ul>
* @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
...
...
fs/proc/os_adapt/proc_vfs.c
浏览文件 @
0c7dd0f9
/*
* Copyright (c) 2021-202
1
Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2021-202
3
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
=
{
...
...
fs/proc/os_adapt/process_proc.c
浏览文件 @
0c7dd0f9
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
1
Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
3
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 <sys/statfs.h>
#include <sys/mount.h>
#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
;
}
fs/proc/src/proc_file.c
浏览文件 @
0c7dd0f9
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
1
Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
3
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
;
}
}
...
...
fs/vfs/operation/vfs_other.c
浏览文件 @
0c7dd0f9
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
2
Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-202
3
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
;
}
}
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
)
{
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
);
fullpath_bak
=
fullpath
;
if
(
stat64
(
fullpath
,
&
stat64Info
)
==
0
)
{
if
(
S_ISLNK
(
stat64Info
.
st_mode
))
{
readlink
(
fullpath
,
linkName
,
NAME_MAX
);
}
free
(
fullpath_bak
);
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
;
}
kernel/base/container/los_container.c
浏览文件 @
0c7dd0f9
...
...
@@ -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
kernel/base/container/los_pid_container.c
浏览文件 @
0c7dd0f9
...
...
@@ -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
kernel/base/container/los_uts_container.c
浏览文件 @
0c7dd0f9
...
...
@@ -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
kernel/base/core/los_process.c
浏览文件 @
0c7dd0f9
...
...
@@ -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
;
...
...
kernel/base/include/los_container_pri.h
浏览文件 @
0c7dd0f9
...
...
@@ -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 */
kernel/base/include/los_pid_container_pri.h
浏览文件 @
0c7dd0f9
...
...
@@ -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 */
kernel/base/include/los_process_pri.h
浏览文件 @
0c7dd0f9
...
...
@@ -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.
*/
...
...
kernel/base/include/los_uts_container_pri.h
浏览文件 @
0c7dd0f9
...
...
@@ -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 */
testsuites/unittest/BUILD.gn
浏览文件 @
0c7dd0f9
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-202
1
Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-202
3
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" ]
}
}
}
...
...
testsuites/unittest/config.gni
浏览文件 @
0c7dd0f9
...
...
@@ -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
...
...
testsuites/unittest/process/fs/BUILD.gn
0 → 100644
浏览文件 @
0c7dd0f9
# 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" ]
}
}
testsuites/unittest/process/fs/It_process_fs_test.h
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <sys/time.h>
#include <sys/types.h>
#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
testsuites/unittest/process/fs/config.gni
0 → 100644
浏览文件 @
0c7dd0f9
# 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
}
testsuites/unittest/process/fs/process_fs_test.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#include <climits>
#include <gtest/gtest.h>
#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
}
testsuites/unittest/process/fs/smoke/It_process_fs_001.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#include <climits>
#include <gtest/gtest.h>
#include <sys/types.h>
#include <dirent.h>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_002.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_003.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_004.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_005.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_006.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
}
testsuites/unittest/process/fs/smoke/It_process_fs_007.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <sched.h>
#include <unistd.h>
#include <sys/stat.h>
#include <climits>
#include <string>
#include <iostream>
#include <regex>
#include "It_process_fs_test.h"
void
ItProcessFs007
(
void
)
{
auto
path
=
GenProcPidContainerPath
(
getpid
(),
"uts"
);
std
::
vector
<
char
>
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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_008.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <sched.h>
#include <unistd.h>
#include <sys/stat.h>
#include <climits>
#include <string>
#include <iostream>
#include <regex>
#include "It_process_fs_test.h"
void
ItProcessFs008
(
void
)
{
auto
path
=
GenProcPidContainerPath
(
getpid
(),
"mnt"
);
std
::
vector
<
char
>
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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_009.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <sched.h>
#include <unistd.h>
#include <sys/stat.h>
#include <climits>
#include <string>
#include <iostream>
#include <regex>
#include "It_process_fs_test.h"
void
ItProcessFs009
(
void
)
{
auto
path
=
GenProcPidContainerPath
(
getpid
(),
"user"
);
std
::
vector
<
char
>
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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_010.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <sched.h>
#include <unistd.h>
#include <sys/stat.h>
#include <climits>
#include <string>
#include <iostream>
#include <regex>
#include "It_process_fs_test.h"
void
ItProcessFs010
(
void
)
{
auto
path
=
GenProcPidContainerPath
(
getpid
(),
"pid"
);
std
::
vector
<
char
>
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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_011.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <sched.h>
#include <unistd.h>
#include <sys/stat.h>
#include <climits>
#include <string>
#include <iostream>
#include <regex>
#include "It_process_fs_test.h"
void
ItProcessFs011
(
void
)
{
auto
path
=
GenProcPidContainerPath
(
getpid
(),
"net"
);
std
::
vector
<
char
>
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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_012.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#include <climits>
#include <gtest/gtest.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_013.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <gtest/gtest.h>
#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
);
};
}
}
testsuites/unittest/process/fs/smoke/It_process_fs_014.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <gtest/gtest.h>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_015.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <gtest/gtest.h>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_016.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_017.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_018.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_019.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
testsuites/unittest/process/fs/smoke/It_process_fs_020.cpp
0 → 100644
浏览文件 @
0c7dd0f9
/*
* 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 <cstdio>
#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
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录