Compare commits

...

46 Commits

Author SHA1 Message Date
openharmony_ci
30d6d3c088 !1244 【Pick 4.1 Release】fs_epoll竞争漏洞修复
Merge pull request !1244 from hw_llm/cherry-pick-1729040743
2024-10-16 04:01:14 +00:00
石子怡
65a8243fb1 update fs/vfs/epoll/fs_epoll.c.
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IAXDGA
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
(cherry picked commit from <gitee.com//openharmony/kernel_liteos_a/commit/02abd34ad29301fdd3ade31fe35c62033e732007>
2024-10-16 01:05:43 +00:00
openharmony_ci
4b34b96700 !1240 【Pick 4.1 Release】shm pid 入参漏洞修复
Merge pull request !1240 from hw_llm/cherry-pick-1728735200
2024-10-12 12:49:43 +00:00
hw_llm
066a984a97 Description: shm pid入参 漏洞修复
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IAWOD7
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
(cherry picked commit from <gitee.com//openharmony/kernel_liteos_a/commit/14c79fc921db176c8c7ae87a917fa50217e664ac>
2024-10-12 12:13:20 +00:00
openharmony_ci
f9ccc6e5fd !1237 【Pick 4.1 Release】hidumper 漏洞修复
Merge pull request !1237 from hw_llm/cherry-pick-1727612382
2024-09-29 14:21:40 +00:00
hw_llm
66228974c5 Description: hidumper 漏洞修复
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IAUKDF
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
(cherry picked commit from <gitee.com//openharmony/kernel_liteos_a/commit/31da79ec80e5a1517e3aff126a4b13ed37d352ee>
2024-09-29 12:19:42 +00:00
openharmony_ci
572022f542 !1234 mem 漏洞修复
Merge pull request !1234 from hw_llm/cherry-pick-1727599316
2024-09-29 11:50:43 +00:00
hw_llm
439633c93b Description: mem 漏洞修复
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IAUJWK
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
(cherry picked commit from <gitee.com//openharmony/kernel_liteos_a/commit/4bb465f9af0af618c9d4b24b82ede7dd9f12faa6>
2024-09-29 08:41:56 +00:00
openharmony_ci
020edcb1b7 !1231 【Pick 4.1 Release】liteipc 解决 释放后使用问题
Merge pull request !1231 from hw_llm/cherry-pick-1727158800
2024-09-24 08:30:39 +00:00
hw_llm
562c5d93d3 Description: liteipc 解决 释放后使用问题
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IAT99L
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
(cherry picked commit from <gitee.com//openharmony/kernel_liteos_a/commit/8b571985262dc1d5ed64bbeb08f55a11306bf174>
2024-09-24 06:20:00 +00:00
openharmony_ci
898e71eb54 !1228 【同步4.1 release分支】VM Map 添加LITEIPC保护
Merge pull request !1228 from hw_llm/cherry-pick-1727060660
2024-09-24 01:50:14 +00:00
hw_llm
07be40d1f3 Description: VM Map 添加LiteIPC 保护
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IASJLX
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
(cherry picked commit from <gitee.com//openharmony/kernel_liteos_a/commit/75af9e28d9e92398f71e2f884c53a2745e7cd097>
2024-09-23 03:04:20 +00:00
openharmony_ci
20820bd0f7 !1223 OsShellCmdTskInfoGet 内存泄露漏洞修复
Merge pull request !1223 from hw_llm/cherry-pick-1724405916
2024-08-26 12:29:32 +00:00
openharmony_ci
20cf25498f !1220 SysEpollWait 系统调用使用正确长度。
Merge pull request !1220 from hw_llm/cherry-pick-1724401985
2024-08-23 10:39:01 +00:00
hw_llm
a502da19c0 cherry pick b58c6d4 from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1221
Description: OsShellCmdTskInfoGet 内存泄露漏洞修复
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IAM34B?from=project-issue
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
2024-08-23 09:38:36 +00:00
hw_llm
dc523053cd cherry pick 5e3a8f1 from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1218
Description: syscall SysEpollWait 执行漏洞修复
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IALYB5?from=project-issue
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
2024-08-23 08:33:05 +00:00
openharmony_ci
f264fa6b13 !1214 [Pick 4.1 Release]console read 漏洞修复
Merge pull request !1214 from hw_llm/cherry-pick-1724245367
2024-08-22 08:38:58 +00:00
hw_llm
1bb7968775 cherry pick 0c53eca from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1213
cherry pick b22a7c2 from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1212
Description: console read 漏洞修复
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IALLNX?from=project-issue
Feature Or Bugfix: Feature
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
2024-08-21 13:02:47 +00:00
openharmony_ci
017822c2fd !1211 liteos_a 内核shell 漏洞修复
Merge pull request !1211 from hw_llm/cherry-pick-1724202574
2024-08-21 12:41:57 +00:00
hw_llm
fef87f5da8 cherry pick bca2645 from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1210
cherry pick 2ac53f2 from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1209
Description: shell lk 漏洞修复
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IAKVF0
Feature Or Bugfix: Feature
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
2024-08-21 01:09:34 +00:00
openharmony_ci
a0088a2e53 !1206 内核代码适配
Merge pull request !1206 from yaowenrui/OpenHarmony-4.1-Release
2024-08-19 07:45:48 +00:00
openharmony_ci
08b1ab779c !1208 【同步4.1 Release】容器编译失败问题同步
Merge pull request !1208 from hw_llm/cherry-pick-1723789557
2024-08-16 10:12:17 +00:00
hw_llm
03a2bf2c68 cherry pick d958a85 from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1202
Description: 解决容器编译报错问题
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/I9TEYD
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
2024-08-16 06:25:58 +00:00
yaowenrui
589820d05a 5.10内核仓代码适配
Signed-off-by: yaowenrui <yaowenrui2@huawei.com>
2024-08-15 14:21:37 +08:00
openharmony_ci
4e90ebdd73 !1200 整数溢出漏洞修复
Merge pull request !1200 from hw_llm/cherry-pick-1721456740
2024-07-22 10:22:58 +00:00
hw_llm
6241f722f3 fixed da45d3f from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1197
Description: fix CVE-817641412102197248
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IACJLK
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
2024-07-20 06:25:40 +00:00
openharmony_ci
b7a35ec4bb !1196 【同步4.1 release分支】解决UAF问题
Merge pull request !1196 from hw_llm/cherry-pick-1720749987
2024-07-12 08:18:50 +00:00
hw_llm
50410f66fb fixed 21087fb from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1195
fixed 78db02d from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1194
Description: fix CVE-810023952561737728
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/IAAZWU
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
2024-07-12 02:06:27 +00:00
openharmony_ci
26a187ede7 !1191 【Pick】【OH-4.1-Release】解决竞争冲突
Merge pull request !1191 from hw_llm/cherry-pick-1715399782
2024-05-23 12:40:06 +00:00
hw_llm
4e62fec983 fixed dfc582a from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1190
fixed dbbb96c from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1189
Description: liteos_a 内核竞争漏洞修复
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/I9OACM
Feature Or Bugfix: Bugfix
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
2024-05-11 03:56:23 +00:00
openharmony_ci
25a4c3f13a !1186 部件bundle.json 中syscap与设计信息不一致
Merge pull request !1186 from hw_llm/cherry-pick-1708502857
2024-02-22 06:34:28 +00:00
hw_llm
7dc3f24815 fixed cfa0209 from https://gitee.com/hw_llm/kernel_liteos_a/pulls/1185
Description: 删除bundle.json中syscap信息
IssueNo: https://gitee.com/openharmony/kernel_liteos_a/issues/I90PKD
Feature Or Bugfix: Feature
Binary Source: No
Signed-off-by: hw_llm <liu.limin@huawei.com>
2024-02-21 08:07:38 +00:00
openharmony_ci
c2cb0435b2 !1182 LTS 5.10 补丁升级适配
Merge pull request !1182 from Ywenrui44091/master
2023-11-20 04:43:43 +00:00
yaowenrui
4fbb41b7d5 LTS 5.10 补丁升级适配
Signed-off-by: yaowenrui <yaowenrui2@huawei.com>
2023-11-16 10:46:44 +08:00
openharmony_ci
04f971084b !1178 fix: /dev/mem 及 /proc/fs_cache 权限漏洞修复
Merge pull request !1178 from yinjiaming/fix
2023-10-16 09:38:00 +00:00
yinjiaming
6daecc8d26 fix: /dev/mem 及 /proc/fs_cache 权限漏洞修复
/dev/mem 和 /proc/fs_cache 存在多余的读写权限,
有被低权限者利用进行攻击的风险,现予以修复。

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Ie6b537e8cb1de7353dfc357411eba4920a539b4f
2023-10-12 09:52:18 +08:00
openharmony_ci
173cdeb077 !1166 fix: 修复告警
Merge pull request !1166 from Zhaotianyu/20230526fix_codecheck
2023-09-05 13:36:55 +00:00
openharmony_ci
e28271d650 !1174 fix:SysMqNotify系统调用安全增强
Merge pull request !1174 from zhangdengyu/mq_0904
2023-09-04 13:19:17 +00:00
zhangdengyu
27eb4e2334 fix:SysMqNotify系统调用安全增强
Close: #I7YG58

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: Iee5a6c24cd2226e9cab0c4fd37e76194ad068862
2023-09-04 20:43:40 +08:00
openharmony_ci
bd57ef7e2c !1161 添加unittest用例测试工具
Merge pull request !1161 from zhushengle/unittest_tools
2023-09-04 09:12:43 +00:00
zhushengle
342a3eb5c1 feat: 添加unittest用例测试工具
Close #I73IZ3

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I899978a8d8d2edeb30f0ba4d896f6f5abc8a6939
2023-09-04 11:57:15 +08:00
openharmony_ci
63885154d2 !1173 test:调整测试用例
Merge pull request !1173 from zhangdengyu/test_0831
2023-08-31 03:47:11 +00:00
zhangdengyu
95d1eb890a test: 调整测试用例
Close: #I7XBLH

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: Ie58907ea40c062fd1604035945810c53dc7f0bf2
2023-08-31 09:04:51 +08:00
openharmony_ci
0bc453c2cd !1169 修复swtmr遍历不全导致的用例问题
Merge pull request !1169 from wangchen/0726_a
2023-07-26 02:39:24 +00:00
wangchen
73bcf0ec9a Fix: 修复swtmr只在当前核遍历链表的问题
Close #I7NZDT
Signed-off-by: wangchen <wangchen240@huawei.com>
2023-07-26 09:35:58 +08:00
arvinzzz
145ff76ab6 refactor: fix codecheck
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Ib35ca40dc837d78a4c9dc03e44d117088865a5a6
2023-05-26 15:44:47 +08:00
27 changed files with 690 additions and 90 deletions

View File

@@ -87,6 +87,8 @@ OpenHarmony LiteOS-A内核支持[Hi3516DV300](https://gitee.com/openharmony/docs
编译可以参考:[编译指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-pkg-3516-build.md)
测试参考:[单元测试](testsuites/unittest/tools/README.md)
## 贡献<a name="section1371123476304"></a>
[如何贡献](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/%E5%8F%82%E4%B8%8E%E8%B4%A1%E7%8C%AE.md)

View File

@@ -27,9 +27,6 @@
"component": {
"name": "liteos_a",
"subsystem": "kernel",
"syscap": [
"SystemCapability.Kernel.Liteos-A"
],
"features": [],
"adapted_system_type": [
"small"

View File

@@ -270,6 +270,7 @@ STATIC INT32 DoMqueueClose(struct mqpersonal *privateMqPersonal)
{
struct mqarray *mqueueCB = NULL;
struct mqpersonal *tmp = NULL;
INT32 ret;
mqueueCB = privateMqPersonal->mq_posixdes;
if (mqueueCB == NULL || mqueueCB->mq_personal == NULL) {
@@ -277,6 +278,12 @@ STATIC INT32 DoMqueueClose(struct mqpersonal *privateMqPersonal)
return LOS_NOK;
}
if ((mqueueCB->unlinkflag == TRUE) && (privateMqPersonal->mq_next == NULL)) {
ret = DoMqueueDelete(mqueueCB);
if (ret < 0) {
return ret;
}
}
/* find the personal and remove */
if (mqueueCB->mq_personal == privateMqPersonal) {
mqueueCB->mq_personal = privateMqPersonal->mq_next;
@@ -298,9 +305,6 @@ STATIC INT32 DoMqueueClose(struct mqpersonal *privateMqPersonal)
/* free the personal */
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, privateMqPersonal);
if ((mqueueCB->unlinkflag == TRUE) && (mqueueCB->mq_personal == NULL)) {
return DoMqueueDelete(mqueueCB);
}
return LOS_OK;
}
@@ -604,17 +608,19 @@ int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr)
struct mqarray *mqueueCB = NULL;
struct mqpersonal *privateMqPersonal = NULL;
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
privateMqPersonal = MqGetPrivDataBuff(personal);
if (privateMqPersonal == NULL) {
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
return -1;
}
if (mqAttr == NULL) {
errno = EINVAL;
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
return -1;
}
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
errno = EBADF;
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
@@ -634,17 +640,19 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
{
struct mqpersonal *privateMqPersonal = NULL;
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
privateMqPersonal = MqGetPrivDataBuff(personal);
if (privateMqPersonal == NULL) {
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
return -1;
}
if (mqSetAttr == NULL) {
errno = EINVAL;
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);
return -1;
}
(VOID)pthread_mutex_lock(&IPC_QUEUE_MUTEX);
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
errno = EBADF;
(VOID)pthread_mutex_unlock(&IPC_QUEUE_MUTEX);

View File

@@ -61,7 +61,7 @@ static ssize_t MemMap(struct file *filep, LosVmMapRegion *region)
VADDR_T vaddr = region->range.base;
LosVmSpace *space = LOS_SpaceGet(vaddr);
if ((paddr >= SYS_MEM_BASE) && (paddr < SYS_MEM_END)) {
if (((paddr + size) >= SYS_MEM_BASE) && (paddr < SYS_MEM_END)) {
return -EINVAL;
}
@@ -97,5 +97,5 @@ static const struct file_operations_vfs g_memDevOps = {
int DevMemRegister(void)
{
return register_driver("/dev/mem", &g_memDevOps, 0666, 0); /* 0666: file mode */
return register_driver("/dev/mem", &g_memDevOps, 0644, 0); /* 0644: file mode */
}

View File

@@ -2311,7 +2311,7 @@ diff -Nupr old/fs/jffs2/erase.c new/fs/jffs2/erase.c
diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
--- old/fs/jffs2/file.c 2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/file.c 2022-05-10 09:43:14.250000000 +0800
@@ -9,335 +9,30 @@
@@ -9,334 +9,31 @@
* For licensing information, see the file 'LICENCE' in this directory.
*
*/
@@ -2348,7 +2348,7 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
- struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
+ /* FIXME: This works only with one file system mounted at a time */
int ret;
-
- ret = file_write_and_wait_range(filp, start, end);
+ ret = jffs2_read_inode_range(c, f, gc_buffer,
+ offset & ~(PAGE_SIZE-1), PAGE_SIZE);
@@ -2361,8 +2361,10 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
- inode_unlock(inode);
-
- return 0;
-}
-
+ return ERR_PTR(ret);
+ return gc_buffer;
}
-const struct file_operations jffs2_file_operations =
-{
- .llseek = generic_file_llseek,
@@ -2387,7 +2389,10 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
-};
-
-const struct address_space_operations jffs2_file_address_operations =
-{
+void jffs2_gc_release_page(struct jffs2_sb_info *c,
+ unsigned char *ptr,
+ unsigned long *priv)
{
- .readpage = jffs2_readpage,
- .write_begin = jffs2_write_begin,
- .write_end = jffs2_write_end,
@@ -2443,35 +2448,29 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
- ret = jffs2_do_readpage_unlock(pg->mapping->host, pg);
- mutex_unlock(&f->sem);
- return ret;
+ return ERR_PTR(ret);
+ return gc_buffer;
}
-}
-
-static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
- loff_t pos, unsigned len, unsigned flags,
- struct page **pagep, void **fsdata)
+void jffs2_gc_release_page(struct jffs2_sb_info *c,
+ unsigned char *ptr,
+ unsigned long *priv)
{
-{
- struct page *pg;
- struct inode *inode = mapping->host;
- struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
- struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
- pgoff_t index = pos >> PAGE_SHIFT;
- uint32_t pageofs = index << PAGE_SHIFT;
- int ret = 0;
-
- jffs2_dbg(1, "%s()\n", __func__);
-
- if (pageofs > inode->i_size) {
- /* Make new hole frag from old EOF to new page */
- if (pos > inode->i_size) {
- /* Make new hole frag from old EOF to new position */
- struct jffs2_raw_inode ri;
- struct jffs2_full_dnode *fn;
- uint32_t alloc_len;
-
- jffs2_dbg(1, "Writing new hole frag 0x%x-0x%x between current EOF and new page\n",
- (unsigned int)inode->i_size, pageofs);
- jffs2_dbg(1, "Writing new hole frag 0x%x-0x%x between current EOF and new position\n",
- (unsigned int)inode->i_size, (uint32_t)pos);
-
- ret = jffs2_reserve_space(c, sizeof(ri), &alloc_len,
- ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
@@ -2491,10 +2490,10 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
- ri.mode = cpu_to_jemode(inode->i_mode);
- ri.uid = cpu_to_je16(i_uid_read(inode));
- ri.gid = cpu_to_je16(i_gid_read(inode));
- ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs));
- ri.isize = cpu_to_je32((uint32_t)pos);
- ri.atime = ri.ctime = ri.mtime = cpu_to_je32(JFFS2_NOW());
- ri.offset = cpu_to_je32(inode->i_size);
- ri.dsize = cpu_to_je32(pageofs - inode->i_size);
- ri.dsize = cpu_to_je32((uint32_t)pos - inode->i_size);
- ri.csize = cpu_to_je32(0);
- ri.compr = JFFS2_COMPR_ZERO;
- ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
@@ -2524,7 +2523,7 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
- goto out_err;
- }
- jffs2_complete_reservation(c);
- inode->i_size = pageofs;
- inode->i_size = pos;
- mutex_unlock(&f->sem);
- }
-
@@ -6341,7 +6340,7 @@ diff -Nupr old/fs/jffs2/summary.h new/fs/jffs2/summary.h
diff -Nupr old/fs/jffs2/super.c new/fs/jffs2/super.c
--- old/fs/jffs2/super.c 2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/super.c 2022-05-09 20:09:32.170000000 +0800
@@ -9,433 +9,188 @@
@@ -9,434 +9,188 @@
*
*/
@@ -6419,6 +6418,7 @@ diff -Nupr old/fs/jffs2/super.c new/fs/jffs2/super.c
+ c->cleanmarker_size = sizeof(struct jffs2_unknown_node);
- mutex_init(&f->sem);
- f->target = NULL;
- inode_init_once(&f->vfs_inode);
-}
+ ret = jffs2_do_mount_fs(c);

View File

@@ -490,14 +490,14 @@ off_t VfsJffs2Seek(struct file *filep, off_t offset, int whence)
filePos = filep->f_pos;
switch (whence) {
case SEEK_SET:
filePos = offset;
break;
case SEEK_CUR:
filePos += offset;
break;
case SEEK_SET:
filePos = offset;
break;
case SEEK_END:
filePos = node->i_size + offset;
break;

View File

@@ -207,7 +207,7 @@ static const struct ProcFileOperations FS_CACHE_PROC_FOPS = {
void ProcFsCacheInit(void)
{
struct ProcDirEntry *pde = CreateProcEntry("fs_cache", 0, NULL);
struct ProcDirEntry *pde = CreateProcEntry("fs_cache", 0400, NULL);
if (pde == NULL) {
PRINT_ERR("create fs_cache error!\n");
return;

View File

@@ -220,14 +220,18 @@ int epoll_close(int epfd)
{
struct epoll_head *epHead = NULL;
(VOID)pthread_mutex_lock(&g_epollMutex);
epHead = EpollGetDataBuff(epfd);
if (epHead == NULL) {
(VOID)pthread_mutex_unlock(&g_epollMutex);
set_errno(EBADF);
return -1;
}
DoEpollClose(epHead);
return EpollFreeSysFd(epfd);
int ret = EpollFreeSysFd(epfd);
(VOID)pthread_mutex_unlock(&g_epollMutex);
return ret;
}
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
@@ -236,15 +240,16 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
int i;
int ret = -1;
(VOID)pthread_mutex_lock(&g_epollMutex);
epHead = EpollGetDataBuff(epfd);
if (epHead == NULL) {
set_errno(EBADF);
return ret;
goto OUT_RELEASE;
}
if (ev == NULL) {
set_errno(EINVAL);
return -1;
goto OUT_RELEASE;
}
switch (op) {
@@ -252,18 +257,19 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
ret = CheckFdExist(epHead, fd);
if (ret == -1) {
set_errno(EEXIST);
return -1;
goto OUT_RELEASE;
}
if (epHead->nodeCount == EPOLL_DEFAULT_SIZE) {
set_errno(ENOMEM);
return -1;
goto OUT_RELEASE;
}
epHead->evs[epHead->nodeCount].events = ev->events | POLLERR | POLLHUP;
epHead->evs[epHead->nodeCount].data.fd = fd;
epHead->nodeCount++;
return 0;
ret = 0;
break;
case EPOLL_CTL_DEL:
for (i = 0; i < epHead->nodeCount; i++) {
if (epHead->evs[i].data.fd != fd) {
@@ -275,23 +281,29 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
epHead->nodeCount - i);
}
epHead->nodeCount--;
return 0;
ret = 0;
goto OUT_RELEASE;
}
set_errno(ENOENT);
return -1;
break;
case EPOLL_CTL_MOD:
for (i = 0; i < epHead->nodeCount; i++) {
if (epHead->evs[i].data.fd == fd) {
epHead->evs[i].events = ev->events | POLLERR | POLLHUP;
return 0;
ret = 0;
goto OUT_RELEASE;
}
}
set_errno(ENOENT);
return -1;
break;
default:
set_errno(EINVAL);
return -1;
break;
}
OUT_RELEASE:
(VOID)pthread_mutex_unlock(&g_epollMutex);
return ret;
}
int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout)
@@ -326,7 +338,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout
return -1;
}
for (i = 0; i < epHead->nodeCount; i++) {
for (i = 0; i < pollSize; i++) {
pFd[i].fd = epHead->evs[i].data.fd;
pFd[i].events = (short)epHead->evs[i].events;
}

View File

@@ -583,7 +583,7 @@ STATIC INLINE BOOL SwtmrRunqueueFind(SortLinkAttribute *swtmrSortLink, SCHED_TL_
STATIC BOOL SwtmrTimeListFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
{
for (UINT16 cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
SortLinkAttribute *swtmrSortLink = &g_swtmrRunqueue[ArchCurrCpuid()].swtmrSortLink;
SortLinkAttribute *swtmrSortLink = &g_swtmrRunqueue[cpuid].swtmrSortLink;
if (SwtmrRunqueueFind(swtmrSortLink, checkFunc, arg)) {
return TRUE;
}

View File

@@ -157,7 +157,8 @@ typedef struct VmSpace {
#define VM_MAP_REGION_FLAG_SHM (1<<16)
#define VM_MAP_REGION_FLAG_FIXED (1<<17)
#define VM_MAP_REGION_FLAG_FIXED_NOREPLACE (1<<18)
#define VM_MAP_REGION_FLAG_INVALID (1<<19) /* indicates that flags are not specified */
#define VM_MAP_REGION_FLAG_LITEIPC (1<<19)
#define VM_MAP_REGION_FLAG_INVALID (1<<20) /* indicates that flags are not specified */
STATIC INLINE UINT32 OsCvtProtFlagsToRegionFlags(unsigned long prot, unsigned long flags)
{

View File

@@ -379,6 +379,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 processID, VOID *seqBu
(VOID)memset_s(threadInfo, sizeof(ProcessThreadInfo), 0, sizeof(ProcessThreadInfo));
if (OsGetProcessThreadInfo(processID, threadInfo) != LOS_OK) {
(VOID)LOS_MemFree(m_aucSysMem1, threadInfo);
return LOS_NOK;
}

View File

@@ -76,6 +76,8 @@ const CHAR *OsGetRegionNameOrFilePath(LosVmMapRegion *region)
return "MMAP";
} else if (region->regionFlags & VM_MAP_REGION_FLAG_SHM) {
return "SHM";
} else if (region->regionFlags & VM_MAP_REGION_FLAG_LITEIPC) {
return "LITEIPC";
} else {
return "";
}

View File

@@ -273,6 +273,8 @@ STATIC UINT32 OsInheritOldRegionName(UINT32 oldRegionFlags)
vmFlags |= VM_MAP_REGION_FLAG_MMAP;
} else if (oldRegionFlags & VM_MAP_REGION_FLAG_SHM) {
vmFlags |= VM_MAP_REGION_FLAG_SHM;
} else if (oldRegionFlags & VM_MAP_REGION_FLAG_LITEIPC) {
vmFlags |= VM_MAP_REGION_FLAG_LITEIPC;
}
return vmFlags;
@@ -298,7 +300,9 @@ INT32 LOS_DoMprotect(VADDR_T vaddr, size_t len, unsigned long prot)
goto OUT_MPROTECT;
}
if ((region->regionFlags & VM_MAP_REGION_FLAG_VDSO) || (region->regionFlags & VM_MAP_REGION_FLAG_HEAP)) {
if ((region->regionFlags & VM_MAP_REGION_FLAG_VDSO) ||
(region->regionFlags & VM_MAP_REGION_FLAG_HEAP) ||
(region->regionFlags & VM_MAP_REGION_FLAG_LITEIPC)) {
ret = -EPERM;
goto OUT_MPROTECT;
}

View File

@@ -689,6 +689,9 @@ INT32 ShmCtl(INT32 shmid, INT32 cmd, struct shmid_ds *buf)
(shm_perm.mode & ACCESSPERMS);
seg->ds.shm_ctime = time(NULL);
#ifdef LOSCFG_SHELL
if (OsProcessIDUserCheckInvalid(shm_perm.uid)) {
break;
}
(VOID)memcpy_s(seg->ownerName, OS_PCB_NAME_LEN, OS_PCB_FROM_PID(shm_perm.uid)->processName,
OS_PCB_NAME_LEN);
#endif

View File

@@ -687,7 +687,7 @@ STATIC ssize_t ConsoleRead(struct file *filep, CHAR *buffer, size_t bufLen)
}
if (userBuf) {
if (LOS_ArchCopyToUser(buffer, sbuffer, bufLen) != 0) {
if (LOS_ArchCopyToUser(buffer, sbuffer, ret) != 0) {
ret = -EFAULT;
goto ERROUT;
}

View File

@@ -278,7 +278,6 @@ static void DumpFaultLog(void)
static void DumpMemData(struct MemDumpParam *param)
{
PRINTK("\nDumpType: %d\n", param->type);
PRINTK("Unsupported now!\n");
}

View File

@@ -239,6 +239,7 @@ LITE_OS_SEC_TEXT STATIC int LiteIpcMmap(struct file *filep, LosVmMapRegion *regi
goto ERROR_MAP_OUT;
}
ipcInfo->pool.poolSize = region->range.size;
region->regionFlags |= VM_MAP_REGION_FLAG_LITEIPC;
return 0;
ERROR_MAP_OUT:
LOS_VFree(ipcInfo->pool.kvaddr);
@@ -757,7 +758,10 @@ LITE_OS_SEC_TEXT STATIC UINT32 HandlePtr(LosProcessCB *pcb, SpecialObj *obj, BOO
obj->content.ptr.buff = (VOID *)GetIpcUserAddr(pcb, (INTPTR)buf);
EnableIpcNodeFreeByUser(pcb, (VOID *)buf);
} else {
(VOID)LiteIpcNodeFree(pcb, (VOID *)GetIpcKernelAddr(pcb, (INTPTR)obj->content.ptr.buff));
buf = (VOID *)GetIpcKernelAddr(pcb, (INTPTR)obj->content.ptr.buff);
if (IsIpcNode(pcb, buf) == TRUE) {
(VOID)LiteIpcNodeFree(pcb, buf);
}
}
return LOS_OK;
}

View File

@@ -485,29 +485,35 @@ UINT32 OsDevLimitWriteDeny(ProcLimitSet *plimit, const CHAR *buf, UINT32 size)
return DevLimitUpdateAccess(plimit, buf, DEVLIMIT_DENY);
}
STATIC VOID DevLimitItemSetAccess(CHAR *acc, INT16 access)
STATIC VOID DevLimitItemSetAccess(CHAR *accArray, INT16 access)
{
INT32 index = 0;
(VOID)memset_s(acc, ACCLEN, 0, ACCLEN);
(VOID)memset_s(accArray, ACCLEN, 0, ACCLEN);
if (access & DEVLIMIT_ACC_READ) {
acc[index++] = 'r';
accArray[index] = 'r';
index++;
}
if (access & DEVLIMIT_ACC_WRITE) {
acc[index++] = 'w';
accArray[index] = 'w';
index++;
}
if (access & DEVLIMIT_ACC_MKNOD) {
acc[index++] = 'm';
accArray[index] = 'm';
index++;
}
}
STATIC CHAR DevLimitItemTypeToChar(INT16 type)
{
if (type == DEVLIMIT_DEV_ALL) {
return 'a';
} else if (type == DEVLIMIT_DEV_CHAR) {
return 'c';
} else if (type == DEVLIMIT_DEV_BLOCK) {
return 'b';
switch (type) {
case DEVLIMIT_DEV_ALL:
return 'a';
case DEVLIMIT_DEV_CHAR:
return 'c';
case DEVLIMIT_DEV_BLOCK:
return 'b';
default:
break;
}
return 'X';
}

View File

@@ -154,7 +154,6 @@ INT32 CmdLog(INT32 argc, const CHAR **argv)
PRINTK("not support yet\n");
}
} else if (!strncmp(argv[0], "path", strlen(argv[0]) + 1)) {
OsLkLogFileSet(argv[1]);
PRINTK("not support yet\n");
} else {
PRINTK("Usage: log level <num>\n");

View File

@@ -94,9 +94,15 @@ int SysMqClose(mqd_t personal)
int SysMqNotify(mqd_t personal, const struct sigevent *sigev)
{
int ret;
struct sigevent ksigev;
ret = LOS_ArchCopyFromUser(&ksigev, sigev, sizeof(struct sigevent));
if (ret != 0) {
return -EFAULT;
}
MQUEUE_FD_U2K(personal);
ret = OsMqNotify(personal, sigev);
ret = OsMqNotify(personal, &ksigev);
if (ret < 0) {
return -get_errno();
}

View File

@@ -401,7 +401,7 @@ ssize_t SysSendMsg(int s, const struct msghdr *message, int flags)
CHECK_ASPACE(message, sizeof(struct msghdr));
CPY_FROM_CONST_USER(struct msghdr, message);
if (message && message->msg_iovlen > IOV_MAX) {
if (message && (size_t)message->msg_iovlen > IOV_MAX) {
set_errno(EMSGSIZE);
return -get_errno();
}
@@ -449,7 +449,7 @@ ssize_t SysRecvMsg(int s, struct msghdr *message, int flags)
CHECK_ASPACE(message, sizeof(struct msghdr));
CPY_FROM_NONCONST_USER(message);
if (message && message->msg_iovlen > IOV_MAX) {
if (message && (size_t)message->msg_iovlen > IOV_MAX) {
set_errno(EMSGSIZE);
return -get_errno();
}

View File

@@ -67,6 +67,8 @@ config("public_config_for_pressure") {
group("unittest") {
deps = []
if (ohos_build_type == "debug") {
deps += [ "tools:liteos_unittest_run" ]
# basic test
if (LOSCFG_USER_TEST_BASIC == true) {
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {

View File

@@ -53,26 +53,6 @@ HWTEST_F(TimeTimerTest, TimerTest001, TestSize.Level0)
TimerTest001();
}
/* *
* @tc.name: TimerTest002
* @tc.desc: function for TimeTimerTest
* @tc.type: FUNC
*/
HWTEST_F(TimeTimerTest, TimerTest002, TestSize.Level0)
{
TimerTest002();
}
/* *
* @tc.name: TimerTest003
* @tc.desc: function for TimeTimerTest
* @tc.type: FUNC
*/
HWTEST_F(TimeTimerTest, TimerTest003, TestSize.Level0)
{
TimerTest003();
}
/* *
* @tc.name: TimerTest005
* @tc.desc: function for timer_create SIGEV_THREAD.

View File

@@ -0,0 +1,38 @@
# 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/liteos.gni")
import("//kernel/liteos_a/testsuites/unittest/config.gni")
unittest("liteos_unittest_run") {
output_extension = "bin"
output_dir = "$root_out_dir/test/unittest/kernel"
sources = [ "unittest_tools.cpp" ]
deps = [ "$THIRDPARTY_BOUNDS_CHECKING_FUNCTION_DIR:libsec_shared" ]
}

View File

@@ -0,0 +1,63 @@
# LiteOS Unittest tools
## 介绍
可执行程序 ***liteos_unittest_run.bin*** 是为了提升liteos unittest 测试效率的工具。
## 使用介绍
### 1.使用帮助
```
OHOS # ./liteos_unittest_run.bin --help
Usage:
liteos_unittest_run.bin [testsuites_dir] [options]
options:
-r [1-1000] --- The number of repeated runs of the test program.
-m [smoke/full] --- Run the smoke or full test case in this directory.
-t [case] [args] -t ... --- Runs the specified executable program name.
```
- testsuites_dir: unittest 用例所在的绝对路径
### 2.常见测试场景举例
假设单板上单元测试用例位于路径 ***/usr/bin/unittest*** 下。
#### 2.1 运行全量用例或smoke用例
- smoke命令
```
./liteos_unittest_run.bin /usr/bin/unittest -r 10 -m smoke
```
注: -r 10 表示: smoke用例运行10次 一般用于压测
- 全量命令
```
./liteos_unittest_run.bin /usr/bin/unittest -r 10 -m full
```
注: -r 10 表示: 全量用例运行10次 一般用于压测
#### 2.2 单或多用例组合运行
- 单用例执行命令
```
./liteos_unittest_run.bin /usr/bin/unittest -r 10 -t liteos_a_basic_unittest.bin
```
注: 只运行liteos_a_basic_unittest.bin 用例, 重复10次
```
./liteos_unittest_run.bin /usr/bin/unittest -r 10 -t liteos_a_basic_unittest.bin --gtest_filter=ExcTest.ItTestExc002
```
注: 只运行liteos_a_basic_unittest.bin 用例中的ItTestExc002重复10次
- 多用例组合命令
```
./liteos_unittest_run.bin /usr/bin/unittest -r 10 -t liteos_a_basic_unittest.bin -t liteos_a_process_basic_pthread_unittest_door.bin
```
注: 先运行liteos_a_basic_unittest.bin再运行liteos_a_process_basic_pthread_unittest_door.bin 重复10次。-t 最多5个。
```
./liteos_unittest_run.bin /usr/bin/unittest -r 10 -t liteos_a_basic_unittest.bin --gtest_filter=ExcTest.ItTestExc002 -t liteos_a_process_basic_pthread_unittest_door.bin --gtest_filter=ProcessPthreadTest.ItTestPthread003
```
注:先运行liteos_a_basic_unittest.bin的ItTestExc002再运行liteos_a_process_basic_pthread_unittest_door.bin的ItTestPthread003重复10次。-t最多5个。

View File

@@ -0,0 +1,468 @@
/*
* 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 <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <dirent.h>
#include <unistd.h>
#include <sys/wait.h>
#include <securec.h>
using namespace std;
const static int TEST_PATH_MAX = 255;
const static int TEST_PARAM_NUM = 5;
const static int TEST_CASE_MODE_FULL = 0;
const static int TEST_CASE_MODE_SMOKE = 1;
const static int TEST_DEFAULT_CASE_MAX = 5;
const static int TEST_T_PARAM_LEN = 2;
const static unsigned int TEST_CASE_FLAGS_ALL = 1;
const static unsigned int TEST_CASE_FLAGS_SPECIFY = 2;
const static unsigned int TEST_CASE_FAILED_COUNT_MAX = 500;
static unsigned int g_testsuitesCount = 0;
static unsigned int g_testsuitesFailedCount = 0;
struct TestCase {
char bin[TEST_PATH_MAX];
char *param[TEST_PARAM_NUM];
int caseLen;
};
struct TestsuitesParam {
char testsuitesBin[TEST_PATH_MAX];
char testsuitesDir[TEST_PATH_MAX];
int testsuitesDirLen;
struct TestCase *testCase[TEST_DEFAULT_CASE_MAX];
int testCaseNum;
int testMode;
int repeat;
};
static struct TestsuitesParam g_param;
static char *g_testsuitesFailedCase[TEST_CASE_FAILED_COUNT_MAX];
static vector<string> GetAllTestsuites(string testsuitesDir)
{
vector<string> vFiles;
int suffixLen = strlen(".bin");
DIR *dir = opendir(testsuitesDir.c_str());
if (dir == nullptr) {
cout << "opendir " << testsuitesDir << " failed" << endl;
return vFiles;
}
do {
struct dirent *pDir = readdir(dir);
if (pDir == nullptr) {
break;
}
if ((strcmp(pDir->d_name, ".") == 0) || (strcmp(pDir->d_name, "..") == 0)) {
continue;
}
if (pDir->d_type == DT_REG) {
int pathLen = strlen(pDir->d_name);
if (pathLen <= suffixLen) {
continue;
}
if (strcmp(".bin", (char *)(pDir->d_name + (pathLen - suffixLen))) != 0) {
continue;
}
vFiles.push_back(testsuitesDir + "/" + pDir->d_name);
}
} while (1);
closedir(dir);
return vFiles;
}
static bool TestsuitesIsSmoke(string testsuite, int fileLen, string smokeTest, int smokeTestLen)
{
if (fileLen <= smokeTestLen) {
return false;
}
if (strcmp(smokeTest.c_str(), (char *)(testsuite.c_str() + (fileLen - smokeTestLen))) == 0) {
return true;
}
return false;
}
static void RunCase(const char *testCase, char *param[])
{
int ret;
int size;
int status = 0;
pid_t pid = fork();
if (pid < 0) {
cout << "fork failed, " << strerror(errno) << endl;
return;
}
g_testsuitesCount++;
if (pid == 0) {
cout << testCase << ":" << endl;
ret = execve(param[0], param, nullptr);
if (ret != 0) {
cout << "execl: " << testCase << " failed, " << strerror(errno) << endl;
exit(0);
}
}
ret = waitpid(pid, &status, 0);
if (ret != pid) {
cout << "waitpid failed, " << strerror(errno) << endl;
return;
}
if (WEXITSTATUS(status) == 0) {
return;
}
if (g_testsuitesFailedCount >= TEST_CASE_FAILED_COUNT_MAX) {
cout << "[UNITTEST_RUN] Failure cases more than upper limit!\n";
return;
}
size = strlen(testCase) + 1;
g_testsuitesFailedCase[g_testsuitesFailedCount] = static_cast<char *>(malloc(size));
if (g_testsuitesFailedCase[g_testsuitesFailedCount] == nullptr) {
cout << "[UNITTEST_RUN] malloc failed!\n";
return;
}
if (memcpy_s(g_testsuitesFailedCase[g_testsuitesFailedCount], size, testCase, size) != EOK) {
cout << "[UNITTEST_RUN] memcpy failed!\n";
return;
}
g_testsuitesFailedCount++;
}
static void RunAllTestCase(vector<string> files, struct TestsuitesParam *param)
{
const char *testMode = nullptr;
const char *smokeTest = "door.bin";
const char *unittestRun = g_param.testsuitesBin;
int unittestRunLen = strlen(unittestRun);
int smokeTestLen = strlen(smokeTest);
char *execParam[TEST_PARAM_NUM];
if (param->testMode == TEST_CASE_MODE_SMOKE) {
testMode = "door.bin";
} else {
testMode = ".bin";
}
for (size_t i = 0; i < files.size(); i++) {
int fileLen = strlen(files[i].c_str());
if (fileLen >= unittestRunLen) {
if (strcmp((char *)(files[i].c_str() + (fileLen - unittestRunLen)), unittestRun) == 0) {
continue;
}
}
if (strcmp(testMode, smokeTest) == 0) {
if (!TestsuitesIsSmoke(files[i], fileLen, smokeTest, smokeTestLen)) {
continue;
}
} else {
if (TestsuitesIsSmoke(files[i], fileLen, smokeTest, smokeTestLen)) {
continue;
}
}
(void)memset_s(execParam, sizeof(char *) * TEST_PARAM_NUM, 0, sizeof(char *) * TEST_PARAM_NUM);
execParam[0] = (char *)files[i].c_str();
RunCase(files[i].c_str(), execParam);
}
}
static void TestsuitesToolsUsage(void)
{
cout << "Usage: " << endl;
cout << "liteos_unittest_run.bin [testsuites_dir] [options]" << endl;
cout << "options:" << endl;
cout << " -r [1-1000] --- The number of repeated runs of the test program." << endl;
cout << " -m [smoke/full] --- Run the smoke or full test case in this directory." << endl;
cout << " -t [case] [args] -t ... --- Runs the specified executable program name." << endl;
}
static int TestsuitesDirFormat(char *testDir, int len)
{
if (memcpy_s(g_param.testsuitesDir, TEST_PATH_MAX, testDir, len + 1) != EOK) {
cout << "testsuites dir: " << strerror(ENAMETOOLONG) << endl;
return -1;
}
char *end = g_param.testsuitesDir + len;
while ((testDir != end) && (*end == '/')) {
*end = '\0';
end--;
len--;
}
g_param.testsuitesDirLen = len;
if (len <= 0) {
return -1;
}
return 0;
}
static int GetTestsuitesToolsName(const char *argv[])
{
const char *testBin = static_cast<const char *>(argv[0]);
const char *end = testBin + strlen(testBin);
while (*end != '/') {
end--;
}
end++;
if (memcpy_s(g_param.testsuitesBin, TEST_PATH_MAX, end, strlen(end)) != EOK) {
cout << "testsuites dir: " << strerror(ENAMETOOLONG) << endl;
return -1;
}
return 0;
}
static int ParseTestCaseAndParam(int argc, const char *argv[], int *index)
{
int j;
(*index)++;
if (*index >= argc) {
return -1;
}
if (g_param.testCaseNum >= TEST_DEFAULT_CASE_MAX) {
return -1;
}
g_param.testCase[g_param.testCaseNum] = (struct TestCase *)malloc(sizeof(struct TestCase));
if (g_param.testCase[g_param.testCaseNum] == nullptr) {
cout << "test case " << strerror(ENOMEM) << endl;
return -1;
}
(void)memset_s(g_param.testCase[g_param.testCaseNum], sizeof(struct TestCase), 0, sizeof(struct TestCase));
struct TestCase *testCase = g_param.testCase[g_param.testCaseNum];
testCase->caseLen = strlen(argv[*index]);
if (memcpy_s(testCase->bin, TEST_PATH_MAX, argv[*index], testCase->caseLen + 1) != EOK) {
testCase->caseLen = 0;
cout << "test case " << strerror(ENAMETOOLONG) << endl;
return -1;
}
testCase->param[0] = testCase->bin;
(*index)++;
for (j = 1; (j < TEST_PARAM_NUM) && (*index < argc) && (strncmp("-t", argv[*index], TEST_T_PARAM_LEN) != 0); j++) {
testCase->param[j] = (char *)argv[*index];
(*index)++;
}
g_param.testCaseNum++;
if (((*index) < argc) && (strncmp("-t", argv[*index], TEST_T_PARAM_LEN) == 0)) {
(*index)--;
}
return 0;
}
static int TestsuitesParamCheck(int argc, const char *argv[])
{
int ret;
unsigned int mask = 0;
g_param.testMode = TEST_CASE_MODE_FULL;
g_param.repeat = 1;
ret = TestsuitesDirFormat((char *)argv[1], strlen(argv[1]));
if (ret < 0) {
return -1;
}
for (int i = 2; i < argc; i++) { /* 2: param index */
if (strcmp("-m", argv[i]) == 0) {
i++;
if (i >= argc) {
return -1;
}
mask |= TEST_CASE_FLAGS_ALL;
if (strcmp("smoke", argv[i]) == 0) {
g_param.testMode = TEST_CASE_MODE_SMOKE;
} else if (strcmp("full", argv[i]) == 0) {
g_param.testMode = TEST_CASE_MODE_FULL;
} else {
return -1;
}
} else if (strcmp("-t", argv[i]) == 0) {
mask |= TEST_CASE_FLAGS_SPECIFY;
ret = ParseTestCaseAndParam(argc, argv, &i);
if (ret < 0) {
return ret;
}
} else if (strcmp("-r", argv[i]) == 0) {
i++;
if (i >= argc) {
return -1;
}
g_param.repeat = atoi(argv[i]);
if ((g_param.repeat <= 0) || (g_param.repeat > 1000)) { /* 1000: repeat limit */
return -1;
}
}
}
if (((mask & TEST_CASE_FLAGS_ALL) != 0) && ((mask & TEST_CASE_FLAGS_SPECIFY) != 0)) {
cout << "Invalid parameter combination" << endl;
return -1;
}
return 0;
}
static void IsCase(vector<string> files, struct TestCase *testCase)
{
for (size_t i = 0; i < files.size(); i++) {
string file = files[i];
int fileLen = strlen(file.c_str());
if (fileLen <= testCase->caseLen) {
continue;
}
const string &suffix = file.c_str() + (fileLen - testCase->caseLen);
if (strcmp(suffix.c_str(), testCase->bin) != 0) {
continue;
}
if (memcpy_s(testCase->bin, TEST_PATH_MAX, file.c_str(), fileLen + 1) != EOK) {
testCase->caseLen = 0;
return;
}
testCase->caseLen = fileLen;
g_param.testCaseNum++;
return;
}
cout << "liteos_unittest_run.bin: not find test case: " << testCase->bin << endl;
return;
}
static int FindTestCase(vector<string> files)
{
int count = g_param.testCaseNum;
g_param.testCaseNum = 0;
for (int i = 0; i < count; i++) {
IsCase(files, g_param.testCase[i]);
}
if (g_param.testCaseNum == 0) {
cout << "Not find test case !" << endl;
return -1;
}
return 0;
}
static void FreeTestCaseMem(void)
{
for (int index = 0; index < g_param.testCaseNum; index++) {
free(g_param.testCase[index]);
g_param.testCase[index] = nullptr;
}
}
static void ShowTestLog(int count)
{
cout << "[UNITTEST_RUN] Repeats: " << count << " Succeed count: "
<< g_testsuitesCount - g_testsuitesFailedCount
<< " Failed count: " << g_testsuitesFailedCount << endl;
if (g_testsuitesFailedCount == 0) {
return;
}
cout << "[UNITTEST_RUN] Failed testcase: " << endl;
for (int i = 0; i < g_testsuitesFailedCount; i++) {
cout << "[" << i << "] -> " << g_testsuitesFailedCase[i] << endl;
free(g_testsuitesFailedCase[i]);
g_testsuitesFailedCase[i] = nullptr;
}
}
int main(int argc, const char *argv[])
{
int ret;
int count = 0;
if ((argc < 2) || (argv == nullptr)) { /* 2: param index */
cout << argv[0] << ": " << strerror(EINVAL) << endl;
return -1;
}
if ((strcmp("--h", argv[1]) == 0) || (strcmp("--help", argv[1]) == 0)) {
TestsuitesToolsUsage();
return 0;
}
(void)memset_s(&g_param, sizeof(struct TestsuitesParam), 0, sizeof(struct TestsuitesParam));
ret = GetTestsuitesToolsName(argv);
if (ret < 0) {
return -1;
}
ret = TestsuitesParamCheck(argc, argv);
if (ret < 0) {
cout << strerror(EINVAL) << endl;
FreeTestCaseMem();
return -1;
}
vector<string> files = GetAllTestsuites(g_param.testsuitesDir);
if (g_param.testCaseNum != 0) {
ret = FindTestCase(files);
if (ret < 0) {
files.clear();
FreeTestCaseMem();
return -1;
}
}
while (count < g_param.repeat) {
if (g_param.testCaseNum == 0) {
RunAllTestCase(files, &g_param);
} else {
for (int index = 0; index < g_param.testCaseNum; index++) {
RunCase(g_param.testCase[index]->bin, g_param.testCase[index]->param);
}
}
count++;
}
files.clear();
FreeTestCaseMem();
ShowTestLog(count);
return 0;
}

View File

@@ -124,6 +124,11 @@ LITEOS_BASELIB += -lcommon
LIB_SUBDIRS += kernel/common
LITEOS_KERNEL_INCLUDE += -I $(LITEOSTOPDIR)/kernel/common
ifeq ($(LOSCFG_KERNEL_CONTAINER), y)
LITEOS_BASELIB += -lcontainer
LIB_SUBDIRS += kernel/extended/container
endif
ifeq ($(LOSCFG_KERNEL_CPPSUPPORT), y)
LITEOS_BASELIB += -lcppsupport
LIB_SUBDIRS += kernel/extended/cppsupport