Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
10c5e2e6
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
464
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看板
未验证
提交
10c5e2e6
编写于
2月 23, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 23, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1124 限制对资源控制器的删除以及添加资源控制器测试用例
Merge pull request !1124 from zhushengle/cgroups_test
上级
f0a435dc
da9ce464
变更
61
隐藏空白更改
内联
并排
Showing
61 changed file
with
4109 addition
and
322 deletion
+4109
-322
fs/proc/os_adapt/plimits_proc.c
fs/proc/os_adapt/plimits_proc.c
+0
-166
fs/proc/src/proc_file.c
fs/proc/src/proc_file.c
+0
-4
kernel/extended/plimit/los_devicelimit.c
kernel/extended/plimit/los_devicelimit.c
+2
-16
kernel/extended/plimit/los_devicelimit.h
kernel/extended/plimit/los_devicelimit.h
+0
-3
kernel/extended/plimit/los_ipclimit.c
kernel/extended/plimit/los_ipclimit.c
+1
-6
kernel/extended/plimit/los_ipclimit.h
kernel/extended/plimit/los_ipclimit.h
+0
-2
kernel/extended/plimit/los_memlimit.c
kernel/extended/plimit/los_memlimit.c
+1
-6
kernel/extended/plimit/los_memlimit.h
kernel/extended/plimit/los_memlimit.h
+0
-2
kernel/extended/plimit/los_plimits.c
kernel/extended/plimit/los_plimits.c
+3
-76
kernel/extended/plimit/los_plimits.h
kernel/extended/plimit/los_plimits.h
+0
-3
kernel/extended/plimit/los_processlimit.c
kernel/extended/plimit/los_processlimit.c
+1
-17
kernel/extended/plimit/los_processlimit.h
kernel/extended/plimit/los_processlimit.h
+0
-3
kernel/extended/plimit/los_schedlimit.c
kernel/extended/plimit/los_schedlimit.c
+1
-15
kernel/extended/plimit/los_schedlimit.h
kernel/extended/plimit/los_schedlimit.h
+0
-3
testsuites/unittest/BUILD.gn
testsuites/unittest/BUILD.gn
+6
-0
testsuites/unittest/config.gni
testsuites/unittest/config.gni
+5
-0
testsuites/unittest/process/plimits/BUILD.gn
testsuites/unittest/process/plimits/BUILD.gn
+58
-0
testsuites/unittest/process/plimits/It_process_plimits.h
testsuites/unittest/process/plimits/It_process_plimits.h
+136
-0
testsuites/unittest/process/plimits/config.gni
testsuites/unittest/process/plimits/config.gni
+100
-0
testsuites/unittest/process/plimits/process_plimits_test.cpp
testsuites/unittest/process/plimits/process_plimits_test.cpp
+901
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_001.cpp
...unittest/process/plimits/smoke/It_process_plimits_001.cpp
+55
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_002.cpp
...unittest/process/plimits/smoke/It_process_plimits_002.cpp
+43
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_003.cpp
...unittest/process/plimits/smoke/It_process_plimits_003.cpp
+43
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_004.cpp
...unittest/process/plimits/smoke/It_process_plimits_004.cpp
+60
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_005.cpp
...unittest/process/plimits/smoke/It_process_plimits_005.cpp
+43
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_006.cpp
...unittest/process/plimits/smoke/It_process_plimits_006.cpp
+99
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_007.cpp
...unittest/process/plimits/smoke/It_process_plimits_007.cpp
+66
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_008.cpp
...unittest/process/plimits/smoke/It_process_plimits_008.cpp
+88
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_001.cpp
.../process/plimits/smoke/It_process_plimits_devices_001.cpp
+65
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_002.cpp
.../process/plimits/smoke/It_process_plimits_devices_002.cpp
+66
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_003.cpp
.../process/plimits/smoke/It_process_plimits_devices_003.cpp
+65
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_004.cpp
.../process/plimits/smoke/It_process_plimits_devices_004.cpp
+65
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_005.cpp
.../process/plimits/smoke/It_process_plimits_devices_005.cpp
+65
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_006.cpp
.../process/plimits/smoke/It_process_plimits_devices_006.cpp
+65
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_007.cpp
.../process/plimits/smoke/It_process_plimits_devices_007.cpp
+65
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_008.cpp
.../process/plimits/smoke/It_process_plimits_devices_008.cpp
+65
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_009.cpp
.../process/plimits/smoke/It_process_plimits_devices_009.cpp
+65
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_002.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_002.cpp
+59
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_003.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_003.cpp
+67
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_004.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_004.cpp
+72
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_005.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_005.cpp
+85
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_006.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_006.cpp
+119
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_007.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_007.cpp
+57
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_008.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_008.cpp
+77
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_009.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_009.cpp
+73
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_010.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_010.cpp
+100
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_011.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_011.cpp
+58
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_012.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_012.cpp
+77
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_013.cpp
...test/process/plimits/smoke/It_process_plimits_ipc_013.cpp
+111
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_001.cpp
...t/process/plimits/smoke/It_process_plimits_memory_001.cpp
+87
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_002.cpp
...t/process/plimits/smoke/It_process_plimits_memory_002.cpp
+90
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_001.cpp
...test/process/plimits/smoke/It_process_plimits_pid_001.cpp
+108
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_002.cpp
...test/process/plimits/smoke/It_process_plimits_pid_002.cpp
+108
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_003.cpp
...test/process/plimits/smoke/It_process_plimits_pid_003.cpp
+93
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_004.cpp
...test/process/plimits/smoke/It_process_plimits_pid_004.cpp
+63
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_005.cpp
...test/process/plimits/smoke/It_process_plimits_pid_005.cpp
+78
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_006.cpp
...test/process/plimits/smoke/It_process_plimits_pid_006.cpp
+63
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_001.cpp
...st/process/plimits/smoke/It_process_plimits_sched_001.cpp
+42
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_002.cpp
...st/process/plimits/smoke/It_process_plimits_sched_002.cpp
+42
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_003.cpp
...st/process/plimits/smoke/It_process_plimits_sched_003.cpp
+41
-0
testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_004.cpp
...st/process/plimits/smoke/It_process_plimits_sched_004.cpp
+41
-0
未找到文件。
fs/proc/os_adapt/plimits_proc.c
浏览文件 @
10c5e2e6
...
...
@@ -68,8 +68,6 @@ static ssize_t PidLimitReadPriorityLimit(struct SeqBuf *seqBuf, VOID *data);
static
ssize_t
PriorityLimitVariableWrite
(
struct
ProcFile
*
pf
,
const
CHAR
*
buf
,
size_t
count
,
loff_t
*
ppos
);
static
ssize_t
PidsMaxVariableWrite
(
struct
ProcFile
*
pf
,
const
CHAR
*
buf
,
size_t
count
,
loff_t
*
ppos
);
static
ssize_t
ProcLimitsShowLimiters
(
struct
SeqBuf
*
seqBuf
,
VOID
*
data
);
static
ssize_t
ProcLimitsDeleteLimiters
(
struct
ProcFile
*
pf
,
const
CHAR
*
buf
,
size_t
count
,
loff_t
*
ppos
);
static
ssize_t
ProcLimitsAddLimiters
(
struct
ProcFile
*
pf
,
const
CHAR
*
buf
,
size_t
count
,
loff_t
*
ppos
);
static
int
ProcfsPlimitsMkdir
(
struct
ProcDirEntry
*
parent
,
const
char
*
dirName
,
mode_t
mode
,
struct
ProcDirEntry
**
pde
);
static
int
ProcfsPlimitsRmdir
(
struct
ProcDirEntry
*
parent
,
struct
ProcDirEntry
*
pde
,
const
char
*
name
);
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
...
...
@@ -120,24 +118,6 @@ static struct PLimitsEntryOpt g_plimitsEntryOpts[] = {
.
read
=
ProcLimitsShowLimiters
,
}
},
{
.
id
=
PROCESS_LIMITER_COUNT
,
.
name
=
"plimits.limiter_add"
,
.
mode
=
PLIMIT_FILE_MODE_READ_WRITE
,
.
offset
=
UNITPTR_NULL
,
.
ops
=
{
.
write
=
ProcLimitsAddLimiters
,
},
},
{
.
id
=
PROCESS_LIMITER_COUNT
,
.
name
=
"plimits.limiter_delete"
,
.
mode
=
PLIMIT_FILE_MODE_READ_WRITE
,
.
offset
=
UNITPTR_NULL
,
.
ops
=
{
.
write
=
ProcLimitsDeleteLimiters
,
},
},
{
.
id
=
PROCESS_LIMITER_COUNT
,
.
name
=
"plimits.procs"
,
...
...
@@ -458,152 +438,6 @@ static ssize_t ProcLimitsShowLimiters(struct SeqBuf *seqBuf, VOID *data)
return
LOS_OK
;
}
static
ssize_t
ProcLimitsAddLimiters
(
struct
ProcFile
*
pf
,
const
CHAR
*
buf
,
size_t
count
,
loff_t
*
ppos
)
{
(
VOID
)
ppos
;
unsigned
int
ret
;
struct
ProcDirEntry
*
dirEntry
=
pf
->
pPDE
;
ProcLimiterSet
*
plimits
=
GetProcLimiterSetFromDirEntry
(
dirEntry
);
char
*
kbuf
=
NULL
;
ret
=
MemUserCopy
(
buf
,
count
,
&
kbuf
);
if
(
ret
!=
0
)
{
return
-
ret
;
}
else
if
((
ret
==
0
)
&&
(
kbuf
!=
NULL
))
{
buf
=
(
const
char
*
)
kbuf
;
}
enum
ProcLimiterID
procLimiterID
=
0
;
if
(
strcmp
(
buf
,
"pids"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_PIDS
;
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
}
else
if
(
strcmp
(
buf
,
"memory"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_MEM
;
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
}
else
if
(
strcmp
(
buf
,
"ipc"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_IPC
;
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
}
else
if
(
strcmp
(
buf
,
"devices"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_DEV
;
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
}
else
if
(
strcmp
(
buf
,
"sched"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_SCHED
;
#endif
}
else
{
(
void
)
LOS_MemFree
(
m_aucSysMem1
,
kbuf
);
PRINTK
(
"enter error, please check the params.
\n
"
);
return
-
EINVAL
;
}
(
void
)
LOS_MemFree
(
m_aucSysMem1
,
kbuf
);
ret
=
OsPLimitsAddLimiters
(
plimits
,
procLimiterID
);
if
(
ret
!=
LOS_OK
)
{
return
-
ret
;
}
ProcLimiterDirEntryInit
(
dirEntry
,
BIT
(
procLimiterID
),
PLIMIT_FILE_MODE_MASK_NONE
);
return
count
;
}
static
struct
ProcDirEntry
*
PLimitsProcFindEntry
(
const
char
*
name
,
struct
ProcDirEntry
*
parent
)
{
int
len
=
strlen
(
name
);
struct
ProcDirEntry
*
pn
=
NULL
;
for
(
pn
=
parent
->
subdir
;
pn
!=
NULL
;
pn
=
pn
->
next
)
{
if
(
ProcMatch
(
len
,
name
,
pn
))
{
break
;
}
}
return
pn
;
}
static
int
DeleteProcEntry
(
const
char
*
buf
,
struct
ProcDirEntry
*
currDirectory
)
{
struct
ProcDirEntry
*
entry
=
PLimitsProcFindEntry
(
buf
,
currDirectory
);
if
(
entry
==
NULL
)
{
return
EINVAL
;
}
ProcDetachNode
(
entry
);
ProcEntryClearVnode
(
entry
);
ProcFreeEntry
(
entry
);
return
0
;
}
static
int
PLimitsDeleteProcEntry
(
enum
ProcLimiterID
procLimiterID
,
struct
ProcDirEntry
*
currDirectory
)
{
for
(
int
index
=
0
;
index
<
(
sizeof
(
g_plimitsEntryOpts
)
/
sizeof
(
struct
PLimitsEntryOpt
));
index
++
)
{
struct
PLimitsEntryOpt
*
entryOpt
=
&
g_plimitsEntryOpts
[
index
];
if
(
entryOpt
->
id
!=
procLimiterID
)
{
continue
;
}
(
void
)
DeleteProcEntry
(
entryOpt
->
name
,
currDirectory
);
}
return
0
;
}
static
ssize_t
ProcLimitsDeleteLimiters
(
struct
ProcFile
*
pf
,
const
CHAR
*
buf
,
size_t
count
,
loff_t
*
ppos
)
{
(
VOID
)
ppos
;
unsigned
ret
;
unsigned
mask
=
0
;
enum
ProcLimiterID
procLimiterID
=
0
;
char
*
kbuf
=
NULL
;
if
((
pf
==
NULL
)
||
(
pf
->
pPDE
==
NULL
))
{
return
-
EINVAL
;
}
struct
ProcDirEntry
*
pde
=
pf
->
pPDE
;
struct
ProcDirEntry
*
currDirectory
=
GetCurrDirectory
(
pde
);
if
((
currDirectory
==
NULL
)
||
(
currDirectory
->
data
==
NULL
))
{
return
-
EINVAL
;
}
ProcLimiterSet
*
plimits
=
(
ProcLimiterSet
*
)
currDirectory
->
data
;
ret
=
MemUserCopy
(
buf
,
count
,
&
kbuf
);
if
(
ret
!=
0
)
{
return
-
ret
;
}
else
if
((
ret
==
0
)
&&
(
kbuf
!=
NULL
))
{
buf
=
(
const
char
*
)
kbuf
;
}
if
(
strcmp
(
buf
,
"pids"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_PIDS
;
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
}
else
if
(
strcmp
(
buf
,
"memory"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_MEM
;
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
}
else
if
(
strcmp
(
buf
,
"ipc"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_IPC
;
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
}
else
if
(
strcmp
(
buf
,
"devices"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_DEV
;
#endif
#ifdef LOSCFG_KERNEL_SCHED_PLIMIT
}
else
if
(
strcmp
(
buf
,
"sched"
)
==
0
)
{
procLimiterID
=
PROCESS_LIMITER_ID_SCHED
;
#endif
}
else
{
PRINTK
(
"the input information or format is incorrect.
\n
"
);
(
void
)
LOS_MemFree
(
m_aucSysMem1
,
kbuf
);
return
-
EINVAL
;
}
(
void
)
LOS_MemFree
(
m_aucSysMem1
,
kbuf
);
ret
=
OsPLimitsDeleteLimiters
(
plimits
,
procLimiterID
,
&
mask
);
if
(
ret
!=
LOS_OK
)
{
return
-
ret
;
}
PLimitsDeleteProcEntry
(
procLimiterID
,
currDirectory
);
return
count
;
}
#define PLIMITS_PID_STR_LENGTH 4
static
int
ShowPids
(
struct
SeqBuf
*
seqBuf
,
VOID
*
data
)
{
...
...
fs/proc/src/proc_file.c
浏览文件 @
10c5e2e6
...
...
@@ -645,15 +645,11 @@ int WriteProcFile(struct ProcDirEntry *pde, const void *buf, size_t len)
return
-
EISDIR
;
}
#ifndef LOSCFG_KERNEL_PLIMITS
spin_lock
(
&
procfsLock
);
#endif
if
((
pde
->
procFileOps
!=
NULL
)
&&
(
pde
->
procFileOps
->
write
!=
NULL
))
{
result
=
pde
->
procFileOps
->
write
(
pde
->
pf
,
(
const
char
*
)
buf
,
len
,
&
(
pde
->
pf
->
fPos
));
}
#ifndef LOSCFG_KERNEL_PLIMITS
spin_unlock
(
&
procfsLock
);
#endif
return
result
;
}
...
...
kernel/extended/plimit/los_devicelimit.c
浏览文件 @
10c5e2e6
...
...
@@ -58,7 +58,6 @@ VOID *OsDevLimitAlloc(VOID)
(
VOID
)
memset_s
(
plimit
,
sizeof
(
ProcDevLimit
),
0
,
sizeof
(
ProcDevLimit
));
LOS_ListInit
(
&
(
plimit
->
accessList
));
plimit
->
behavior
=
DEVLIMIT_DEFAULT_NONE
;
LOS_AtomicSet
(
&
plimit
->
rc
,
1
);
return
(
VOID
*
)
plimit
;
}
...
...
@@ -79,11 +78,8 @@ VOID OsDevLimitFree(UINTPTR limit)
return
;
}
LOS_AtomicDec
(
&
devLimit
->
rc
);
if
(
LOS_AtomicRead
(
&
devLimit
->
rc
)
<=
0
)
{
DevAccessListDelete
(
devLimit
);
LOS_KernelFree
(
devLimit
);
}
DevAccessListDelete
(
devLimit
);
LOS_KernelFree
(
devLimit
);
}
STATIC
UINT32
DevLimitCopyAccess
(
ProcDevLimit
*
devLimitDest
,
ProcDevLimit
*
devLimitSrc
)
...
...
@@ -110,16 +106,6 @@ VOID OsDevLimitCopy(UINTPTR dest, UINTPTR src)
devLimitDest
->
parent
=
(
ProcDevLimit
*
)
src
;
}
VOID
OsDevLimitMigrate
(
UINTPTR
currLimit
,
UINTPTR
parentLimit
,
UINTPTR
process
)
{
(
VOID
)
currLimit
;
ProcDevLimit
*
parentDevLimit
=
(
ProcDevLimit
*
)
parentLimit
;
LosProcessCB
*
pcb
=
(
LosProcessCB
*
)
process
;
if
(
pcb
==
NULL
)
{
LOS_AtomicInc
(
&
parentDevLimit
->
rc
);
}
}
STATIC
INLINE
INT32
IsSpace
(
INT32
c
)
{
return
(
c
==
' '
||
(
unsigned
)
c
-
'\t'
<
BUF_SEPARATOR
);
...
...
kernel/extended/plimit/los_devicelimit.h
浏览文件 @
10c5e2e6
...
...
@@ -32,7 +32,6 @@
#define _LOS_DEVICELIMIT_H
#include "los_typedef.h"
#include "los_atomic.h"
#include "los_list.h"
#include "vfs_config.h"
...
...
@@ -74,7 +73,6 @@ typedef struct DevAccessItem {
typedef
struct
ProcDevLimit
{
struct
ProcDevLimit
*
parent
;
Atomic
rc
;
UINT8
allowFile
;
UINT8
denyFile
;
LOS_DL_LIST
accessList
;
// device belong to devicelimite
...
...
@@ -85,7 +83,6 @@ VOID OsDevLimitInit(UINTPTR limit);
VOID
*
OsDevLimitAlloc
(
VOID
);
VOID
OsDevLimitFree
(
UINTPTR
limit
);
VOID
OsDevLimitCopy
(
UINTPTR
dest
,
UINTPTR
src
);
VOID
OsDevLimitMigrate
(
UINTPTR
currLimit
,
UINTPTR
parentLimit
,
UINTPTR
process
);
UINT32
OsDevLimitWriteAllow
(
ProcLimitSet
*
plimit
,
const
CHAR
*
buf
,
UINT32
size
);
UINT32
OsDevLimitWriteDeny
(
ProcLimitSet
*
plimit
,
const
CHAR
*
buf
,
UINT32
size
);
UINT32
OsDevLimitShow
(
ProcDevLimit
*
devLimit
,
struct
SeqBuf
*
seqBuf
);
...
...
kernel/extended/plimit/los_ipclimit.c
浏览文件 @
10c5e2e6
...
...
@@ -50,7 +50,6 @@ VOID *OsIPCLimitAlloc(VOID)
return
NULL
;
}
(
VOID
)
memset_s
(
plimite
,
sizeof
(
ProcIPCLimit
),
0
,
sizeof
(
ProcIPCLimit
));
LOS_AtomicSet
(
&
plimite
->
rc
,
1
);
return
(
VOID
*
)
plimite
;
}
...
...
@@ -61,10 +60,7 @@ VOID OsIPCLimitFree(UINTPTR limite)
return
;
}
LOS_AtomicDec
(
&
plimite
->
rc
);
if
(
LOS_AtomicRead
(
&
plimite
->
rc
)
<=
0
)
{
LOS_KernelFree
((
VOID
*
)
plimite
);
}
LOS_KernelFree
((
VOID
*
)
plimite
);
}
VOID
OsIPCLimitCopy
(
UINTPTR
dest
,
UINTPTR
src
)
...
...
@@ -101,7 +97,6 @@ VOID OsIPCLimitMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process)
parentIpcLimit
->
mqFailedCount
+=
currIpcLimit
->
mqFailedCount
;
parentIpcLimit
->
shmSize
+=
currIpcLimit
->
shmSize
;
parentIpcLimit
->
shmFailedCount
+=
currIpcLimit
->
shmFailedCount
;
LOS_AtomicInc
(
&
parentIpcLimit
->
rc
);
return
;
}
...
...
kernel/extended/plimit/los_ipclimit.h
浏览文件 @
10c5e2e6
...
...
@@ -32,7 +32,6 @@
#define _LOS_IPCLIMIT_H
#include "los_typedef.h"
#include "los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
...
...
@@ -41,7 +40,6 @@ extern "C" {
#endif
/* __cplusplus */
typedef
struct
ProcIPCLimit
{
Atomic
rc
;
UINT32
mqCount
;
UINT32
mqFailedCount
;
UINT32
mqCountLimit
;
...
...
kernel/extended/plimit/los_memlimit.c
浏览文件 @
10c5e2e6
...
...
@@ -57,7 +57,6 @@ VOID *OsMemLimiterAlloc(VOID)
return
NULL
;
}
(
VOID
)
memset_s
(
plimite
,
sizeof
(
ProcMemLimiter
),
0
,
sizeof
(
ProcMemLimiter
));
LOS_AtomicSet
(
&
plimite
->
rc
,
1
);
return
(
VOID
*
)
plimite
;
}
...
...
@@ -68,10 +67,7 @@ VOID OsMemLimiterFree(UINTPTR limite)
return
;
}
LOS_AtomicDec
(
&
plimite
->
rc
);
if
(
LOS_AtomicRead
(
&
plimite
->
rc
)
<=
0
)
{
LOS_KernelFree
((
VOID
*
)
limite
);
}
LOS_KernelFree
((
VOID
*
)
limite
);
}
VOID
OsMemLimiterCopy
(
UINTPTR
dest
,
UINTPTR
src
)
...
...
@@ -104,7 +100,6 @@ VOID OsMemLimiterMigrate(UINTPTR currLimit, UINTPTR parentLimit, UINTPTR process
if
(
parentMemLimit
->
peak
<
parentMemLimit
->
usage
)
{
parentMemLimit
->
peak
=
parentMemLimit
->
usage
;
}
LOS_AtomicInc
(
&
parentMemLimit
->
rc
);
return
;
}
...
...
kernel/extended/plimit/los_memlimit.h
浏览文件 @
10c5e2e6
...
...
@@ -32,7 +32,6 @@
#define _LOS_MEMLIMIT_H
#include "los_typedef.h"
#include "los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
...
...
@@ -41,7 +40,6 @@ extern "C" {
#endif
/* __cplusplus */
typedef
struct
ProcMemLimiter
{
Atomic
rc
;
UINT64
usage
;
UINT64
limit
;
UINT64
peak
;
...
...
kernel/extended/plimit/los_plimits.c
浏览文件 @
10c5e2e6
...
...
@@ -56,7 +56,7 @@ static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = {
.
LimiterAddProcess
=
OsPidLimitAddProcess
,
.
LimiterDelProcess
=
OsPidLimitDelProcess
,
.
LimiterMigrateCheck
=
PidLimitMigrateCheck
,
.
LimiterMigrate
=
OsPidLimiterMigrate
,
.
LimiterMigrate
=
NULL
,
},
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
[
PROCESS_LIMITER_ID_MEM
]
=
{
...
...
@@ -81,7 +81,7 @@ static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = {
.
LimiterAddProcess
=
NULL
,
.
LimiterDelProcess
=
NULL
,
.
LimiterMigrateCheck
=
NULL
,
.
LimiterMigrate
=
OsSchedLimitMigrate
,
.
LimiterMigrate
=
NULL
,
},
#endif
#ifdef LOSCFG_KERNEL_DEV_PLIMIT
...
...
@@ -94,7 +94,7 @@ static PlimiteOperations g_limiteOps[PROCESS_LIMITER_COUNT] = {
.
LimiterAddProcess
=
NULL
,
.
LimiterDelProcess
=
NULL
,
.
LimiterMigrateCheck
=
NULL
,
.
LimiterMigrate
=
OsDevLimitMigrate
,
.
LimiterMigrate
=
NULL
,
},
#endif
#ifdef LOSCFG_KERNEL_IPC_PLIMIT
...
...
@@ -360,79 +360,6 @@ ProcLimiterSet *OsPLimitsCreate(ProcLimiterSet *parentPLimits)
return
newPLimits
;
}
UINT32
OsPLimitsAddLimiters
(
ProcLimiterSet
*
procLimiterSet
,
enum
ProcLimiterID
plimiteID
)
{
UINT32
intSave
;
UINT32
mask
=
BIT
(
plimiteID
);
if
((
procLimiterSet
==
NULL
)
||
(
plimiteID
>
PROCESS_LIMITER_COUNT
))
{
return
EINVAL
;
}
SCHEDULER_LOCK
(
intSave
);
if
(
procLimiterSet
->
level
==
0
)
{
SCHEDULER_UNLOCK
(
intSave
);
return
EPERM
;
}
if
(
procLimiterSet
->
mask
&
mask
)
{
SCHEDULER_UNLOCK
(
intSave
);
return
EINVAL
;
}
UINTPTR
currLimit
=
procLimiterSet
->
limitsList
[
plimiteID
];
UINTPTR
parentPLimit
=
procLimiterSet
->
parent
->
limitsList
[
plimiteID
];
procLimiterSet
->
limitsList
[
plimiteID
]
=
(
UINTPTR
)
g_limiteOps
[
plimiteID
].
LimiterAlloc
();
if
(
procLimiterSet
->
limitsList
[
plimiteID
]
==
(
UINTPTR
)
NULL
)
{
procLimiterSet
->
limitsList
[
plimiteID
]
=
parentPLimit
;
SCHEDULER_UNLOCK
(
intSave
);
return
ENOMEM
;
}
g_limiteOps
[
plimiteID
].
LimiterCopy
(
procLimiterSet
->
limitsList
[
plimiteID
],
parentPLimit
);
g_limiteOps
[
plimiteID
].
LimiterMigrate
(
procLimiterSet
->
limitsList
[
plimiteID
],
parentPLimit
,
(
UINTPTR
)
OsCurrProcessGet
());
g_limiteOps
[
plimiteID
].
LimiterFree
(
currLimit
);
SCHEDULER_UNLOCK
(
intSave
);
return
LOS_OK
;
}
UINT32
OsPLimitsDeleteLimiters
(
ProcLimiterSet
*
procLimiterSet
,
enum
ProcLimiterID
plimiteID
,
UINT32
*
mask
)
{
UINT32
intSave
;
if
((
procLimiterSet
==
NULL
)
||
(
plimiteID
>
PROCESS_LIMITER_COUNT
)
||
(
mask
==
NULL
))
{
return
EINVAL
;
}
SCHEDULER_LOCK
(
intSave
);
if
(
!
(
procLimiterSet
->
mask
&
BIT
(
plimiteID
)))
{
SCHEDULER_UNLOCK
(
intSave
);
return
EINVAL
;
}
if
(
procLimiterSet
->
level
==
0
)
{
SCHEDULER_UNLOCK
(
intSave
);
return
EPERM
;
}
UINTPTR
currLimit
=
procLimiterSet
->
limitsList
[
plimiteID
];
UINTPTR
parentPLimit
=
procLimiterSet
->
parent
->
limitsList
[
plimiteID
];
if
((
g_limiteOps
[
plimiteID
].
LimiterMigrateCheck
!=
NULL
)
&&
!
g_limiteOps
[
plimiteID
].
LimiterMigrateCheck
(
currLimit
,
parentPLimit
))
{
SCHEDULER_UNLOCK
(
intSave
);
return
EINVAL
;
}
g_limiteOps
[
plimiteID
].
LimiterMigrate
(
currLimit
,
parentPLimit
,
0
);
procLimiterSet
->
limitsList
[
plimiteID
]
=
parentPLimit
;
g_limiteOps
[
plimiteID
].
LimiterFree
(
currLimit
);
procLimiterSet
->
mask
&=
(
~
BIT
(
plimiteID
));
*
mask
=
procLimiterSet
->
mask
;
SCHEDULER_UNLOCK
(
intSave
);
return
LOS_OK
;
}
#ifdef LOSCFG_KERNEL_MEM_PLIMIT
UINT32
OsPLimitsMemUsageGet
(
ProcLimiterSet
*
plimits
,
UINT64
*
usage
,
UINT32
size
)
{
...
...
kernel/extended/plimit/los_plimits.h
浏览文件 @
10c5e2e6
...
...
@@ -101,9 +101,6 @@ UINT32 OsPLimitsFree(ProcLimiterSet *currPLimits);
ProcLimiterSet
*
OsPLimitsCreate
(
ProcLimiterSet
*
parentProcLimiterSet
);
UINT32
OsProcLimiterSetInit
(
VOID
);
UINT32
OsPLimitsAddLimiters
(
ProcLimiterSet
*
procLimiterSet
,
enum
ProcLimiterID
plimiteID
);
UINT32
OsPLimitsDeleteLimiters
(
ProcLimiterSet
*
procLimiterSet
,
enum
ProcLimiterID
plimiteID
,
UINT32
*
mask
);
UINT32
OsPLimitsMemUsageGet
(
ProcLimiterSet
*
plimits
,
UINT64
*
usage
,
UINT32
size
);
UINT32
OsPLimitsIPCStatGet
(
ProcLimiterSet
*
plimits
,
ProcIPCLimit
*
ipc
,
UINT32
size
);
UINT32
OsPLimitsSchedUsageGet
(
ProcLimiterSet
*
plimits
,
UINT64
*
usage
,
UINT32
size
);
...
...
kernel/extended/plimit/los_processlimit.c
浏览文件 @
10c5e2e6
...
...
@@ -57,7 +57,6 @@ VOID *PidLimiterAlloc(VOID)
return
NULL
;
}
(
VOID
)
memset_s
(
plimite
,
sizeof
(
PidLimit
),
0
,
sizeof
(
PidLimit
));
LOS_AtomicSet
(
&
plimite
->
rc
,
1
);
return
(
VOID
*
)
plimite
;
}
...
...
@@ -68,10 +67,7 @@ VOID PidLimterFree(UINTPTR limit)
return
;
}
LOS_AtomicDec
(
&
pidLimit
->
rc
);
if
(
LOS_AtomicRead
(
&
pidLimit
->
rc
)
<=
0
)
{
LOS_KernelFree
((
VOID
*
)
limit
);
}
LOS_KernelFree
((
VOID
*
)
limit
);
}
BOOL
PidLimitMigrateCheck
(
UINTPTR
curr
,
UINTPTR
parent
)
...
...
@@ -88,18 +84,6 @@ BOOL PidLimitMigrateCheck(UINTPTR curr, UINTPTR parent)
return
TRUE
;
}
VOID
OsPidLimiterMigrate
(
UINTPTR
currLimit
,
UINTPTR
parentLimit
,
UINTPTR
process
)
{
(
VOID
)
currLimit
;
PidLimit
*
parentPidLimit
=
(
PidLimit
*
)
parentLimit
;
LosProcessCB
*
pcb
=
(
LosProcessCB
*
)
process
;
if
(
pcb
==
NULL
)
{
LOS_AtomicInc
(
&
parentPidLimit
->
rc
);
}
}
BOOL
OsPidLimitAddProcessCheck
(
UINTPTR
limit
,
UINTPTR
process
)
{
(
VOID
)
process
;
...
...
kernel/extended/plimit/los_processlimit.h
浏览文件 @
10c5e2e6
...
...
@@ -33,7 +33,6 @@
#include "los_list.h"
#include "los_typedef.h"
#include "los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
...
...
@@ -42,7 +41,6 @@ extern "C" {
#endif
/* __cplusplus */
typedef
struct
PidLimit
{
Atomic
rc
;
UINT32
pidLimit
;
UINT32
priorityLimit
;
UINT32
pidCount
;
...
...
@@ -53,7 +51,6 @@ VOID *PidLimiterAlloc(VOID);
VOID
PidLimterFree
(
UINTPTR
limit
);
VOID
PidLimiterCopy
(
UINTPTR
curr
,
UINTPTR
parent
);
BOOL
PidLimitMigrateCheck
(
UINTPTR
curr
,
UINTPTR
parent
);
VOID
OsPidLimiterMigrate
(
UINTPTR
currLimit
,
UINTPTR
parentLimit
,
UINTPTR
process
);
BOOL
OsPidLimitAddProcessCheck
(
UINTPTR
limit
,
UINTPTR
process
);
VOID
OsPidLimitAddProcess
(
UINTPTR
limit
,
UINTPTR
process
);
VOID
OsPidLimitDelProcess
(
UINTPTR
limit
,
UINTPTR
process
);
...
...
kernel/extended/plimit/los_schedlimit.c
浏览文件 @
10c5e2e6
...
...
@@ -49,7 +49,6 @@ VOID *OsSchedLimitAlloc(VOID)
return
NULL
;
}
(
VOID
)
memset_s
(
plimit
,
sizeof
(
ProcSchedLimiter
),
0
,
sizeof
(
ProcSchedLimiter
));
LOS_AtomicSet
(
&
plimit
->
rc
,
1
);
return
(
VOID
*
)
plimit
;
}
...
...
@@ -60,10 +59,7 @@ VOID OsSchedLimitFree(UINTPTR limit)
return
;
}
LOS_AtomicDec
(
&
schedLimit
->
rc
);
if
(
LOS_AtomicRead
(
&
schedLimit
->
rc
)
<=
0
)
{
LOS_KernelFree
((
VOID
*
)
limit
);
}
LOS_KernelFree
((
VOID
*
)
limit
);
}
VOID
OsSchedLimitCopy
(
UINTPTR
dest
,
UINTPTR
src
)
...
...
@@ -75,16 +71,6 @@ VOID OsSchedLimitCopy(UINTPTR dest, UINTPTR src)
return
;
}
VOID
OsSchedLimitMigrate
(
UINTPTR
currLimit
,
UINTPTR
parentLimit
,
UINTPTR
process
)
{
(
VOID
)
currLimit
;
ProcSchedLimiter
*
parentSchedLimit
=
(
ProcSchedLimiter
*
)
parentLimit
;
LosProcessCB
*
pcb
=
(
LosProcessCB
*
)
process
;
if
(
pcb
==
NULL
)
{
LOS_AtomicInc
(
&
parentSchedLimit
->
rc
);
}
}
VOID
OsSchedLimitUpdateRuntime
(
LosTaskCB
*
runTask
,
UINT64
currTime
,
INT32
incTime
)
{
LosProcessCB
*
run
=
(
LosProcessCB
*
)
runTask
->
processCB
;
...
...
kernel/extended/plimit/los_schedlimit.h
浏览文件 @
10c5e2e6
...
...
@@ -32,7 +32,6 @@
#define _LOS_SCHEDLIMIT_H
#include "los_typedef.h"
#include "los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
...
...
@@ -44,7 +43,6 @@ extern "C" {
typedef
struct
TagTaskCB
LosTaskCB
;
typedef
struct
ProcSchedLimiter
{
Atomic
rc
;
UINT64
startTime
;
UINT64
endTime
;
UINT64
period
;
...
...
@@ -58,7 +56,6 @@ VOID OsSchedLimitInit(UINTPTR limit);
VOID
*
OsSchedLimitAlloc
(
VOID
);
VOID
OsSchedLimitFree
(
UINTPTR
limit
);
VOID
OsSchedLimitCopy
(
UINTPTR
dest
,
UINTPTR
src
);
VOID
OsSchedLimitMigrate
(
UINTPTR
currLimit
,
UINTPTR
parentLimit
,
UINTPTR
process
);
VOID
OsSchedLimitUpdateRuntime
(
LosTaskCB
*
runTask
,
UINT64
currTime
,
INT32
incTime
);
UINT32
OsSchedLimitSetPeriod
(
ProcSchedLimiter
*
schedLimit
,
UINT64
value
);
UINT32
OsSchedLimitSetQuota
(
ProcSchedLimiter
*
schedLimit
,
UINT64
value
);
...
...
testsuites/unittest/BUILD.gn
浏览文件 @
10c5e2e6
...
...
@@ -138,6 +138,9 @@ group("unittest") {
if (LOSCFG_USER_TEST_PROCESS_FS == true) {
deps += [ "process/fs:liteos_a_process_fs_unittest_door" ]
}
if (LOSCFG_USER_TEST_PROCESS_PLIMITS == true) {
deps += [ "process/plimits:liteos_a_process_plimits_unittest_door" ]
}
}
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
deps += [ "process/basic:liteos_a_process_basic_unittest" ]
...
...
@@ -145,6 +148,9 @@ group("unittest") {
if (LOSCFG_USER_TEST_PROCESS_FS == true) {
deps += [ "process/fs:liteos_a_process_fs_unittest" ]
}
if (LOSCFG_USER_TEST_PROCESS_PLIMITS == true) {
deps += [ "process/plimits:liteos_a_process_plimits_unittest" ]
}
}
}
...
...
testsuites/unittest/config.gni
浏览文件 @
10c5e2e6
...
...
@@ -165,6 +165,11 @@ if (defined(LOSCFG_KERNEL_CONTAINER) || liteos_container_test_enable == true) {
}
}
LOSCFG_USER_TEST_PROCESS_PLIMITS = false
if (defined(LOSCFG_KERNEL_PLIMITS) || liteos_container_test_enable == true) {
LOSCFG_USER_TEST_PROCESS_PLIMITS = true
}
########## fuzz test ##########
LOSCFG_USER_FUZZ_TEST = false
if (liteos_fuzz_test_enable == true) {
...
...
testsuites/unittest/process/plimits/BUILD.gn
0 → 100644
浏览文件 @
10c5e2e6
# 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_plimits_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_plimits_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/plimits/It_process_plimits.h
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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_PLIMITS_H
#define _IT_PROCESS_PLIMITS_H
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <regex>
#include <fcntl.h>
#include <iostream>
#include <cstring>
#include <fstream>
#include <regex>
#include <sstream>
#include <numeric>
#include "osTest.h"
#define MEM_PAGE_SIZE 4096
#define MEM_SLEEP_TIME 5
#define MEM_RESERVED_PAGE 2
#define CHILD_FUNC_ARG (0x2088)
#define STACK_SIZE (1024 * 1024)
#define PROCESS_LIMIT_AMOUNT (64)
#define TEST_BUFFER_SIZE (512)
#define CPUP10S_INDEX (11)
#define CPUP1S_INDEX (12)
#define WAIT_CPUP_STABLE (7)
#define WAIT_CPUP_STABLE_FOR_100 (17)
#define STATISTIC_TIMES (11)
#define PERIOD_10_SEC_IN_US (10 * 1000 * 1000)
#define QUOTA_2_SEC_IN_US (2 * 1000 * 1000)
#define QUOTA_5_SEC_IN_US (5 * 1000 * 1000)
#define QUOTA_6_SEC_IN_US (6 * 1000 * 1000)
#define QUOTA_7_SEC_IN_US (7 * 1000 * 1000)
#define QUOTA_10_SEC_IN_US (10 * 1000 * 1000)
#define QUOTA_PERCENT_20 (20)
#define QUOTA_PERCENT_50 (50)
#define QUOTA_PERCENT_60 (60)
#define QUOTA_PERCENT_70 (70)
#define QUOTA_PERCENT_100 (100)
#define HARDWARE_CORE_AMOUNT (2)
#define TOLERANCE_ERROR (5)
int
WriteFile
(
const
char
*
filepath
,
const
char
*
buf
);
int
RmdirLimiterFile
(
std
::
string
path
);
int
RmdirControlFile
(
std
::
string
path
);
int
ReadFile
(
const
char
*
filepath
,
char
*
buf
);
int
GetLine
(
char
*
buf
,
int
count
,
int
maxLen
,
char
**
array
);
int
RmdirTest
(
std
::
string
path
);
extern
UINT32
LosCurTaskIDGet
();
int
ForkChilds
(
int
num
,
int
*
pidArray
);
int
CreatePlimitGroup
(
const
char
*
groupName
,
char
*
childPidFiles
,
unsigned
long
long
periodUs
,
unsigned
long
long
quotaUs
);
int
AddPidIntoSchedLimiters
(
int
num
,
int
*
pidArray
,
const
char
*
procspath
);
int
WaitForCpupStable
(
int
expectedCpupPercent
);
double
CalcCpupUsage
(
int
childAmount
,
int
*
childPidArray
,
int
expectedCpupPercent
);
double
CheckCpupUsage
(
double
sumAllChildsCpup
,
int
expectedCpupPercent
);
int
TerminateChildProcess
(
int
*
childPidArray
,
int
childAmount
,
int
sig
);
double
TestCpupInPlimit
(
int
childAmount
,
const
char
*
groupName
,
unsigned
long
long
periodUs
,
unsigned
long
long
quotaUs
,
int
expectedCpupPercent
);
double
TestCpupWithoutLimit
(
int
childAmount
,
const
char
*
groupName
,
int
expectedCpupPercent
);
#if defined(LOSCFG_USER_TEST_SMOKE)
void
ItProcessPlimits001
(
void
);
void
ItProcessPlimits002
(
void
);
void
ItProcessPlimits003
(
void
);
void
ItProcessPlimits004
(
void
);
void
ItProcessPlimits005
(
void
);
void
ItProcessPlimits006
(
void
);
void
ItProcessPlimits007
(
void
);
void
ItProcessPlimits008
(
void
);
void
ItProcessPlimitsMemory001
(
void
);
void
ItProcessPlimitsMemory002
(
void
);
void
ItProcessPlimitsPid001
(
void
);
void
ItProcessPlimitsPid002
(
void
);
void
ItProcessPlimitsPid003
(
void
);
void
ItProcessPlimitsPid004
(
void
);
void
ItProcessPlimitsPid005
(
void
);
void
ItProcessPlimitsPid006
(
void
);
void
ItProcessPlimitsSched001
(
VOID
);
void
ItProcessPlimitsSched002
(
VOID
);
void
ItProcessPlimitsSched003
(
VOID
);
void
ItProcessPlimitsSched004
(
VOID
);
void
ItProcessPlimitsDevices001
(
void
);
void
ItProcessPlimitsDevices002
(
void
);
void
ItProcessPlimitsDevices003
(
void
);
void
ItProcessPlimitsDevices004
(
void
);
void
ItProcessPlimitsDevices005
(
void
);
void
ItProcessPlimitsDevices006
(
void
);
void
ItProcessPlimitsDevices007
(
void
);
void
ItProcessPlimitsDevices008
(
void
);
void
ItProcessPlimitsDevices009
(
void
);
void
ItProcessPlimitsIpc002
(
void
);
void
ItProcessPlimitsIpc003
(
void
);
void
ItProcessPlimitsIpc004
(
void
);
void
ItProcessPlimitsIpc005
(
void
);
void
ItProcessPlimitsIpc006
(
void
);
void
ItProcessPlimitsIpc007
(
void
);
void
ItProcessPlimitsIpc008
(
void
);
void
ItProcessPlimitsIpc009
(
void
);
void
ItProcessPlimitsIpc010
(
void
);
void
ItProcessPlimitsIpc011
(
void
);
void
ItProcessPlimitsIpc012
(
void
);
void
ItProcessPlimitsIpc013
(
void
);
#endif
#endif
/* _IT_PROCESS_PLIMITS_H */
testsuites/unittest/process/plimits/config.gni
0 → 100644
浏览文件 @
10c5e2e6
# 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_plimits_include_dirs = [ "$TEST_UNITTEST_DIR/process/plimits" ]
process_plimits_sources_entry =
[ "$TEST_UNITTEST_DIR/process/plimits/process_plimits_test.cpp" ]
process_plimits_sources_smoke = [
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_001.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_002.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_003.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_004.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_005.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_006.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_007.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_008.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_001.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_002.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_003.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_004.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_005.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_pid_006.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_memory_001.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_memory_002.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_001.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_002.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_003.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_sched_004.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_001.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_002.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_003.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_004.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_005.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_006.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_007.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_008.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_devices_009.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_002.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_003.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_004.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_005.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_006.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_007.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_008.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_009.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_010.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_011.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_012.cpp",
"$TEST_UNITTEST_DIR/process/plimits/smoke/It_process_plimits_ipc_013.cpp",
]
process_plimits_sources_full = []
# plimits module
if (LOSCFG_USER_TEST_PROCESS == true) {
common_include_dirs += process_plimits_include_dirs
sources_entry += process_plimits_sources_entry
sources_smoke += process_plimits_sources_smoke
sources_full += process_plimits_sources_full
}
testsuites/unittest/process/plimits/process_plimits_test.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <climits>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <fcntl.h>
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include "It_process_plimits.h"
using
namespace
std
;
using
namespace
testing
::
ext
;
namespace
OHOS
{
class
ProcessPlimitsTest
:
public
testing
::
Test
{
public:
static
void
SetUpTestCase
(
void
)
{}
static
void
TearDownTestCase
(
void
)
{}
protected:
virtual
void
SetUp
();
virtual
void
TearDown
();
private:
inline
bool
IsFile
(
const
std
::
string
&
file
);
inline
bool
IsDir
(
const
std
::
string
&
path
);
inline
bool
IsSpecialDir
(
const
std
::
string
&
path
);
};
#if defined(LOSCFG_USER_TEST_SMOKE)
/**
* @tc.name: plimits_Test_001
* @tc.desc: plimits function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimits001
,
TestSize
.
Level0
)
{
ItProcessPlimits001
();
}
/**
* @tc.name: plimits_Test_002
* @tc.desc: plimits function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimits002
,
TestSize
.
Level0
)
{
ItProcessPlimits002
();
}
/**
* @tc.name: plimits_Test_003
* @tc.desc: plimits function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimits003
,
TestSize
.
Level0
)
{
ItProcessPlimits003
();
}
/**
* @tc.name: plimits_Test_004
* @tc.desc: plimits function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimits004
,
TestSize
.
Level0
)
{
ItProcessPlimits004
();
}
/**
* @tc.name: plimits_Test_005
* @tc.desc: plimits function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimits005
,
TestSize
.
Level0
)
{
ItProcessPlimits005
();
}
/**
* @tc.name: plimits_Test_006
* @tc.desc: plimits function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimits006
,
TestSize
.
Level0
)
{
ItProcessPlimits006
();
}
/**
* @tc.name: plimits_Test_007
* @tc.desc: plimits function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimits007
,
TestSize
.
Level0
)
{
ItProcessPlimits007
();
}
/**
* @tc.name: plimits_Test_008
* @tc.desc: plimits function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimits008
,
TestSize
.
Level0
)
{
ItProcessPlimits008
();
}
/**
* @tc.name: plimits_pid_Test_001
* @tc.desc: pid plimit function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsPid001
,
TestSize
.
Level0
)
{
ItProcessPlimitsPid001
();
}
/**
* @tc.name: plimits_pid_Test_002
* @tc.desc: pid plimit function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsPid002
,
TestSize
.
Level0
)
{
ItProcessPlimitsPid002
();
}
/**
* @tc.name: plimits_pid_Test_003
* @tc.desc: pid plimit function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsPid003
,
TestSize
.
Level0
)
{
ItProcessPlimitsPid003
();
}
/**
* @tc.name: plimits_pid_Test_004
* @tc.desc: pid plimit function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsPid004
,
TestSize
.
Level0
)
{
ItProcessPlimitsPid004
();
}
/**
* @tc.name: plimits_pid_Test_005
* @tc.desc: pid plimit function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsPid005
,
TestSize
.
Level0
)
{
ItProcessPlimitsPid005
();
}
/**
* @tc.name: plimits_pid_Test_006
* @tc.desc: pid plimit function test case
* @tc.type: FUNC
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsPid006
,
TestSize
.
Level0
)
{
ItProcessPlimitsPid006
();
}
/**
* @tc.name: plimits_Mem_Test_001
* @tc.desc: mem plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsMemory001
,
TestSize
.
Level0
)
{
ItProcessPlimitsMemory001
();
}
/**
* @tc.name: plimits_Mem_Test_002
* @tc.desc: mem plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsMemory002
,
TestSize
.
Level0
)
{
ItProcessPlimitsMemory002
();
}
/**
* @tc.name: plimits_Dev_Test_001
* @tc.desc: devices plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsDevices001
,
TestSize
.
Level0
)
{
ItProcessPlimitsDevices001
();
}
/**
* @tc.name: plimits_Dev_Test_002
* @tc.desc: devices plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsDevices002
,
TestSize
.
Level0
)
{
ItProcessPlimitsDevices002
();
}
/**
* @tc.name: plimits_Dev_Test_003
* @tc.desc: devices plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsDevices003
,
TestSize
.
Level0
)
{
ItProcessPlimitsDevices003
();
}
/**
* @tc.name: plimits_Dev_Test_004
* @tc.desc: devices plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsDevices004
,
TestSize
.
Level0
)
{
ItProcessPlimitsDevices004
();
}
/**
* @tc.name: plimits_Dev_Test_005
* @tc.desc: devices plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsDevices005
,
TestSize
.
Level0
)
{
ItProcessPlimitsDevices005
();
}
/**
* @tc.name: plimits_Dev_Test_006
* @tc.desc: devices plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsDevices006
,
TestSize
.
Level0
)
{
ItProcessPlimitsDevices006
();
}
/**
* @tc.name: plimits_Dev_Test_007
* @tc.desc: devices plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsDevices007
,
TestSize
.
Level0
)
{
ItProcessPlimitsDevices007
();
}
/**
* @tc.name: plimits_Dev_Test_008
* @tc.desc: devices plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsDevices008
,
TestSize
.
Level0
)
{
ItProcessPlimitsDevices008
();
}
/**
* @tc.name: plimits_Dev_Test_009
* @tc.desc: devices plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsDevices009
,
TestSize
.
Level0
)
{
ItProcessPlimitsDevices009
();
}
/**
* @tc.name: plimits_Ipc_Test_002
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc002
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc002
();
}
/**
* @tc.name: plimits_Ipc_Test_003
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc003
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc003
();
}
/**
* @tc.name: plimits_Ipc_Test_004
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc004
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc004
();
}
/**
* @tc.name: plimits_Ipc_Test_005
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc005
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc005
();
}
/**
* @tc.name: plimits_Ipc_Test_006
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc006
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc006
();
}
/**
* @tc.name: plimits_Ipc_Test_007
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc007
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc007
();
}
/**
* @tc.name: plimits_Ipc_Test_008
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc008
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc008
();
}
/**
* @tc.name: plimits_Ipc_Test_009
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc009
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc009
();
}
/**
* @tc.name: plimits_Ipc_Test_010
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc010
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc010
();
}
/**
* @tc.name: plimits_Ipc_Test_011
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc011
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc011
();
}
/**
* @tc.name: plimits_Ipc_Test_012
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc012
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc012
();
}
/**
* @tc.name: plimits_Ipc_Test_013
* @tc.desc: ipc plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
ItProcessPlimitsIpc013
,
TestSize
.
Level0
)
{
ItProcessPlimitsIpc013
();
}
/**
* @tc.name: plimits_Sched_Test_001
* @tc.desc: sched plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
IItProcessPlimitsSched001
,
TestSize
.
Level0
)
{
ItProcessPlimitsSched001
();
}
/**
* @tc.name: plimits_Sched_Test_002
* @tc.desc: sched plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
IItProcessPlimitsSched002
,
TestSize
.
Level0
)
{
ItProcessPlimitsSched002
();
}
/**
* @tc.name: plimits_Sched_Test_003
* @tc.desc: sched plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
IItProcessPlimitsSched003
,
TestSize
.
Level0
)
{
ItProcessPlimitsSched003
();
}
/**
* @tc.name: plimits_Sched_Test_004
* @tc.desc: sched plimit function test case
* @tc.require: issueI6GVPL
* @tc.author:
*/
HWTEST_F
(
ProcessPlimitsTest
,
IItProcessPlimitsSched004
,
TestSize
.
Level0
)
{
ItProcessPlimitsSched004
();
}
#endif
}
// namespace OHOS
namespace
OHOS
{
void
ProcessPlimitsTest
::
SetUp
()
{
(
void
)
rmdir
(
"/proc/plimits/test"
);
}
void
ProcessPlimitsTest
::
TearDown
()
{
(
void
)
rmdir
(
"/proc/plimits/test"
);
}
bool
ProcessPlimitsTest
::
IsFile
(
const
std
::
string
&
file
)
{
struct
stat
statbuf
;
return
(
lstat
(
file
.
c_str
(),
&
statbuf
)
==
0
)
&&
S_ISREG
(
statbuf
.
st_mode
);
}
bool
ProcessPlimitsTest
::
IsDir
(
const
std
::
string
&
path
)
{
struct
stat
statbuf
;
return
(
lstat
(
path
.
c_str
(),
&
statbuf
)
==
0
)
&&
S_ISDIR
(
statbuf
.
st_mode
);
}
bool
ProcessPlimitsTest
::
IsSpecialDir
(
const
std
::
string
&
path
)
{
return
strcmp
(
path
.
c_str
(),
"."
)
==
0
||
strcmp
(
path
.
c_str
(),
".."
)
==
0
;
}
}
// namespace OHOS
int
ReadFile
(
const
char
*
filepath
,
char
*
buf
)
{
FILE
*
fpid
=
nullptr
;
fpid
=
fopen
(
filepath
,
"r"
);
if
(
fpid
==
nullptr
)
{
return
-
1
;
}
size_t
trd
=
fread
(
buf
,
1
,
512
,
fpid
);
(
void
)
fclose
(
fpid
);
return
trd
;
}
int
WriteFile
(
const
char
*
filepath
,
const
char
*
buf
)
{
int
fd
=
open
(
filepath
,
O_WRONLY
);
if
(
fd
==
-
1
)
{
return
-
1
;
}
size_t
twd
=
write
(
fd
,
buf
,
strlen
(
buf
));
if
(
twd
==
-
1
)
{
(
void
)
close
(
fd
);
return
-
1
;
}
(
void
)
close
(
fd
);
return
twd
;
}
int
GetLine
(
char
*
buf
,
int
count
,
int
maxLen
,
char
**
array
)
{
char
*
head
=
buf
;
char
*
tail
=
buf
;
char
index
=
0
;
if
((
buf
==
NULL
)
||
(
strlen
(
buf
)
==
0
))
{
return
0
;
}
while
(
*
tail
!=
'\0'
)
{
if
(
*
tail
!=
'\n'
)
{
tail
++
;
continue
;
}
if
(
index
>=
count
)
{
return
index
+
1
;
}
array
[
index
]
=
head
;
index
++
;
*
tail
=
'\0'
;
if
(
strlen
(
head
)
>
maxLen
)
{
return
index
+
1
;
}
tail
++
;
head
=
tail
;
tail
++
;
}
return
(
index
+
1
);
}
int
RmdirTest
(
std
::
string
path
)
{
int
ret
;
RmdirControlFile
(
path
);
ret
=
rmdir
(
path
.
c_str
());
ICUNIT_ASSERT_EQUAL
(
ret
,
0
,
ret
);
return
0
;
}
int
WaitForCpupStable
(
int
expectedCpupPercent
)
{
int
sleepTime
;
if
(
expectedCpupPercent
>=
QUOTA_PERCENT_100
)
{
sleepTime
=
WAIT_CPUP_STABLE_FOR_100
;
}
else
{
sleepTime
=
WAIT_CPUP_STABLE
;
}
return
sleep
(
sleepTime
);
}
static
int
SampleRound
(
void
)
{
return
STATISTIC_TIMES
;
}
static
vector
<
string
>
GetProcessInfo
(
pid_t
pid
)
{
vector
<
string
>
contentArr
;
char
buf
[
TEST_BUFFER_SIZE
+
1
]
=
{
0
};
string
strpid
=
to_string
(
pid
);
ifstream
infile
;
infile
.
open
(
"/proc/process"
);
while
(
!
infile
.
eof
())
{
infile
.
getline
(
buf
,
TEST_BUFFER_SIZE
);
regex
e
(
"^
\\
s+"
+
strpid
);
int
matchResult
=
regex_search
(
buf
,
e
);
if
(
matchResult
==
1
)
{
istringstream
str
(
buf
);
string
out
;
while
(
str
>>
out
)
{
contentArr
.
push_back
(
out
);
}
break
;
}
(
void
)
memset_s
(
buf
,
TEST_BUFFER_SIZE
,
0
,
TEST_BUFFER_SIZE
);
}
infile
.
close
();
(
void
)
memset_s
(
buf
,
TEST_BUFFER_SIZE
,
0
,
TEST_BUFFER_SIZE
);
return
contentArr
;
}
static
void
SigQuit
(
int
s
)
{
exit
(
0
);
}
static
int
ChildRunCpup
()
{
struct
sigaction
act
;
act
.
sa_handler
=
SigQuit
;
(
void
)
sigaction
(
SIGUSR1
,
&
act
,
NULL
);
unsigned
long
x
=
1
;
unsigned
long
y
=
1
;
while
(
1
)
{
y
++
;
x
*=
y
;
}
return
0
;
}
int
ForkChilds
(
int
num
,
int
*
pidArray
)
{
pid_t
childPid
;
pid_t
pidArrayLocal
[
PROCESS_LIMIT_AMOUNT
];
for
(
int
idx
=
0
;
idx
<
num
;
idx
++
)
{
childPid
=
fork
();
if
(
childPid
==
0
)
{
(
void
)
ChildRunCpup
();
}
else
if
(
childPid
>
0
)
{
pidArrayLocal
[
idx
]
=
childPid
;
*
pidArray
=
childPid
;
pidArray
++
;
}
else
{
return
-
errno
;
}
}
return
0
;
}
static
double
GetCpup
(
pid_t
pid
)
{
auto
content
=
GetProcessInfo
(
pid
);
double
cpup10s
=
atof
(
content
[
CPUP10S_INDEX
].
c_str
());
return
cpup10s
;
}
static
int
CollectCpupData
(
int
childAmount
,
int
sampleSeconds
,
int
*
pidArray
,
vector
<
vector
<
double
>>
&
cpupValuesArray
)
{
double
cpup10s
;
for
(
int
i
=
0
;
i
<
sampleSeconds
;
i
++
)
{
for
(
int
j
=
0
;
j
<
childAmount
;
j
++
)
{
cpup10s
=
GetCpup
(
pidArray
[
j
]);
cpupValuesArray
[
j
].
push_back
(
cpup10s
);
}
sleep
(
1
);
}
return
0
;
}
static
int
CalcAverageCpup
(
int
num
,
vector
<
vector
<
double
>>
&
cpupValuesArray
,
double
*
cpupAverageArray
)
{
double
cpup10sAverage
;
for
(
int
idx
=
0
;
idx
<
num
;
idx
++
)
{
auto
size
=
cpupValuesArray
[
idx
].
size
();
cpup10sAverage
=
std
::
accumulate
(
cpupValuesArray
[
idx
].
begin
(),
cpupValuesArray
[
idx
].
end
(),
0.0
)
/
size
;
cpupAverageArray
[
idx
]
=
cpup10sAverage
;
}
return
0
;
}
int
CreatePlimitGroup
(
const
char
*
groupName
,
char
*
childPidFiles
,
unsigned
long
long
periodUs
,
unsigned
long
long
quotaUs
)
{
int
ret
;
mode_t
mode
=
0777
;
char
dirpath
[
TEST_BUFFER_SIZE
];
char
procspath
[
TEST_BUFFER_SIZE
];
char
periodpath
[
TEST_BUFFER_SIZE
];
char
quotapath
[
TEST_BUFFER_SIZE
];
char
periodValue
[
TEST_BUFFER_SIZE
];
char
quotaValue
[
TEST_BUFFER_SIZE
];
if
(
sprintf_s
(
dirpath
,
TEST_BUFFER_SIZE
,
"/proc/plimits/%s"
,
groupName
)
<
0
)
{
return
-
1
;
}
if
(
sprintf_s
(
procspath
,
TEST_BUFFER_SIZE
,
"%s/plimits.procs"
,
dirpath
)
<
0
)
{
return
-
1
;
}
if
(
sprintf_s
(
periodpath
,
TEST_BUFFER_SIZE
,
"%s/sched.period"
,
dirpath
)
<
0
)
{
return
-
1
;
}
if
(
sprintf_s
(
quotapath
,
TEST_BUFFER_SIZE
,
"%s/sched.quota"
,
dirpath
)
<
0
)
{
return
-
1
;
}
ret
=
access
(
dirpath
,
0
);
ICUNIT_ASSERT_EQUAL
(
ret
,
-
1
,
ret
);
ret
=
mkdir
(
dirpath
,
mode
);
ICUNIT_ASSERT_EQUAL
(
ret
,
0
,
ret
);
if
(
sprintf_s
(
periodValue
,
TEST_BUFFER_SIZE
,
"%llu"
,
periodUs
)
<
0
)
{
return
-
1
;
}
if
(
sprintf_s
(
quotaValue
,
TEST_BUFFER_SIZE
,
"%llu"
,
quotaUs
)
<
0
)
{
return
-
1
;
}
ret
=
WriteFile
(
periodpath
,
periodValue
);
if
(
ret
<
0
)
{
printf
(
"%s %d
\n
"
,
__FUNCTION__
,
__LINE__
);
return
ret
;
}
ret
=
WriteFile
(
quotapath
,
quotaValue
);
if
(
ret
<
0
)
{
printf
(
"%s %d
\n
"
,
__FUNCTION__
,
__LINE__
);
return
ret
;
}
if
(
sprintf_s
(
childPidFiles
,
TEST_BUFFER_SIZE
,
"%s"
,
procspath
)
<
0
)
{
return
-
1
;
}
return
0
;
}
int
CreatePlimitGroupWithoutLimit
(
const
char
*
groupName
,
char
*
childPidFiles
)
{
int
ret
;
mode_t
mode
=
0777
;
char
dirpath
[
TEST_BUFFER_SIZE
];
char
procspath
[
TEST_BUFFER_SIZE
];
if
(
sprintf_s
(
dirpath
,
TEST_BUFFER_SIZE
,
"/proc/plimits/%s"
,
groupName
)
<
0
)
{
return
-
1
;
}
if
(
sprintf_s
(
procspath
,
TEST_BUFFER_SIZE
,
"%s/plimits.procs"
,
dirpath
)
<
0
)
{
return
-
1
;
}
ret
=
access
(
dirpath
,
0
);
ICUNIT_ASSERT_EQUAL
(
ret
,
-
1
,
ret
);
ret
=
mkdir
(
dirpath
,
mode
);
ICUNIT_ASSERT_EQUAL
(
ret
,
0
,
ret
);
if
(
sprintf_s
(
childPidFiles
,
TEST_BUFFER_SIZE
,
"%s"
,
procspath
)
<
0
)
{
return
-
1
;
}
return
0
;
}
int
TerminateChildProcess
(
int
*
childPidArray
,
int
childAmount
,
int
sig
)
{
int
idx
;
for
(
idx
=
0
;
idx
<
childAmount
;
idx
++
)
{
(
void
)
kill
(
childPidArray
[
idx
],
SIGUSR1
);
int
status
;
(
void
)
waitpid
(
childPidArray
[
idx
],
&
status
,
0
);
}
(
void
)
signal
(
SIGUSR1
,
SIG_DFL
);
return
0
;
}
double
CalcCpupUsage
(
int
childAmount
,
int
*
childPidArray
,
int
expectedCpupPercent
)
{
int
idx
;
int
sampleSeconds
=
SampleRound
();
vector
<
vector
<
double
>>
cpupValuesArray
(
PROCESS_LIMIT_AMOUNT
);
(
void
)
CollectCpupData
(
childAmount
,
sampleSeconds
,
&
childPidArray
[
0
],
cpupValuesArray
);
double
actualCpup10sArray
[
PROCESS_LIMIT_AMOUNT
];
(
void
)
CalcAverageCpup
(
childAmount
,
cpupValuesArray
,
&
actualCpup10sArray
[
0
]);
double
sumAllChildsCpup
=
0
;
for
(
idx
=
0
;
idx
<
childAmount
;
idx
++
)
{
sumAllChildsCpup
+=
actualCpup10sArray
[
idx
];
}
return
sumAllChildsCpup
;
}
double
CheckCpupUsage
(
double
sumAllChildsCpup
,
int
expectedCpupPercent
)
{
if
(
expectedCpupPercent
<=
0.0
)
{
return
500.0
;
/* 500.0: errno */
}
double
errorRate
=
fabs
(
sumAllChildsCpup
/
expectedCpupPercent
-
1.0
);
return
errorRate
;
}
int
checkCpupUsageGreaterThan
(
double
sumAllChildsCpup
,
int
expectedCpupPercent
)
{
if
(
sumAllChildsCpup
>
expectedCpupPercent
)
{
return
0
;
}
else
{
return
-
1
;
}
}
double
TestCpupInPlimit
(
int
childAmount
,
const
char
*
groupName
,
unsigned
long
long
periodUs
,
unsigned
long
long
quotaUs
,
int
expectedCpupPercent
)
{
char
dirpath
[
TEST_BUFFER_SIZE
];
pid_t
childPidArray
[
PROCESS_LIMIT_AMOUNT
];
char
procspath
[
TEST_BUFFER_SIZE
];
double
sumAllChildsCpup
=
0
;
int
ret
=
CreatePlimitGroup
(
groupName
,
procspath
,
periodUs
,
quotaUs
);
if
(
ret
<
0
)
{
printf
(
"%s %d, ret=%d
\n
"
,
__FUNCTION__
,
__LINE__
,
ret
);
return
100.0
;
/* 100.0: errno */
}
ret
=
ForkChilds
(
childAmount
,
&
childPidArray
[
0
]);
if
(
ret
!=
0
)
{
printf
(
"%s %d, ret=%d
\n
"
,
__FUNCTION__
,
__LINE__
,
ret
);
return
200.0
;
/* 200.0: errno */
}
(
void
)
WaitForCpupStable
(
expectedCpupPercent
);
sumAllChildsCpup
=
CalcCpupUsage
(
childAmount
,
&
childPidArray
[
0
],
0
);
double
errorRate
=
CheckCpupUsage
(
sumAllChildsCpup
,
expectedCpupPercent
);
(
void
)
TerminateChildProcess
(
&
childPidArray
[
0
],
childAmount
,
SIGUSR1
);
if
(
sprintf_s
(
dirpath
,
TEST_BUFFER_SIZE
,
"/proc/plimits/%s"
,
groupName
)
<
0
)
{
return
300.0
;
/* 300.0: errno */
}
ret
=
rmdir
(
dirpath
);
if
(
ret
!=
0
)
{
printf
(
"%s %d, ret=%d
\n
"
,
__FUNCTION__
,
__LINE__
,
errno
);
return
400.0
;
/* 400.0: errno */
}
return
errorRate
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_001.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <climits>
#include <sys/types.h>
#include <gtest/gtest.h>
#include <dirent.h>
#include "It_process_plimits.h"
void
ItProcessPlimits001
(
void
)
{
DIR
*
dirp
=
opendir
(
"/proc/plimits"
);
ASSERT_NE
(
dirp
,
nullptr
);
(
void
)
closedir
(
dirp
);
int
ret
;
std
::
string
path
=
"/proc/plimits/test1"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IRWXU
);
// create directory
ASSERT_EQ
(
ret
,
0
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_002.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <cstdlib>
#include <unistd.h>
#include <fcntl.h>
#include "It_process_plimits.h"
void
ItProcessPlimits002
(
void
)
{
(
void
)
rmdir
(
"/proc/plimits"
);
DIR
*
dirp
=
opendir
(
"/proc/plimits/"
);
ASSERT_NE
(
dirp
,
nullptr
);
(
void
)
closedir
(
dirp
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_003.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include "It_process_plimits.h"
void
ItProcessPlimits003
(
void
)
{
int
ret
;
const
char
*
path
=
"/proc/text.txt"
;
ret
=
open
(
path
,
O_CREAT
);
ASSERT_EQ
(
ret
,
-
1
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_004.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <dirent.h>
#include <sys/stat.h>
#include <regex>
#include <fstream>
#include "It_process_plimits.h"
void
ItProcessPlimits004
(
void
)
{
int
ret
,
matchResult
;
const
size_t
BUFFER_SIZE
=
512
;
char
buf
[
BUFFER_SIZE
+
1
]
=
{
0
};
std
::
string
path
=
"/proc/plimits/test"
;
mode_t
mode
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
(
void
)
ReadFile
(
"/proc/plimits/test/plimits.limiters"
,
buf
);
printf
(
"/proc/plimits/test/plimits.limiters: %s
\n
"
,
buf
);
matchResult
=
strncmp
(
buf
,
"pids memory ipc devices sched"
,
29
);
/* 29: buf len */
ASSERT_EQ
(
matchResult
,
0
);
ret
=
rmdir
(
"/proc/plimits/test"
);
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_005.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <cstdlib>
#include <unistd.h>
#include <fcntl.h>
#include "It_process_plimits.h"
void
ItProcessPlimits005
(
void
)
{
int
ret
;
const
char
*
path
=
"/proc/plimits/text.txt"
;
ret
=
open
(
path
,
O_CREAT
);
ASSERT_EQ
(
ret
,
-
1
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_006.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include "It_process_plimits.h"
void
ItProcessPlimits006
(
void
)
{
int
ret
;
const
char
*
path3
=
"/proc/plimits/plimits.procs"
;
ret
=
remove
(
path3
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path4
=
"/proc/plimits/pids.max"
;
ret
=
remove
(
path4
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path5
=
"/proc/plimits/pids.priority"
;
ret
=
remove
(
path5
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path6
=
"/proc/plimits/sched.period"
;
ret
=
remove
(
path6
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path7
=
"/proc/plimits/sched.quota"
;
ret
=
remove
(
path7
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path8
=
"/proc/plimits/sched.stat"
;
ret
=
remove
(
path8
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path9
=
"/proc/plimits/memory.limit"
;
ret
=
remove
(
path9
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path10
=
"/proc/plimits/memory.stat"
;
ret
=
remove
(
path10
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path11
=
"/proc/plimits/ipc.mq_limit"
;
ret
=
remove
(
path11
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path12
=
"/proc/plimits/ipc.shm_limit"
;
ret
=
remove
(
path12
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path13
=
"/proc/plimits/ipc.stat"
;
ret
=
remove
(
path13
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path14
=
"/proc/plimits/devices.list"
;
ret
=
remove
(
path14
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path15
=
"/proc/plimits/devices.deny"
;
ret
=
remove
(
path15
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path16
=
"/proc/plimits/devices.allow"
;
ret
=
remove
(
path16
);
ASSERT_EQ
(
ret
,
-
1
);
const
char
*
path17
=
"/proc/plimits/limiters"
;
ret
=
remove
(
path17
);
ASSERT_EQ
(
ret
,
-
1
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_007.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <cstdlib>
#include <unistd.h>
#include <fcntl.h>
#include <cstring>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <climits>
#include "It_process_plimits.h"
void
ItProcessPlimits007
(
void
)
{
mode_t
mode
=
S_IRWXU
;
std
::
string
path0
=
"/proc/plimits/test"
;
std
::
string
path1
=
"/proc/plimits/test/subtest"
;
std
::
string
path2
=
"/proc/plimits/test/subtest/subtest"
;
std
::
string
path3
=
"/proc/plimits/test/subtest/subtest/subtest"
;
std
::
string
path4
=
"/proc/plimits/test/subtest/subtest/subtest/subtest"
;
int
ret
=
mkdir
(
path0
.
c_str
(),
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
mkdir
(
path1
.
c_str
(),
mode
);
ASSERT_EQ
(
ret
,
-
1
);
ret
=
mkdir
(
path2
.
c_str
(),
mode
);
ASSERT_EQ
(
ret
,
-
1
);
ret
=
mkdir
(
path3
.
c_str
(),
mode
);
ASSERT_EQ
(
ret
,
-
1
);
ret
=
mkdir
(
path4
.
c_str
(),
mode
);
ASSERT_EQ
(
ret
,
-
1
);
ret
=
rmdir
(
path0
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_008.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <cstdlib>
#include <climits>
#include <sys/types.h>
#include <gtest/gtest.h>
#include <dirent.h>
#include <unistd.h>
#include <vector>
#include <cstring>
#include "It_process_plimits.h"
static
std
::
string
GetFileMode
(
const
char
*
filePath
)
{
const
int
MODE_COUNT
=
11
;
char
fileProperty
[
MODE_COUNT
]
=
"----------"
;
char
fileMode
[
MODE_COUNT
]
=
"-rwxrwxrwx"
;
struct
stat
buf
;
stat
(
filePath
,
&
buf
);
unsigned
int
off
=
256
;
const
int
LOOP_VARY
=
10
;
for
(
int
i
=
1
;
i
<
LOOP_VARY
;
i
++
)
{
if
(
buf
.
st_mode
&
(
off
>>
(
i
-
1
)))
{
fileProperty
[
i
]
=
fileMode
[
i
];
}
}
return
fileProperty
;
}
static
int
IsFilePropertyR1
(
const
char
*
filePath
)
{
std
::
string
fileOrg
=
"-r--r--r--"
;
std
::
string
fileProperty
=
GetFileMode
(
filePath
);
return
strcmp
(
fileProperty
.
c_str
(),
fileOrg
.
c_str
());
}
void
ItProcessPlimits008
(
void
)
{
std
::
string
filePath
=
"/proc/plimits/"
;
std
::
vector
<
std
::
string
>
fileName
;
fileName
.
push_back
(
"plimits.procs"
);
fileName
.
push_back
(
"plimits.limiters"
);
fileName
.
push_back
(
"pids.max"
);
fileName
.
push_back
(
"sched.period"
);
fileName
.
push_back
(
"sched.quota"
);
fileName
.
push_back
(
"sched.stat"
);
fileName
.
push_back
(
"memory.failcnt"
);
fileName
.
push_back
(
"memory.limit"
);
fileName
.
push_back
(
"memory.peak"
);
fileName
.
push_back
(
"memory.usage"
);
fileName
.
push_back
(
"memory.stat"
);
for
(
auto
iter
=
fileName
.
begin
();
iter
!=
fileName
.
end
();
++
iter
)
{
std
::
string
fileFullPath
=
filePath
+
*
iter
;
int
ret
=
IsFilePropertyR1
(
fileFullPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_001.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsDevices001
(
void
)
{
int
fd
;
int
ret
;
mode_t
mode
;
char
writeBuf
[
8
];
std
::
string
test_dev
=
"/dev/hi_mipi"
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
procsTestPath
=
"/proc/plimits/test/plimits.procs"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
(
void
)
memset_s
(
writeBuf
,
sizeof
(
writeBuf
),
0
,
sizeof
(
writeBuf
));
ret
=
sprintf_s
(
writeBuf
,
sizeof
(
writeBuf
),
"%d"
,
getpid
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
WriteFile
(
procsTestPath
.
c_str
(),
writeBuf
);
ASSERT_NE
(
ret
,
0
);
fd
=
open
(
test_dev
.
c_str
(),
O_RDWR
|
O_CREAT
);
ASSERT_NE
(
fd
,
-
1
);
(
void
)
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_002.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsDevices002
(
void
)
{
int
fd
;
int
ret
;
mode_t
mode
;
std
::
string
test_dev
=
"/dev/hi_mipi"
;
std
::
string
device_a
=
"a * rwm"
;
std
::
string
device_a_r
=
"a * r"
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
devicesDenyPath
=
"/proc/plimits/test/devices.deny"
;
std
::
string
devicesAllowPath
=
"/proc/plimits/test/devices.allow"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
devicesDenyPath
.
c_str
(),
device_a
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
WriteFile
(
devicesAllowPath
.
c_str
(),
device_a_r
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
fd
=
open
(
test_dev
.
c_str
(),
O_RDWR
|
O_CREAT
);
ASSERT_NE
(
fd
,
-
1
);
(
void
)
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_003.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsDevices003
(
void
)
{
int
fd
;
int
ret
;
mode_t
mode
;
std
::
string
test_dev
=
"/dev/hi_mipi"
;
std
::
string
device_a
=
"a * rwm"
;
std
::
string
device_a_w
=
"a * w"
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
devicesDenyPath
=
"/proc/plimits/test/devices.deny"
;
std
::
string
devicesAllowPath
=
"/proc/plimits/test/devices.allow"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
devicesDenyPath
.
c_str
(),
device_a
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
WriteFile
(
devicesAllowPath
.
c_str
(),
device_a_w
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
fd
=
open
(
test_dev
.
c_str
(),
O_RDWR
|
O_CREAT
);
ASSERT_NE
(
fd
,
-
1
);
(
void
)
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_004.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsDevices004
(
void
)
{
int
fd
;
int
ret
;
mode_t
mode
;
std
::
string
test_dev
=
"/dev/hi_mipi"
;
std
::
string
device_a
=
"a * rwm"
;
std
::
string
device_a_m
=
"a * m"
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
devicesDenyPath
=
"/proc/plimits/test/devices.deny"
;
std
::
string
devicesAllowPath
=
"/proc/plimits/test/devices.allow"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
devicesDenyPath
.
c_str
(),
device_a
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
WriteFile
(
devicesAllowPath
.
c_str
(),
device_a_m
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
fd
=
open
(
test_dev
.
c_str
(),
O_CREAT
);
ASSERT_NE
(
fd
,
-
1
);
(
void
)
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_005.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsDevices005
(
void
)
{
int
fd
;
int
ret
;
mode_t
mode
;
std
::
string
test_dev
=
"/dev/mem"
;
std
::
string
device_a
=
"a * rwm"
;
std
::
string
device_c
=
"c * rwm"
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
devicesDenyPath
=
"/proc/plimits/test/devices.deny"
;
std
::
string
devicesAllowPath
=
"/proc/plimits/test/devices.allow"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
devicesDenyPath
.
c_str
(),
device_a
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
WriteFile
(
devicesAllowPath
.
c_str
(),
device_c
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
fd
=
open
(
test_dev
.
c_str
(),
O_RDWR
|
O_CREAT
);
ASSERT_NE
(
fd
,
-
1
);
(
void
)
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_006.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsDevices006
(
void
)
{
int
fd
;
int
ret
;
mode_t
mode
;
std
::
string
test_dev
=
"/dev/mem"
;
std
::
string
device_a
=
"a * rwm"
;
std
::
string
device_c_r
=
"c * r"
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
devicesDenyPath
=
"/proc/plimits/test/devices.deny"
;
std
::
string
devicesAllowPath
=
"/proc/plimits/test/devices.allow"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
devicesDenyPath
.
c_str
(),
device_a
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
WriteFile
(
devicesAllowPath
.
c_str
(),
device_c_r
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
fd
=
open
(
test_dev
.
c_str
(),
O_RDONLY
);
ASSERT_NE
(
fd
,
-
1
);
(
void
)
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_007.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsDevices007
(
void
)
{
int
fd
;
int
ret
;
mode_t
mode
;
std
::
string
test_dev
=
"/dev/mem"
;
std
::
string
device_a
=
"a * rwm"
;
std
::
string
device_c_w
=
"c * w"
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
devicesDenyPath
=
"/proc/plimits/test/devices.deny"
;
std
::
string
devicesAllowPath
=
"/proc/plimits/test/devices.allow"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
devicesDenyPath
.
c_str
(),
device_a
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
WriteFile
(
devicesAllowPath
.
c_str
(),
device_c_w
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
fd
=
open
(
test_dev
.
c_str
(),
O_WRONLY
);
ASSERT_NE
(
fd
,
-
1
);
(
void
)
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_008.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsDevices008
(
void
)
{
int
fd
;
int
ret
;
mode_t
mode
;
std
::
string
test_dev
=
"/dev/mem"
;
std
::
string
device_a
=
"a * rwm"
;
std
::
string
device_c_m
=
"c * rm"
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
devicesDenyPath
=
"/proc/plimits/test/devices.deny"
;
std
::
string
devicesAllowPath
=
"/proc/plimits/test/devices.allow"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
devicesDenyPath
.
c_str
(),
device_a
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
WriteFile
(
devicesAllowPath
.
c_str
(),
device_c_m
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
fd
=
open
(
test_dev
.
c_str
(),
O_CREAT
,
O_RDONLY
);
ASSERT_NE
(
fd
,
-
1
);
(
void
)
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_devices_009.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsDevices009
(
void
)
{
int
fd
;
int
ret
;
mode_t
mode
;
std
::
string
test_dev
=
"/dev/hi_mipi"
;
std
::
string
device_a
=
"a"
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
devicesDenyPath
=
"/proc/plimits/test/devices.deny"
;
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
devicesDenyPath
.
c_str
(),
device_a
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
fd
=
open
(
test_dev
.
c_str
(),
O_RDONLY
|
O_CREAT
);
ASSERT_EQ
(
fd
,
-
1
);
(
void
)
close
(
fd
);
fd
=
open
(
test_dev
.
c_str
(),
O_WRONLY
|
O_CREAT
);
ASSERT_EQ
(
fd
,
-
1
);
(
void
)
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_002.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsIpc002
(
void
)
{
mode_t
mode
;
int
ret
;
int
fd
;
std
::
string
plimitsRootPath
=
"/proc/plimits/"
;
std
::
vector
<
std
::
string
>
ipcConfFileName
;
ipcConfFileName
.
push_back
(
"ipc.mq_limit"
);
ipcConfFileName
.
push_back
(
"ipc.shm_limit"
);
ipcConfFileName
.
push_back
(
"ipc.stat"
);
for
(
auto
iter
=
ipcConfFileName
.
begin
();
iter
!=
ipcConfFileName
.
end
();
++
iter
)
{
std
::
string
fullPath
=
plimitsRootPath
+
*
iter
;
fd
=
access
(
fullPath
.
c_str
(),
W_OK
|
X_OK
);
ASSERT_EQ
(
fd
,
-
1
);
fd
=
access
(
fullPath
.
c_str
(),
F_OK
|
R_OK
);
ASSERT_EQ
(
fd
,
0
);
}
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_003.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsIpc003
(
void
)
{
mode_t
mode
;
int
ret
;
std
::
string
plimitsPath
=
"/proc/plimits/test"
;
std
::
string
configFileMqCount
=
"/proc/plimits/test/ipc.mq_limit"
;
std
::
string
configFileShmSize
=
"/proc/plimits/test/ipc.shm_limit"
;
std
::
string
configFileStat
=
"/proc/plimits/test/ipc.stat"
;
ret
=
mkdir
(
plimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
int
fd
=
access
(
configFileMqCount
.
c_str
(),
F_OK
|
W_OK
|
R_OK
);
ASSERT_EQ
(
fd
,
0
);
fd
=
access
(
configFileShmSize
.
c_str
(),
F_OK
|
W_OK
|
R_OK
);
ASSERT_EQ
(
fd
,
0
);
fd
=
access
(
configFileStat
.
c_str
(),
F_OK
|
R_OK
);
ASSERT_EQ
(
fd
,
0
);
fd
=
access
(
configFileStat
.
c_str
(),
W_OK
|
X_OK
);
ASSERT_EQ
(
fd
,
-
1
);
ret
=
rmdir
(
plimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_004.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsIpc004
(
void
)
{
mode_t
mode
;
mode_t
chmodMode
=
0777
;
int
ret
;
int
fd
;
std
::
string
rootplimitsPath
=
"/proc/plimits"
;
std
::
string
subPlimitsPath
=
"/proc/plimits/test"
;
std
::
vector
<
std
::
string
>
ipcConfFileName
;
ipcConfFileName
.
push_back
(
"ipc.mq_limit"
);
ipcConfFileName
.
push_back
(
"ipc.shm_limit"
);
ipcConfFileName
.
push_back
(
"ipc.stat"
);
ret
=
mkdir
(
subPlimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
for
(
auto
iter
=
ipcConfFileName
.
begin
();
iter
!=
ipcConfFileName
.
end
();
++
iter
)
{
std
::
string
fullPath
=
rootplimitsPath
+
"/"
+
*
iter
;
ret
=
chmod
(
fullPath
.
c_str
(),
mode
);
ASSERT_EQ
(
ret
,
-
1
);
}
for
(
auto
iter
=
ipcConfFileName
.
begin
();
iter
!=
ipcConfFileName
.
end
();
++
iter
)
{
std
::
string
fullPath
=
subPlimitsPath
+
"/"
+
*
iter
;
ret
=
chmod
(
fullPath
.
c_str
(),
mode
);
ASSERT_EQ
(
ret
,
-
1
);
}
ret
=
rmdir
(
subPlimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_005.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <mqueue.h>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
static
const
int
g_buffSize
=
512
;
static
const
int
g_arryLen
=
4
;
static
const
int
MQ_MAX_PER_PROCESS_COUNT
=
255
;
static
const
int
MQUEUE_STANDARD_NAME_LENGTH
=
50
;
void
ItProcessPlimitsIpc005
(
void
)
{
INT32
ret
;
mode_t
mode
;
char
buf
[
g_buffSize
]
=
{
0
};
CHAR
mqname
[
MQUEUE_STANDARD_NAME_LENGTH
]
=
""
;
mqd_t
mqueue
[
MQ_MAX_PER_PROCESS_COUNT
];
struct
mq_attr
attr
=
{
0
};
int
index
=
0
;
attr
.
mq_msgsize
=
MQUEUE_STANDARD_NAME_LENGTH
;
attr
.
mq_maxmsg
=
1
;
std
::
string
plimitsPath
=
"/proc/plimits/test"
;
ret
=
mkdir
(
plimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
ReadFile
(
"/proc/plimits/test/ipc.mq_limit"
,
buf
);
ASSERT_STREQ
(
buf
,
"1024
\n
"
);
for
(
index
=
0
;
index
<
MQ_MAX_PER_PROCESS_COUNT
;
++
index
)
{
ret
=
snprintf_s
(
mqname
,
sizeof
(
mqname
),
MQUEUE_STANDARD_NAME_LENGTH
,
"/mq_005_%d_%d"
,
index
,
LosCurTaskIDGet
());
ASSERT_NE
(
ret
,
-
1
);
mqueue
[
index
]
=
mq_open
(
mqname
,
O_CREAT
|
O_RDWR
,
S_IRUSR
|
S_IWUSR
,
&
attr
);
ASSERT_NE
(
mqueue
[
index
],
(
mqd_t
)
-
1
);
}
for
(
int
k
=
0
;
k
<
MQ_MAX_PER_PROCESS_COUNT
;
++
k
)
{
ret
=
mq_close
(
mqueue
[
k
]);
ASSERT_NE
(
ret
,
-
1
);
ret
=
snprintf_s
(
mqname
,
sizeof
(
mqname
),
MQUEUE_STANDARD_NAME_LENGTH
,
"/mq_005_%d_%d"
,
k
,
LosCurTaskIDGet
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
mq_unlink
(
mqname
);
ASSERT_EQ
(
ret
,
0
);
}
ret
=
rmdir
(
plimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_006.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <mqueue.h>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
static
const
int
MQUEUE_STANDARD_NAME_LENGTH
=
50
;
static
const
int
g_buffSize
=
512
;
static
const
int
g_arryLen
=
4
;
static
const
int
g_readLen
=
254
;
static
const
int
MQ_MAX_LIMIT_COUNT
=
10
;
static
int
FreeResource
(
mqd_t
*
mqueue
,
int
index
,
char
*
mqname
)
{
int
ret
=
-
1
;
for
(
int
k
=
0
;
k
<
index
;
++
k
)
{
if
(
snprintf_s
(
mqname
,
MQUEUE_STANDARD_NAME_LENGTH
,
MQUEUE_STANDARD_NAME_LENGTH
,
"/mq_006_%d_%d"
,
k
,
LosCurTaskIDGet
())
<
0
)
{
return
-
1
;
}
ret
=
mq_close
(
mqueue
[
k
]);
if
(
ret
!=
0
)
{
return
-
2
;
/* 2: errno */
}
ret
=
mq_unlink
(
mqname
);
if
(
ret
!=
0
)
{
return
-
3
;
/* 3: errno */
}
(
void
)
memset_s
(
mqname
,
MQUEUE_STANDARD_NAME_LENGTH
,
0
,
MQUEUE_STANDARD_NAME_LENGTH
);
}
return
ret
;
}
// plimits_ipc_07, plimits_ipc_14, plimits_ipc_17
void
ItProcessPlimitsIpc006
(
void
)
{
INT32
ret
;
mode_t
mode
;
char
buf
[
g_buffSize
]
=
{
0
};
char
*
array
[
g_arryLen
]
=
{
nullptr
};
int
mqSuccessCount
=
-
1
,
mqFailedCount
=
-
1
;
CHAR
mqname
[
MQUEUE_STANDARD_NAME_LENGTH
]
=
""
;
mqd_t
mqueue
[
g_readLen
];
std
::
string
subPlimitsPath
=
"/proc/plimits/test"
;
std
::
string
configFileMqCount
=
"/proc/plimits/test/ipc.mq_limit"
;
std
::
string
limitMqCount
=
"10"
;
struct
mq_attr
attr
=
{
0
};
attr
.
mq_msgsize
=
MQUEUE_STANDARD_NAME_LENGTH
;
attr
.
mq_maxmsg
=
1
;
int
index
=
0
;
ret
=
mkdir
(
subPlimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
configFileMqCount
.
c_str
(),
limitMqCount
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
for
(
index
=
0
;
index
<
MQ_MAX_LIMIT_COUNT
;
++
index
)
{
ret
=
snprintf_s
(
mqname
,
sizeof
(
mqname
),
MQUEUE_STANDARD_NAME_LENGTH
,
"/mq_006_%d_%d"
,
index
,
LosCurTaskIDGet
());
ASSERT_NE
(
ret
,
-
1
);
mqueue
[
index
]
=
mq_open
(
mqname
,
O_CREAT
|
O_RDWR
,
S_IRUSR
|
S_IWUSR
,
&
attr
);
ASSERT_NE
(
mqueue
[
index
],
(
mqd_t
)
-
1
);
(
void
)
memset_s
(
mqname
,
sizeof
(
mqname
),
0
,
sizeof
(
mqname
));
}
ret
=
snprintf_s
(
mqname
,
sizeof
(
mqname
),
MQUEUE_STANDARD_NAME_LENGTH
,
"/mq_006_%d_%d"
,
index
,
LosCurTaskIDGet
());
ASSERT_NE
(
ret
,
-
1
);
mqueue
[
index
]
=
mq_open
(
mqname
,
O_CREAT
|
O_RDWR
,
S_IRUSR
|
S_IWUSR
,
&
attr
);
ASSERT_EQ
(
mqueue
[
index
],
(
mqd_t
)
-
1
);
(
void
)
memset_s
(
mqname
,
sizeof
(
mqname
),
0
,
sizeof
(
mqname
));
ret
=
ReadFile
(
"/proc/plimits/test/ipc.stat"
,
buf
);
printf
(
"/proc/plimits/test/ipc.stat: %s
\n
"
,
buf
);
GetLine
(
buf
,
g_arryLen
,
g_readLen
,
array
);
mqSuccessCount
=
atoi
(
array
[
0
]
+
strlen
(
"mq count: "
));
mqFailedCount
=
atoi
((
array
[
1
]
+
strlen
(
"mq failed count: "
)));
ASSERT_EQ
(
mqSuccessCount
,
MQ_MAX_LIMIT_COUNT
);
ASSERT_EQ
(
mqFailedCount
,
1
);
ret
=
FreeResource
(
mqueue
,
index
,
mqname
);
ASSERT_EQ
(
ret
,
0
);
ret
=
rmdir
(
subPlimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_007.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsIpc007
(
void
)
{
mode_t
mode
;
int
ret
;
std
::
string
plimitsPath
=
"/proc/plimits/test"
;
std
::
string
configFileMqCount
=
"/proc/plimits/test/ipc.mq_limit"
;
std
::
string
mqLimitCount
=
"0123"
;
ret
=
mkdir
(
plimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
configFileMqCount
.
c_str
(),
mqLimitCount
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
rmdir
(
plimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_008.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsIpc008
(
void
)
{
mode_t
mode
;
int
ret
;
std
::
string
plimitsPath
=
"/proc/plimits/test"
;
std
::
string
configFileMqCount
=
"/proc/plimits/test/ipc.mq_limit"
;
std
::
string
mqLimitCount_0
=
"111*"
;
std
::
string
mqLimitCount_1
=
"123abc"
;
std
::
string
mqLimitCount_2
=
"
\"
123 456
\"
"
;
std
::
string
mqLimitCount_3
=
"
\123
"
;
std
::
string
mqLimitCount_4
=
"10000000000000000000000000000000001"
;
std
::
string
mqLimitCount_5
=
"
\1\2\3
"
;
ret
=
mkdir
(
plimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
configFileMqCount
.
c_str
(),
mqLimitCount_0
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileMqCount
.
c_str
(),
mqLimitCount_1
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileMqCount
.
c_str
(),
mqLimitCount_2
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileMqCount
.
c_str
(),
mqLimitCount_3
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileMqCount
.
c_str
(),
mqLimitCount_4
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileMqCount
.
c_str
(),
mqLimitCount_5
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
rmdir
(
plimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_009.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <sys/shm.h>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
static
const
int
g_buffSize
=
512
;
static
const
int
g_arryLen
=
4
;
static
const
int
g_readLen
=
254
;
void
ItProcessPlimitsIpc009
(
void
)
{
mode_t
mode
;
char
buf
[
g_buffSize
]
=
{
0
};
int
ret
;
int
shmid
;
void
*
shared
=
nullptr
;
mode_t
acessMode
=
0666
;
std
::
string
subPlimitsPath
=
"/proc/plimits/test"
;
ret
=
mkdir
(
subPlimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
ReadFile
(
"/proc/plimits/test/ipc.shm_limit"
,
buf
);
ASSERT_STREQ
(
buf
,
"104857600
\n
"
);
shmid
=
shmget
(
IPC_PRIVATE
,
PAGE_SIZE
,
acessMode
|
IPC_CREAT
);
ASSERT_NE
(
shmid
,
-
1
);
shared
=
shmat
(
shmid
,
nullptr
,
0
);
ASSERT_NE
(
shared
,
(
void
*
)
-
1
);
ret
=
shmdt
(
shared
);
ASSERT_NE
(
ret
,
-
1
);
ret
=
shmctl
(
shmid
,
IPC_RMID
,
nullptr
);
ASSERT_NE
(
ret
,
-
1
);
ret
=
rmdir
(
subPlimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_010.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <sys/shm.h>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
static
const
int
g_buffSize
=
512
;
static
const
int
g_arryLen
=
4
;
static
const
int
g_readLen
=
254
;
void
ItProcessPlimitsIpc010
(
void
)
{
mode_t
mode
;
mode_t
shmAcess
=
0666
;
char
buf
[
g_buffSize
]
=
{
0
};
char
*
array
[
g_arryLen
]
=
{
nullptr
};
int
mqSuccessCount
;
int
mqFailedCount
;
int
shmSuccessSize
;
int
shmFailedCount
;
int
shmid
=
-
1
;
int
shmid_1
=
-
1
;
int
index
=
0
;
int
shmCkeckSize
=
PAGE_SIZE
*
9
;
void
*
shared
=
nullptr
;
size_t
shmSize
=
PAGE_SIZE
*
9
;
std
::
string
subPlimitsPath
=
"/proc/plimits/test"
;
std
::
string
configFileShmSize
=
"/proc/plimits/test/ipc.shm_limit"
;
char
shmemLimit
[
6
]
=
"40960"
;
int
ret
=
mkdir
(
subPlimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
configFileShmSize
.
c_str
(),
shmemLimit
);
ASSERT_NE
(
ret
,
-
1
);
shmid
=
shmget
(
IPC_PRIVATE
,
shmSize
,
shmAcess
|
IPC_CREAT
);
ASSERT_NE
(
shmid
,
-
1
);
shmid_1
=
shmget
(
IPC_PRIVATE
,
2
*
PAGE_SIZE
,
shmAcess
|
IPC_CREAT
);
/* 2: PAGE num */
ASSERT_EQ
(
shmid_1
,
-
1
);
ret
=
ReadFile
(
"/proc/plimits/test/ipc.stat"
,
buf
);
GetLine
(
buf
,
g_arryLen
,
g_readLen
,
array
);
mqSuccessCount
=
atoi
(
array
[
index
++
]
+
strlen
(
"mq count: "
));
mqFailedCount
=
atoi
(
array
[
index
++
]
+
strlen
(
"mq failed count: "
));
shmSuccessSize
=
atoi
(
array
[
index
++
]
+
strlen
(
"shm size: "
));
shmFailedCount
=
atoi
(
array
[
index
++
]
+
strlen
(
"shm failed count: "
));
ASSERT_EQ
(
shmSuccessSize
,
shmCkeckSize
);
ASSERT_EQ
(
shmFailedCount
,
1
);
shared
=
shmat
(
shmid
,
nullptr
,
0
);
ASSERT_NE
(
shared
,
(
void
*
)
-
1
);
ret
=
shmdt
(
shared
);
ASSERT_NE
(
ret
,
-
1
);
ret
=
shmctl
(
shmid
,
IPC_RMID
,
nullptr
);
ASSERT_NE
(
ret
,
-
1
);
shmctl
(
shmid_1
,
IPC_RMID
,
nullptr
);
shmctl
(
shmid
,
IPC_RMID
,
nullptr
);
ret
=
rmdir
(
subPlimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_011.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsIpc011
(
void
)
{
mode_t
mode
;
int
ret
;
char
buf
[
512
]
=
{
0
};
std
::
string
plimitsPath
=
"/proc/plimits/test"
;
std
::
string
configFileShmSize
=
"/proc/plimits/test/ipc.shm_limit"
;
std
::
string
shmLimitSize
=
"0123"
;
ret
=
mkdir
(
plimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
configFileShmSize
.
c_str
(),
shmLimitSize
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
rmdir
(
plimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_012.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
void
ItProcessPlimitsIpc012
(
void
)
{
mode_t
mode
;
int
ret
;
std
::
string
plimitsPath
=
"/proc/plimits/test"
;
std
::
string
configFileShmSize
=
"/proc/plimits/test/ipc.shm_limit"
;
std
::
string
shmLimitSize_0
=
"111*"
;
std
::
string
shmLimitSize_1
=
"123abc"
;
std
::
string
shmLimitSize_2
=
"
\"
123 456
\"
"
;
std
::
string
shmLimitSize_3
=
"
\123
"
;
std
::
string
shmLimitSize_4
=
"10000000000000000000000000000000001"
;
std
::
string
shmLimitSize_5
=
"
\1\2\3
"
;
ret
=
mkdir
(
plimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
configFileShmSize
.
c_str
(),
shmLimitSize_0
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileShmSize
.
c_str
(),
shmLimitSize_1
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileShmSize
.
c_str
(),
shmLimitSize_2
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileShmSize
.
c_str
(),
shmLimitSize_3
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileShmSize
.
c_str
(),
shmLimitSize_4
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
WriteFile
(
configFileShmSize
.
c_str
(),
shmLimitSize_5
.
c_str
());
ASSERT_EQ
(
ret
,
-
1
);
ret
=
rmdir
(
plimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_ipc_013.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <mqueue.h>
#include <gtest/gtest.h>
#include "It_process_plimits.h"
static
const
int
MQUEUE_STANDARD_NAME_LENGTH
=
50
;
static
const
int
MQUEUE_STANDARD_NAME_LENGTH_MAX
=
102500
;
static
const
int
g_buff
=
512
;
static
const
int
MQ_MAX_LIMIT_COUNT
=
10
;
static
int
FreeResource
(
mqd_t
*
mqueue
,
int
index
,
char
*
mqname
)
{
int
ret
=
-
1
;
for
(
int
k
=
0
;
k
<
index
;
++
k
)
{
ret
=
snprintf_s
(
mqname
,
MQUEUE_STANDARD_NAME_LENGTH
,
MQUEUE_STANDARD_NAME_LENGTH
,
"/mq_006_%d_%d"
,
k
,
LosCurTaskIDGet
());
if
(
ret
<
0
)
{
return
-
1
;
/* 1: errno */
}
ret
=
mq_close
(
mqueue
[
k
]);
if
(
ret
<
0
)
{
return
-
2
;
/* 2: errno */
}
ret
=
mq_unlink
(
mqname
);
if
(
ret
<
0
)
{
return
-
3
;
/* 3: errno */
}
(
void
)
memset_s
(
mqname
,
MQUEUE_STANDARD_NAME_LENGTH
,
0
,
MQUEUE_STANDARD_NAME_LENGTH
);
}
return
ret
;
}
void
ItProcessPlimitsIpc013
(
void
)
{
INT32
ret
;
mode_t
mode
;
CHAR
mqname
[
MQUEUE_STANDARD_NAME_LENGTH
]
=
""
;
mqd_t
mqueue
[
g_buff
];
std
::
string
subPlimitsPath
=
"/proc/plimits/test"
;
std
::
string
configFileMqCount
=
"/proc/plimits/test/ipc.mq_limit"
;
std
::
string
limitMqCount
=
"11"
;
struct
mq_attr
attr
=
{
0
};
attr
.
mq_msgsize
=
MQUEUE_STANDARD_NAME_LENGTH
;
attr
.
mq_maxmsg
=
1
;
struct
mq_attr
attr_err
=
{
0
};
attr_err
.
mq_msgsize
=
MQUEUE_STANDARD_NAME_LENGTH_MAX
;
attr_err
.
mq_maxmsg
=
1
;
int
index
=
0
;
ret
=
mkdir
(
subPlimitsPath
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
ret
=
WriteFile
(
configFileMqCount
.
c_str
(),
limitMqCount
.
c_str
());
ASSERT_NE
(
ret
,
-
1
);
for
(
index
=
0
;
index
<
MQ_MAX_LIMIT_COUNT
;
++
index
)
{
ret
=
snprintf_s
(
mqname
,
sizeof
(
mqname
),
MQUEUE_STANDARD_NAME_LENGTH
,
"/mq_006_%d_%d"
,
index
,
LosCurTaskIDGet
());
ASSERT_NE
(
ret
,
-
1
);
mqueue
[
index
]
=
mq_open
(
mqname
,
O_CREAT
|
O_RDWR
,
S_IRUSR
|
S_IWUSR
,
&
attr
);
ASSERT_NE
(
mqueue
[
index
],
(
mqd_t
)
-
1
);
(
void
)
memset_s
(
mqname
,
sizeof
(
mqname
),
0
,
sizeof
(
mqname
));
}
ret
=
snprintf_s
(
mqname
,
sizeof
(
mqname
),
MQUEUE_STANDARD_NAME_LENGTH
,
"/mq_006_%d_%d"
,
index
,
LosCurTaskIDGet
());
ASSERT_NE
(
ret
,
-
1
);
mqueue
[
index
]
=
mq_open
(
mqname
,
O_CREAT
|
O_RDWR
,
S_IRUSR
|
S_IWUSR
,
&
attr_err
);
ASSERT_EQ
(
mqueue
[
index
],
(
mqd_t
)
-
1
);
(
void
)
memset_s
(
mqname
,
sizeof
(
mqname
),
0
,
sizeof
(
mqname
));
ret
=
FreeResource
(
mqueue
,
index
,
mqname
);
ASSERT_EQ
(
ret
,
0
);
ret
=
rmdir
(
subPlimitsPath
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_001.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 "It_process_plimits.h"
static
char
*
testStr1
=
nullptr
;
static
int
limitWrite
(
const
char
*
filepath
,
const
char
*
buf
)
{
int
fd
=
open
(
filepath
,
O_WRONLY
);
size_t
ret
=
write
(
fd
,
buf
,
strlen
(
buf
));
close
(
fd
);
return
ret
;
}
static
int
CloneOne
(
void
*
arg
)
{
const
unsigned
int
testSize
=
11534336
;
testStr1
=
(
char
*
)
malloc
(
testSize
);
EXPECT_STRNE
(
testStr1
,
NULL
);
(
void
)
memset_s
(
testStr1
,
testSize
,
1
,
testSize
);
return
0
;
}
void
ItProcessPlimitsMemory001
(
void
)
{
mode_t
mode
=
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
|
S_IXOTH
;
int
ret
,
pid
,
status
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
limitTestPath
=
"/proc/plimits/test/memory.limit"
;
std
::
string
usageTestPath
=
"/proc/plimits/test/memory.stat"
;
const
char
*
buffer
=
"10485760"
;
char
buf
[
512
];
int
twoM
=
2
*
1024
*
1024
;
char
*
stack
=
(
char
*
)
mmap
(
NULL
,
twoM
,
PROT_READ
|
PROT_WRITE
,
MAP_PRIVATE
|
MAP_ANONYMOUS
|
MAP_STACK
,
-
1
,
0
);
EXPECT_STRNE
(
stack
,
NULL
);
ret
=
access
(
path
.
c_str
(),
0
);
EXPECT_EQ
(
ret
,
-
1
);
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
EXPECT_EQ
(
ret
,
0
);
ret
=
limitWrite
(
limitTestPath
.
c_str
(),
buffer
);
EXPECT_NE
(
ret
,
-
1
);
pid
=
clone
(
CloneOne
,
stack
,
0
,
NULL
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
ASSERT_EQ
(
ret
,
pid
);
ret
=
WIFEXITED
(
status
);
ASSERT_EQ
(
ret
,
0
);
(
void
)
memset_s
(
buf
,
sizeof
(
buf
),
0
,
sizeof
(
buf
));
ret
=
ReadFile
(
usageTestPath
.
c_str
(),
buf
);
EXPECT_NE
(
ret
,
-
1
);
printf
(
"%s: %s
\n
"
,
usageTestPath
.
c_str
(),
buf
);
ret
=
rmdir
(
path
.
c_str
());
EXPECT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_memory_002.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 "It_process_plimits.h"
static
char
*
testStr1
=
nullptr
;
static
int
limitWrite
(
const
char
*
filepath
,
const
char
*
buf
)
{
int
fd
=
open
(
filepath
,
O_WRONLY
);
size_t
ret
=
write
(
fd
,
buf
,
strlen
(
buf
));
close
(
fd
);
return
ret
;
}
static
int
CloneOne
(
void
*
arg
)
{
const
unsigned
int
testSize
=
1153
;
testStr1
=
(
char
*
)
malloc
(
testSize
);
EXPECT_STRNE
(
testStr1
,
NULL
);
(
void
)
memset_s
(
testStr1
,
testSize
,
1
,
testSize
);
free
(
testStr1
);
testStr1
=
nullptr
;
return
0
;
}
void
ItProcessPlimitsMemory002
(
void
)
{
mode_t
mode
=
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
|
S_IXOTH
;
int
ret
,
pid
,
status
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
limitTestPath
=
"/proc/plimits/test/memory.limit"
;
std
::
string
usageTestPath
=
"/proc/plimits/test/memory.stat"
;
char
buf
[
512
];
const
char
*
buffer
=
"10485760"
;
int
twoM
=
2
*
1024
*
1024
;
char
*
stack
=
(
char
*
)
mmap
(
NULL
,
twoM
,
PROT_READ
|
PROT_WRITE
,
MAP_PRIVATE
|
MAP_ANONYMOUS
|
MAP_STACK
,
-
1
,
0
);
EXPECT_STRNE
(
stack
,
NULL
);
ret
=
access
(
path
.
c_str
(),
0
);
EXPECT_EQ
(
ret
,
-
1
);
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
EXPECT_EQ
(
ret
,
0
);
ret
=
limitWrite
(
limitTestPath
.
c_str
(),
buffer
);
EXPECT_NE
(
ret
,
-
1
);
pid
=
clone
(
CloneOne
,
stack
,
0
,
NULL
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
ASSERT_EQ
(
ret
,
pid
);
ret
=
WIFEXITED
(
status
);
ASSERT_NE
(
ret
,
0
);
int
exitCode
=
WEXITSTATUS
(
status
);
ASSERT_EQ
(
exitCode
,
0
);
(
void
)
memset_s
(
buf
,
sizeof
(
buf
),
0
,
sizeof
(
buf
));
ret
=
ReadFile
(
usageTestPath
.
c_str
(),
buf
);
EXPECT_NE
(
ret
,
-
1
);
printf
(
"%s: %s
\n
"
,
usageTestPath
.
c_str
(),
buf
);
ret
=
rmdir
(
path
.
c_str
());
EXPECT_EQ
(
ret
,
0
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_001.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <cstdlib>
#include <fcntl.h>
#include <unistd.h>
#include <fcntl.h>
#include <cstring>
#include <sys/wait.h>
#include "It_process_plimits.h"
static
int
g_pidGroup
[
10
]
=
{
0
};
static
int
g_index
=
0
;
static
int
g_sleepTime
=
5
;
static
int
PidWrite
(
const
char
*
filepath
,
char
*
buf
)
{
int
fd
=
open
(
filepath
,
O_WRONLY
);
if
(
fd
<=
0
)
{
return
2
;
/* 2: errno */
}
size_t
ret
=
write
(
fd
,
buf
,
strlen
(
buf
));
if
(
ret
<
0
)
{
printf
(
"filepath: %s buf: %s, errno=%d
\n
"
,
filepath
,
buf
,
errno
);
}
close
(
fd
);
return
ret
;
}
static
int
PidFork
(
const
char
*
filepath
,
int
index
)
{
pid_t
fpid
=
fork
();
if
(
fpid
==
0
)
{
// children proc
sleep
(
g_sleepTime
);
exit
(
0
);
}
else
if
(
fpid
>
0
)
{
g_pidGroup
[
index
]
=
fpid
;
return
0
;
}
return
-
1
;
}
void
ItProcessPlimitsPid001
(
void
)
{
mode_t
mode
=
0
;
int
status
;
const
char
*
pidMaxPath
=
"/proc/plimits/test/pids.max"
;
const
char
*
procsPath
=
"/proc/plimits/test/plimits.procs"
;
std
::
string
path
=
"/proc/plimits/test"
;
char
writeBuf
[
3
];
int
i
=
0
;
int
pidnum
=
5
;
int
mainpid
=
getpid
();
int
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
(
void
)
memset_s
(
writeBuf
,
sizeof
(
writeBuf
),
0
,
sizeof
(
writeBuf
));
ret
=
sprintf_s
(
writeBuf
,
sizeof
(
writeBuf
),
"%d"
,
pidnum
);
ASSERT_NE
(
ret
,
-
1
);
ret
=
PidWrite
(
pidMaxPath
,
writeBuf
);
ASSERT_NE
(
ret
,
-
1
);
for
(
i
=
g_index
;
i
<
pidnum
;
i
++
)
{
ret
=
PidFork
(
procsPath
,
i
);
if
(
i
!=
(
pidnum
-
1
))
{
ASSERT_EQ
(
ret
,
0
);
}
else
{
ASSERT_EQ
(
ret
,
-
1
);
}
}
for
(
i
=
0
;
i
<
pidnum
-
1
;
++
i
)
{
pid_t
pid
=
waitpid
(
g_pidGroup
[
i
],
&
status
,
0
);
ASSERT_EQ
(
pid
,
g_pidGroup
[
i
]);
ASSERT_EQ
(
WEXITSTATUS
(
status
),
0
);
}
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_002.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <vector>
#include <cstring>
#include <sys/wait.h>
#include "It_process_plimits.h"
static
int
g_pidGroup
[
10
]
=
{
0
};
static
int
g_index
=
0
;
static
int
g_sleepTime
=
5
;
static
int
PidWrite
(
const
char
*
filepath
,
char
*
buf
)
{
int
fd
=
open
(
filepath
,
O_WRONLY
);
size_t
ret
=
write
(
fd
,
buf
,
strlen
(
buf
));
close
(
fd
);
return
ret
;
}
static
void
PidFork
(
int
index
)
{
pid_t
fpid
=
fork
();
if
(
fpid
==
0
)
{
// children proc
sleep
(
g_sleepTime
);
exit
(
0
);
}
else
if
(
fpid
>
0
)
{
g_pidGroup
[
index
]
=
fpid
;
return
;
}
}
void
ItProcessPlimitsPid002
(
void
)
{
mode_t
mode
=
0
;
int
status
;
const
char
*
pidMaxPath
=
"/proc/plimits/test/pids.max"
;
const
char
*
procsPath
=
"/proc/plimits/test/plimits.procs"
;
std
::
string
path
=
"/proc/plimits/test"
;
char
writeBuf
[
3
];
int
num
=
4
;
int
i
=
0
;
pid_t
fpid
;
int
pidnum
=
5
;
int
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
(
void
)
memset_s
(
writeBuf
,
sizeof
(
writeBuf
),
0
,
sizeof
(
writeBuf
));
ret
=
sprintf_s
(
writeBuf
,
sizeof
(
writeBuf
),
"%d"
,
pidnum
);
ASSERT_NE
(
ret
,
-
1
);
ret
=
PidWrite
(
pidMaxPath
,
writeBuf
);
ASSERT_NE
(
ret
,
-
1
);
(
void
)
memset_s
(
writeBuf
,
sizeof
(
writeBuf
),
0
,
sizeof
(
writeBuf
));
ret
=
sprintf_s
(
writeBuf
,
sizeof
(
writeBuf
),
"%d"
,
getpid
());
ASSERT_NE
(
ret
,
-
1
);
ret
=
PidWrite
(
procsPath
,
writeBuf
);
ASSERT_NE
(
ret
,
-
1
);
for
(
i
=
g_index
;
i
<
num
;
++
i
)
{
PidFork
(
i
);
}
g_index
=
i
;
fpid
=
fork
();
if
(
fpid
==
0
)
{
exit
(
0
);
}
else
if
(
fpid
>
0
)
{
waitpid
(
fpid
,
&
status
,
0
);
}
for
(
i
=
0
;
i
<
g_index
;
++
i
)
{
waitpid
(
g_pidGroup
[
i
],
&
status
,
0
);
ASSERT_EQ
(
WEXITSTATUS
(
status
),
0
);
}
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_003.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <vector>
#include <cstring>
#include <sys/wait.h>
#include "It_process_plimits.h"
static
int
PidWrite
(
const
char
*
filepath
,
char
*
buf
)
{
int
fd
=
open
(
filepath
,
O_WRONLY
);
size_t
ret
=
write
(
fd
,
buf
,
strlen
(
buf
));
close
(
fd
);
return
ret
;
}
void
ItProcessPlimitsPid003
(
void
)
{
mode_t
mode
=
0
;
int
status
;
struct
sched_param
param
=
{
0
};
const
char
*
pidMaxPath
=
"/proc/plimits/test/pids.priority"
;
std
::
string
path
=
"/proc/plimits/test"
;
char
writeBuf
[
3
];
int
pidnum
=
15
;
/* 15: priority limit */
int
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
(
void
)
memset_s
(
writeBuf
,
sizeof
(
writeBuf
),
0
,
sizeof
(
writeBuf
));
ret
=
sprintf_s
(
writeBuf
,
sizeof
(
writeBuf
),
"%d"
,
pidnum
);
ASSERT_NE
(
ret
,
-
1
);
ret
=
PidWrite
(
pidMaxPath
,
writeBuf
);
ASSERT_NE
(
ret
,
-
1
);
int
currProcessPri
=
getpriority
(
PRIO_PROCESS
,
getpid
());
param
.
sched_priority
=
pidnum
-
1
;
ret
=
sched_setscheduler
(
getpid
(),
SCHED_RR
,
&
param
);
ASSERT_NE
(
ret
,
0
);
ret
=
setpriority
(
PRIO_PROCESS
,
getpid
(),
param
.
sched_priority
);
ASSERT_NE
(
ret
,
0
);
ret
=
sched_setparam
(
getpid
(),
&
param
);
ASSERT_NE
(
ret
,
0
);
param
.
sched_priority
=
currProcessPri
+
1
;
ret
=
sched_setscheduler
(
getpid
(),
SCHED_RR
,
&
param
);
ASSERT_EQ
(
ret
,
0
);
param
.
sched_priority
++
;
ret
=
setpriority
(
PRIO_PROCESS
,
getpid
(),
param
.
sched_priority
);
ASSERT_EQ
(
ret
,
0
);
param
.
sched_priority
++
;
ret
=
sched_setparam
(
getpid
(),
&
param
);
ASSERT_EQ
(
ret
,
0
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_004.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include "It_process_plimits.h"
void
ItProcessPlimitsPid004
(
void
)
{
mode_t
mode
=
0
;
int
ret
;
const
char
*
res
=
nullptr
;
const
size_t
BUFFER_SIZE
=
512
;
std
::
string
path
=
"/proc/plimits/test"
;
DIR
*
dirp
=
opendir
(
"/proc/plimits"
);
ASSERT_NE
(
dirp
,
nullptr
);
closedir
(
dirp
);
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
char
buff
[
BUFFER_SIZE
]
=
{
0
};
ret
=
ReadFile
(
"/proc/plimits/pids.max"
,
buff
);
res
=
strstr
(
buff
,
"64"
);
ASSERT_STRNE
(
res
,
nullptr
);
(
void
)
memset_s
(
buff
,
BUFFER_SIZE
,
0
,
BUFFER_SIZE
);
ret
=
ReadFile
(
"/proc/plimits/test/pids.max"
,
buff
);
res
=
strstr
(
buff
,
"64"
);
ASSERT_STRNE
(
res
,
nullptr
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_005.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <cstdlib>
#include <unistd.h>
#include <fcntl.h>
#include <cstring>
#include <climits>
#include <sys/types.h>
#include <gtest/gtest.h>
#include <dirent.h>
#include "It_process_plimits.h"
static
int
g_processOs
=
8
;
void
ItProcessPlimitsPid005
(
void
)
{
mode_t
mode
=
0
;
std
::
string
path
=
"/proc/plimits/test"
;
std
::
string
filepath
=
"/proc/plimits/test/plimits.procs"
;
int
pid
=
getpid
();
int
vprocessId
=
90
;
std
::
string
missPid
=
std
::
to_string
(
vprocessId
);
std
::
string
runPid
=
std
::
to_string
(
pid
);
int
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
int
fd
=
open
(
filepath
.
c_str
(),
O_WRONLY
);
ASSERT_NE
(
fd
,
-
1
);
for
(
int
i
=
1
;
i
<=
g_processOs
;
i
++
)
{
std
::
string
fWrite
=
std
::
to_string
(
i
);
ret
=
write
(
fd
,
fWrite
.
c_str
(),
(
fWrite
.
length
()));
ASSERT_EQ
(
ret
,
-
1
);
}
ret
=
write
(
fd
,
missPid
.
c_str
(),
(
missPid
.
length
()));
ASSERT_EQ
(
ret
,
-
1
);
ret
=
write
(
fd
,
path
.
c_str
(),
(
path
.
length
()));
ASSERT_EQ
(
ret
,
-
1
);
ret
=
write
(
fd
,
runPid
.
c_str
(),
(
runPid
.
length
()));
ASSERT_NE
(
ret
,
-
1
);
close
(
fd
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_pid_006.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 <unistd.h>
#include <cstdlib>
#include <fcntl.h>
#include <cstring>
#include "It_process_plimits.h"
void
ItProcessPlimitsPid006
(
void
)
{
mode_t
mode
=
0
;
int
ret
;
const
char
*
res
=
nullptr
;
const
size_t
BUFFER_SIZE
=
512
;
std
::
string
path
=
"/proc/plimits/test"
;
DIR
*
dirp
=
opendir
(
"/proc/plimits"
);
ASSERT_NE
(
dirp
,
nullptr
);
closedir
(
dirp
);
ret
=
mkdir
(
path
.
c_str
(),
S_IFDIR
|
mode
);
ASSERT_EQ
(
ret
,
0
);
char
buff
[
BUFFER_SIZE
]
=
{
0
};
ret
=
ReadFile
(
"/proc/plimits/pids.max"
,
buff
);
res
=
strstr
(
buff
,
"64"
);
ASSERT_STRNE
(
res
,
nullptr
);
(
void
)
memset_s
(
buff
,
BUFFER_SIZE
,
0
,
BUFFER_SIZE
);
ret
=
ReadFile
(
"/proc/plimits/test/pids.max"
,
buff
);
res
=
strstr
(
buff
,
"64"
);
ASSERT_STRNE
(
res
,
nullptr
);
ret
=
rmdir
(
path
.
c_str
());
ASSERT_EQ
(
ret
,
0
);
return
;
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_001.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* Copyright (c) 2020-2021 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 "It_process_plimits.h"
using
namespace
std
;
VOID
ItProcessPlimitsSched001
(
void
)
{
const
int
childAmount
=
1
;
double
errorRate
=
TestCpupInPlimit
(
childAmount
,
"testcpup101"
,
PERIOD_10_SEC_IN_US
,
QUOTA_2_SEC_IN_US
,
QUOTA_PERCENT_20
);
ASSERT_GE
(
errorRate
,
0
);
ASSERT_LE
(
errorRate
,
TOLERANCE_ERROR
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_002.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* Copyright (c) 2020-2021 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 "It_process_plimits.h"
using
namespace
std
;
VOID
ItProcessPlimitsSched002
(
void
)
{
const
int
childAmount
=
1
;
double
errorRate
=
TestCpupInPlimit
(
childAmount
,
"testcpup102"
,
PERIOD_10_SEC_IN_US
,
QUOTA_6_SEC_IN_US
,
QUOTA_PERCENT_60
);
ASSERT_GE
(
errorRate
,
0
);
ASSERT_LE
(
errorRate
,
TOLERANCE_ERROR
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_003.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 "It_process_plimits.h"
using
namespace
std
;
VOID
ItProcessPlimitsSched003
(
void
)
{
const
int
childAmount
=
1
;
double
errorRate
=
TestCpupInPlimit
(
childAmount
,
"testcpup104"
,
PERIOD_10_SEC_IN_US
,
QUOTA_10_SEC_IN_US
,
QUOTA_PERCENT_100
);
ASSERT_GE
(
errorRate
,
0
);
ASSERT_LE
(
errorRate
,
TOLERANCE_ERROR
);
}
testsuites/unittest/process/plimits/smoke/It_process_plimits_sched_004.cpp
0 → 100644
浏览文件 @
10c5e2e6
/*
* 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 "It_process_plimits.h"
using
namespace
std
;
VOID
ItProcessPlimitsSched004
(
void
)
{
const
int
childAmount
=
2
;
double
errorRate
=
TestCpupInPlimit
(
childAmount
,
"testcpup105"
,
PERIOD_10_SEC_IN_US
,
QUOTA_10_SEC_IN_US
,
QUOTA_PERCENT_100
);
ASSERT_GE
(
errorRate
,
0
);
ASSERT_LE
(
errorRate
,
TOLERANCE_ERROR
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录