From 780c3c69cff42bf845c8921ce487006626a6a8e6 Mon Sep 17 00:00:00 2001 From: kuangyufei Date: Tue, 2 Nov 2021 08:57:56 +0800 Subject: [PATCH] =?UTF-8?q?=20=E5=90=8C=E6=AD=A5=E5=AE=98=E6=96=B9?= =?UTF-8?q?=E4=BB=93=E5=BA=93,=E6=9C=AC=E6=AC=A1=E6=94=B9=E5=8A=A8?= =?UTF-8?q?=E4=B8=8D=E5=A4=A7,=E5=AF=B9process,task=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BA=86=E5=BE=AE=E8=B0=83=20=20=20=20=20?= =?UTF-8?q?=E7=99=BE=E4=B8=87=E6=B1=89=E5=AD=97=E6=B3=A8=E8=A7=A3=20+=20?= =?UTF-8?q?=E7=99=BE=E7=AF=87=E5=8D=9A=E5=AE=A2=E5=88=86=E6=9E=90=20=3D>?= =?UTF-8?q?=20=E6=8C=96=E9=80=8F=E9=B8=BF=E8=92=99=E5=86=85=E6=A0=B8?= =?UTF-8?q?=E6=BA=90=E7=A0=81=20=20=20=20=20=E5=8D=9A=E5=AE=A2=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=AB=99=E7=82=B9(=E5=9B=BD=E5=86=85):http://weharmon?= =?UTF-8?q?yos.com=20=20=20=20=20=E5=8D=9A=E5=AE=A2=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E7=AB=99=E7=82=B9(=E5=9B=BD=E5=A4=96):https://weharmony.github?= =?UTF-8?q?.io=20=20=20=20=20=E6=B3=A8=E8=A7=A3=E6=96=87=E4=BB=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F:https://gitee.com/weharmony/third=5Fparty=5FNuttX=20?= =?UTF-8?q?=20=20=20=20=E6=B3=A8=E8=A7=A3=E5=8D=8F=E8=AE=AE=E6=A0=88:https?= =?UTF-8?q?://gitee.com/weharmony/third=5Fparty=5Flwip=20=20=20=20=20?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E7=BC=96=E8=AF=91=E5=AD=90=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?:https://gitee.com/weharmony/build=5Flite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 152 ++++---- apps/config.mk | 2 +- apps/shell/builtin/cd.c | 2 - apps/shell/include/shcmd.h | 2 +- apps/shell/src/main.c | 2 + apps/shell/src/shmsg.c | 2 + compat/posix/src/misc.c | 35 +- compat/posix/src/pthread.c | 2 +- kernel/base/core/los_process.c | 11 +- kernel/base/core/los_task.c | 293 ++++++++++----- kernel/base/include/los_process_pri.h | 2 +- kernel/base/include/los_task_pri.h | 12 +- kernel/base/ipc/los_signal.c | 40 +- kernel/base/sched/sched_sq/los_sched.c | 3 - kernel/common/los_printf.c | 1 + kernel/extended/hilog/los_hilog.c | 7 + kernel/extended/liteipc/hm_liteipc.c | 19 +- kernel/extended/liteipc/hm_liteipc.h | 7 +- kernel/include/los_task.h | 53 ++- syscall/fs_syscall.c | 47 +++ syscall/los_syscall.h | 4 +- syscall/process_syscall.c | 6 +- syscall/syscall_lookup.h | 3 +- testsuites/unittest/IO/BUILD.gn | 2 + testsuites/unittest/IO/It_test_IO.h | 1 + .../unittest/IO/full/IO_test_pselect_001.cpp | 79 +++- .../unittest/IO/full/IO_test_pselect_002.cpp | 123 ++++++ testsuites/unittest/IO/io_test.cpp | 22 ++ testsuites/unittest/common/include/osTest.h | 19 +- testsuites/unittest/common/osTest.cpp | 64 ++++ testsuites/unittest/config.gni | 6 +- .../unittest/misc/full/misc_test_009.cpp | 23 +- testsuites/unittest/process/process/BUILD.gn | 58 +-- .../{smoke => full}/process_test_007.cpp | 0 .../{smoke => full}/process_test_031.cpp | 0 .../{smoke => full}/process_test_032.cpp | 0 .../{smoke => full}/process_test_033.cpp | 0 .../{smoke => full}/process_test_034.cpp | 0 .../{smoke => full}/process_test_035.cpp | 0 .../{smoke => full}/process_test_036.cpp | 0 .../{smoke => full}/process_test_037.cpp | 0 .../{smoke => full}/process_test_040.cpp | 0 .../{smoke => full}/process_test_041.cpp | 0 .../{smoke => full}/process_test_042.cpp | 0 .../{smoke => full}/process_test_049.cpp | 0 .../{smoke => full}/process_test_050.cpp | 0 .../{smoke => full}/process_test_051.cpp | 0 .../{smoke => full}/process_test_052.cpp | 0 .../{smoke => full}/process_test_056.cpp | 0 .../{smoke => full}/process_test_057.cpp | 0 .../{smoke => full}/process_test_058.cpp | 0 .../{smoke => full}/process_test_059.cpp | 0 .../{smoke => full}/process_test_060.cpp | 0 .../{smoke => full}/process_test_063.cpp | 0 .../{smoke => full}/process_test_064.cpp | 0 .../{smoke => full}/process_test_065.cpp | 0 .../{smoke => full}/process_test_066.cpp | 0 .../{smoke => full}/process_test_067.cpp | 0 .../{smoke => full}/process_test_068.cpp | 0 .../{smoke => full}/process_test_069.cpp | 0 .../process/process/process_process_test.cpp | 353 +++++------------- .../process/smoke/process_test_045.cpp | 4 +- .../{full => smoke}/process_test_054.cpp | 0 .../{full => smoke}/process_test_061.cpp | 0 testsuites/unittest/process/pthread/BUILD.gn | 12 +- .../{smoke => full}/pthread_test_001.cpp | 0 .../{smoke => full}/pthread_test_002.cpp | 0 .../{smoke => full}/pthread_test_004.cpp | 4 + .../{smoke => full}/pthread_test_005.cpp | 0 .../{smoke => full}/pthread_test_014.cpp | 0 .../process/pthread/it_pthread_test.h | 4 +- .../process/pthread/process_pthread_test.cpp | 162 ++++---- .../pthread/smoke/pthread_cond_test_001.cpp | 2 +- .../pthread/smoke/pthread_cond_test_003.cpp | 151 ++++++++ .../pthread/smoke/pthread_cond_test_004.cpp | 143 +++++++ .../pthread/smoke/pthread_test_006.cpp | 2 + .../pthread/smoke/pthread_test_009.cpp | 4 - testsuites/unittest/sys/It_test_sys.h | 4 +- testsuites/unittest/sys/full/sys_test_018.cpp | 69 ++-- testsuites/unittest/sys/full/sys_test_019.cpp | 96 +++-- testsuites/unittest/sys/full/sys_test_020.cpp | 73 ++-- testsuites/unittest/sys/full/sys_test_021.cpp | 114 +++--- testsuites/unittest/sys/full/sys_test_022.cpp | 71 ++-- testsuites/unittest/sys/full/sys_test_023.cpp | 46 ++- testsuites/unittest/sys/full/sys_test_025.cpp | 60 ++- testsuites/unittest/sys/full/sys_test_028.cpp | 20 +- testsuites/unittest/sys/sys_unit_test.cpp | 10 +- zzz/git/push.sh | 2 +- 88 files changed, 1623 insertions(+), 887 deletions(-) create mode 100644 testsuites/unittest/IO/full/IO_test_pselect_002.cpp rename testsuites/unittest/process/process/{smoke => full}/process_test_007.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_031.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_032.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_033.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_034.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_035.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_036.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_037.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_040.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_041.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_042.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_049.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_050.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_051.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_052.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_056.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_057.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_058.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_059.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_060.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_063.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_064.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_065.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_066.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_067.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_068.cpp (100%) rename testsuites/unittest/process/process/{smoke => full}/process_test_069.cpp (100%) rename testsuites/unittest/process/process/{full => smoke}/process_test_054.cpp (100%) rename testsuites/unittest/process/process/{full => smoke}/process_test_061.cpp (100%) rename testsuites/unittest/process/pthread/{smoke => full}/pthread_test_001.cpp (100%) rename testsuites/unittest/process/pthread/{smoke => full}/pthread_test_002.cpp (100%) rename testsuites/unittest/process/pthread/{smoke => full}/pthread_test_004.cpp (99%) rename testsuites/unittest/process/pthread/{smoke => full}/pthread_test_005.cpp (100%) rename testsuites/unittest/process/pthread/{smoke => full}/pthread_test_014.cpp (100%) create mode 100644 testsuites/unittest/process/pthread/smoke/pthread_cond_test_003.cpp create mode 100644 testsuites/unittest/process/pthread/smoke/pthread_cond_test_004.cpp diff --git a/README.md b/README.md index 88a6f44d..fc9af3d0 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ 是在 `OpenHarmony` 的 [kernel_liteos_a](https://gitee.com/openharmony/kernel_liteos_a) 基础上给内核源码加上中文注解的版本.与官方源码按月保持同步,同步历史如下: + * `2021/11/02` -- 改动不大,对process,task模块进行了微调 * `2021/10/21` -- 增加性能优化模块`perf`,优化了文件映射模块 * `2021/09/14` -- common,extended等几个目录结构和Makefile调整 * `2021/08/19` -- 各目录增加了`BUILD.gn`文件,文件系统部分文件调整 @@ -75,7 +76,7 @@ [![](https://gitee.com/weharmonyos/resources/raw/master/73/4.png)](http://weharmonyos.com/doxygen/index.html) [![](https://gitee.com/weharmonyos/resources/raw/master/73/3.png)](http://weharmonyos.com/doxygen/index.html) -可前往 >> [鸿蒙研究站 | 源码文档版块 ](http://weharmonyos.com/doxygen/index.html) 搜索 **OsSchedStart** 体验 +可前往 >> [鸿蒙研究站 | 注解文档 ](http://weharmonyos.com/doxygen/index.html) 搜索 **OsSchedStart** 体验 ### 有哪些特殊的记号 - [x] 搜索 `@note_pic` 可查看绘制的全部字符图 - [x] 搜索 `@note_why` 是尚未看明白的地方,有看明白的,请Pull Request完善 @@ -135,7 +136,7 @@ ### 微信 | QQ 群 前往 >> [http://weharmonyos.com/qun.html](http://weharmonyos.com/qun.html) -### 捐赠记录,再次感谢!!! +### 捐赠记录,再次感谢 前往 >> [http://weharmonyos.com/donate.html](http://weharmonyos.com/donate.html) ### 百篇博客分析.深挖内核地基 @@ -144,83 +145,82 @@ 按时间顺序: -* [v01.12 鸿蒙内核源码分析(双向链表) | 谁是内核最重要结构体](https://my.oschina.net/weharmony/blog/4572304) -* [v02.06 鸿蒙内核源码分析(进程管理) | 谁在管理内核资源](https://my.oschina.net/weharmony/blog/4574429) -* [v03.06 鸿蒙内核源码分析(时钟任务) | 调度的源动力从哪来](https://my.oschina.net/weharmony/blog/4574493) -* [v04.03 鸿蒙内核源码分析(任务调度) | 内核调度的单元是谁](https://my.oschina.net/weharmony/blog/4595539) -* [v05.05 鸿蒙内核源码分析(任务管理) | 如何管理任务池](https://my.oschina.net/weharmony/blog/4603919) -* [v06.03 鸿蒙内核源码分析(调度队列) | 内核调度也需要排队](https://my.oschina.net/weharmony/blog/4606916) -* [v07.08 鸿蒙内核源码分析(调度机制) | 任务是如何被调度执行的](https://my.oschina.net/weharmony/blog/4623040) -* [v08.03 鸿蒙内核源码分析(总目录) | 百万汉字注解 百篇博客分析](https://my.oschina.net/weharmony/blog/4626852) -* [v09.04 鸿蒙内核源码分析(调度故事) | 用故事说内核调度](https://my.oschina.net/weharmony/blog/4634668) -* [v10.03 鸿蒙内核源码分析(内存主奴) | 皇上和奴才如何相处](https://my.oschina.net/weharmony/blog/4646802) -* [v11.03 鸿蒙内核源码分析(内存分配) | 内存有哪些分配方式](https://my.oschina.net/weharmony/blog/4646802) -* [v12.04 鸿蒙内核源码分析(内存管理) | 虚拟内存全景图是怎样的](https://my.oschina.net/weharmony/blog/4652284) -* [v13.05 鸿蒙内核源码分析(源码注释) | 每天死磕一点点](https://my.oschina.net/weharmony/blog/4686747) -* [v14.02 鸿蒙内核源码分析(内存汇编) | 谁是虚拟内存实现的基础](https://my.oschina.net/weharmony/blog/4692156) -* [v15.03 鸿蒙内核源码分析(内存映射) | 映射真是个好东西](https://my.oschina.net/weharmony/blog/4694841) -* [v16.02 鸿蒙内核源码分析(内存规则) | 内存管理到底在管什么](https://my.oschina.net/weharmony/blog/4698384) -* [v17.04 鸿蒙内核源码分析(物理内存) | 怎么管理物理内存](https://my.oschina.net/weharmony/blog/4842408) -* [v18.02 鸿蒙内核源码分析(源码结构) | 内核文件各自含义](https://my.oschina.net/weharmony/blog/4869137) -* [v19.04 鸿蒙内核源码分析(位图管理) | 特节俭的苦命孩子](https://my.oschina.net/weharmony/blog/4888467) -* [v20.03 鸿蒙内核源码分析(用栈方式) | 谁来提供程序运行场地](https://my.oschina.net/weharmony/blog/4893388) -* [v21.07 鸿蒙内核源码分析(线程概念) | 是谁在不断的折腾CPU](https://my.oschina.net/weharmony/blog/4915543) -* [v22.03 鸿蒙内核源码分析(汇编基础) | CPU上班也要打卡](https://my.oschina.net/weharmony/blog/4920361) -* [v23.04 鸿蒙内核源码分析(汇编传参) | 如何传递复杂的参数](https://my.oschina.net/weharmony/blog/4927892) -* [v24.03 鸿蒙内核源码分析(进程概念) | 如何更好的理解进程](https://my.oschina.net/weharmony/blog/4937521) -* [v25.05 鸿蒙内核源码分析(并发并行) | 听过无数遍的两个概念](https://my.oschina.net/weharmony/blog/4940329) -* [v26.08 鸿蒙内核源码分析(自旋锁) | 当立贞节牌坊的好同志](https://my.oschina.net/weharmony/blog/4944129) -* [v27.05 鸿蒙内核源码分析(互斥锁) | 同样是锁它确更丰满](https://my.oschina.net/weharmony/blog/4945465) -* [v28.04 鸿蒙内核源码分析(进程通讯) | 九种进程间通讯方式速揽](https://my.oschina.net/weharmony/blog/4947398) -* [v29.05 鸿蒙内核源码分析(信号量) | 谁在解决任务间的同步](https://my.oschina.net/weharmony/blog/4949720) -* [v30.07 鸿蒙内核源码分析(事件控制) | 多对多任务如何同步](https://my.oschina.net/weharmony/blog/4950956) -* [v31.02 鸿蒙内核源码分析(定时器) | 内核最高级任务竟是它](https://my.oschina.net/weharmony/blog/4951625) -* [v32.03 鸿蒙内核源码分析(CPU) | 整个内核是一个死循环](https://my.oschina.net/weharmony/blog/4952034) -* [v33.03 鸿蒙内核源码分析(消息队列) | 进程间如何异步传递大数据](https://my.oschina.net/weharmony/blog/4952961) -* [v34.04 鸿蒙内核源码分析(原子操作) | 谁在为完整性保驾护航](https://my.oschina.net/weharmony/blog/4955290) -* [v35.03 鸿蒙内核源码分析(时间管理) | 内核基本时间单位是谁](https://my.oschina.net/weharmony/blog/4956163) -* [v36.05 鸿蒙内核源码分析(工作模式) | 程序界的韦小宝是谁](https://my.oschina.net/weharmony/blog/4965052) -* [v37.06 鸿蒙内核源码分析(系统调用) | 开发者永远的口头禅](https://my.oschina.net/weharmony/blog/4967613) -* [v38.06 鸿蒙内核源码分析(寄存器) | 讲真 全宇宙只佩服它](https://my.oschina.net/weharmony/blog/4969487) -* [v39.06 鸿蒙内核源码分析(异常接管) | 社会很单纯 复杂的是人](https://my.oschina.net/weharmony/blog/4973016) -* [v40.03 鸿蒙内核源码分析(汇编汇总) | 汇编可爱如邻家女孩](https://my.oschina.net/weharmony/blog/4977924) -* [v41.03 鸿蒙内核源码分析(任务切换) | 看汇编如何切换任务](https://my.oschina.net/weharmony/blog/4988628) -* [v42.05 鸿蒙内核源码分析(中断切换) | 系统因中断活力四射](https://my.oschina.net/weharmony/blog/4990948) -* [v43.05 鸿蒙内核源码分析(中断概念) | 海公公的日常工作](https://my.oschina.net/weharmony/blog/4992750) -* [v44.04 鸿蒙内核源码分析(中断管理) | 没中断太可怕](https://my.oschina.net/weharmony/blog/4995800) -* [v45.05 鸿蒙内核源码分析(Fork) | 一次调用 两次返回](https://my.oschina.net/weharmony/blog/5010301) -* [v46.05 鸿蒙内核源码分析(特殊进程) | 老鼠生儿会打洞](https://my.oschina.net/weharmony/blog/5014444) -* [v47.02 鸿蒙内核源码分析(进程回收) | 临终托孤的短命娃](https://my.oschina.net/weharmony/blog/5017716) -* [v48.05 鸿蒙内核源码分析(信号生产) | 年过半百 活力十足](https://my.oschina.net/weharmony/blog/5022149) -* [v49.03 鸿蒙内核源码分析(信号消费) | 谁让CPU连续四次换栈运行](https://my.oschina.net/weharmony/blog/5027224) -* [v50.03 鸿蒙内核源码分析(编译环境) | 编译鸿蒙防掉坑指南](https://my.oschina.net/weharmony/blog/5028613) -* [v51.04 鸿蒙内核源码分析(ELF格式) | 应用程序入口并非main](https://my.oschina.net/weharmony/blog/5030288) -* [v52.05 鸿蒙内核源码分析(静态站点) | 码农都不爱写注释和文档](https://my.oschina.net/weharmony/blog/5042657) -* [v53.03 鸿蒙内核源码分析(ELF解析) | 敢忘了她姐俩你就不是银](https://my.oschina.net/weharmony/blog/5048746) -* [v54.04 鸿蒙内核源码分析(静态链接) | 一个小项目看中间过程](https://my.oschina.net/weharmony/blog/5049918) -* [v55.04 鸿蒙内核源码分析(重定位) | 与国际接轨的对外发言人](https://my.oschina.net/weharmony/blog/5055124) -* [v56.05 鸿蒙内核源码分析(进程映像) | 程序是如何被加载运行的](https://my.oschina.net/weharmony/blog/5060359) -* [v57.02 鸿蒙内核源码分析(编译过程) | 简单案例说透中间过程](https://my.oschina.net/weharmony/blog/5064209) -* [v58.03 鸿蒙内核源码分析(环境脚本) | 编译鸿蒙原来很简单](https://my.oschina.net/weharmony/blog/5132725) -* [v59.04 鸿蒙内核源码分析(构建工具) | 顺瓜摸藤调试构建过程](https://my.oschina.net/weharmony/blog/5135157) -* [v60.04 鸿蒙内核源码分析(gn应用) | 如何构建鸿蒙系统](https://my.oschina.net/weharmony/blog/5137565) -* [v61.03 鸿蒙内核源码分析(忍者ninja) | 忍者的特点就是一个字](https://my.oschina.net/weharmony/blog/5139034) -* [v62.02 鸿蒙内核源码分析(文件概念) | 为什么说一切皆是文件](https://my.oschina.net/weharmony/blog/5152858) -* [v63.04 鸿蒙内核源码分析(文件系统) | 用图书管理说文件系统](https://my.oschina.net/weharmony/blog/5165752) -* [v64.06 鸿蒙内核源码分析(索引节点) | 谁是文件系统最重要的概念](https://my.oschina.net/weharmony/blog/5168716) -* [v65.05 鸿蒙内核源码分析(挂载目录) | 为何文件系统需要挂载](https://my.oschina.net/weharmony/blog/5172566) -* [v66.07 鸿蒙内核源码分析(根文件系统) | 谁先挂到/谁就是根总](https://my.oschina.net/weharmony/blog/5177087) -* [v67.03 鸿蒙内核源码分析(字符设备) | 绝大多数设备都是这类](https://my.oschina.net/weharmony/blog/5200946) -* [v68.02 鸿蒙内核源码分析(VFS) | 文件系统是个大家庭](https://my.oschina.net/weharmony/blog/5211662) -* [v69.04 鸿蒙内核源码分析(文件句柄) | 你为什么叫句柄](https://my.oschina.net/weharmony/blog/5253251) -* [v70.05 鸿蒙内核源码分析(管道文件) | 如何降低数据流动成本](https://my.oschina.net/weharmony/blog/5258434) -* [v71.03 鸿蒙内核源码分析(Shell编辑) | 两个任务 三个阶段](https://my.oschina.net/weharmony/blog/5269307) -* [v72.01 鸿蒙内核源码分析(Shell解析) | 应用窥伺内核的窗口](https://my.oschina.net/weharmony/blog/5282207) -* [v73.01 鸿蒙内核源码分析(注释文档) | 鸿蒙所有函数调用关系图](https://my.oschina.net/weharmony/blog/5042657) +* [v01.12 鸿蒙内核源码分析(双向链表) | 谁是内核最重要结构体](http://weharmonyos.com/blog/01.html) +* [v02.06 鸿蒙内核源码分析(进程管理) | 谁在管理内核资源](http://weharmonyos.com/blog/02.html) +* [v03.06 鸿蒙内核源码分析(时钟任务) | 调度的源动力从哪来](http://weharmonyos.com/blog/03.html) +* [v04.03 鸿蒙内核源码分析(任务调度) | 内核调度的单元是谁](http://weharmonyos.com/blog/04.html) +* [v05.05 鸿蒙内核源码分析(任务管理) | 如何管理任务池](http://weharmonyos.com/blog/05.html) +* [v06.03 鸿蒙内核源码分析(调度队列) | 内核调度也需要排队](http://weharmonyos.com/blog/06.html) +* [v07.08 鸿蒙内核源码分析(调度机制) | 任务是如何被调度执行的](http://weharmonyos.com/blog/07.html) +* [v08.03 鸿蒙内核源码分析(总目录) | 百万汉字注解 百篇博客分析](http://weharmonyos.com/blog/08.html) +* [v09.04 鸿蒙内核源码分析(调度故事) | 用故事说内核调度](http://weharmonyos.com/blog/09.html) +* [v10.03 鸿蒙内核源码分析(内存主奴) | 皇上和奴才如何相处](http://weharmonyos.com/blog/10.html) +* [v11.03 鸿蒙内核源码分析(内存分配) | 内存有哪些分配方式](http://weharmonyos.com/blog/11.html) +* [v12.04 鸿蒙内核源码分析(内存管理) | 虚拟内存全景图是怎样的](http://weharmonyos.com/blog/12.html) +* [v13.05 鸿蒙内核源码分析(源码注释) | 每天死磕一点点](http://weharmonyos.com/blog/13.html) +* [v14.02 鸿蒙内核源码分析(内存汇编) | 谁是虚拟内存实现的基础](http://weharmonyos.com/blog/14.html) +* [v15.03 鸿蒙内核源码分析(内存映射) | 映射真是个好东西](http://weharmonyos.com/blog/15.html) +* [v16.02 鸿蒙内核源码分析(内存规则) | 内存管理到底在管什么](http://weharmonyos.com/blog/16.html) +* [v17.04 鸿蒙内核源码分析(物理内存) | 怎么管理物理内存](http://weharmonyos.com/blog/17.html) +* [v18.02 鸿蒙内核源码分析(源码结构) | 内核文件各自含义](http://weharmonyos.com/blog/18.html) +* [v19.04 鸿蒙内核源码分析(位图管理) | 特节俭的苦命孩子](http://weharmonyos.com/blog/19.html) +* [v20.03 鸿蒙内核源码分析(用栈方式) | 谁来提供程序运行场地](http://weharmonyos.com/blog/20.html) +* [v21.07 鸿蒙内核源码分析(线程概念) | 是谁在不断的折腾CPU](http://weharmonyos.com/blog/21.html) +* [v22.03 鸿蒙内核源码分析(汇编基础) | CPU上班也要打卡](http://weharmonyos.com/blog/22.html) +* [v23.04 鸿蒙内核源码分析(汇编传参) | 如何传递复杂的参数](http://weharmonyos.com/blog/23.html) +* [v24.03 鸿蒙内核源码分析(进程概念) | 如何更好的理解进程](http://weharmonyos.com/blog/24.html) +* [v25.05 鸿蒙内核源码分析(并发并行) | 听过无数遍的两个概念](http://weharmonyos.com/blog/25.html) +* [v26.08 鸿蒙内核源码分析(自旋锁) | 当立贞节牌坊的好同志](http://weharmonyos.com/blog/26.html) +* [v27.05 鸿蒙内核源码分析(互斥锁) | 同样是锁它确更丰满](http://weharmonyos.com/blog/27.html) +* [v28.04 鸿蒙内核源码分析(进程通讯) | 九种进程间通讯方式速揽](http://weharmonyos.com/blog/28.html) +* [v29.05 鸿蒙内核源码分析(信号量) | 谁在解决任务间的同步](http://weharmonyos.com/blog/29.html) +* [v30.07 鸿蒙内核源码分析(事件控制) | 多对多任务如何同步](http://weharmonyos.com/blog/30.html) +* [v31.02 鸿蒙内核源码分析(定时器) | 内核最高级任务竟是它](http://weharmonyos.com/blog/31.html) +* [v32.03 鸿蒙内核源码分析(CPU) | 整个内核是一个死循环](http://weharmonyos.com/blog/32.html) +* [v33.03 鸿蒙内核源码分析(消息队列) | 进程间如何异步传递大数据](http://weharmonyos.com/blog/33.html) +* [v34.04 鸿蒙内核源码分析(原子操作) | 谁在为完整性保驾护航](http://weharmonyos.com/blog/34.html) +* [v35.03 鸿蒙内核源码分析(时间管理) | 内核基本时间单位是谁](http://weharmonyos.com/blog/35.html) +* [v36.05 鸿蒙内核源码分析(工作模式) | 程序界的韦小宝是谁](http://weharmonyos.com/blog/36.html) +* [v37.06 鸿蒙内核源码分析(系统调用) | 开发者永远的口头禅](http://weharmonyos.com/blog/37.html) +* [v38.06 鸿蒙内核源码分析(寄存器) | 讲真 全宇宙只佩服它](http://weharmonyos.com/blog/38.html) +* [v39.06 鸿蒙内核源码分析(异常接管) | 社会很单纯 复杂的是人](http://weharmonyos.com/blog/39.html) +* [v40.03 鸿蒙内核源码分析(汇编汇总) | 汇编可爱如邻家女孩](http://weharmonyos.com/blog/40.html) +* [v41.03 鸿蒙内核源码分析(任务切换) | 看汇编如何切换任务](http://weharmonyos.com/blog/41.html) +* [v42.05 鸿蒙内核源码分析(中断切换) | 系统因中断活力四射](http://weharmonyos.com/blog/42.html) +* [v43.05 鸿蒙内核源码分析(中断概念) | 海公公的日常工作](http://weharmonyos.com/blog/43.html) +* [v44.04 鸿蒙内核源码分析(中断管理) | 没中断太可怕](http://weharmonyos.com/blog/44.html) +* [v45.05 鸿蒙内核源码分析(Fork) | 一次调用 两次返回](http://weharmonyos.com/blog/45.html) +* [v46.05 鸿蒙内核源码分析(特殊进程) | 老鼠生儿会打洞](http://weharmonyos.com/blog/46.html) +* [v47.02 鸿蒙内核源码分析(进程回收) | 临终托孤的短命娃](http://weharmonyos.com/blog/47.html) +* [v48.05 鸿蒙内核源码分析(信号生产) | 年过半百 活力十足](http://weharmonyos.com/blog/48.html) +* [v49.03 鸿蒙内核源码分析(信号消费) | 谁让CPU连续四次换栈运行](http://weharmonyos.com/blog/49.html) +* [v50.03 鸿蒙内核源码分析(编译环境) | 编译鸿蒙防掉坑指南](http://weharmonyos.com/blog/50.html) +* [v51.04 鸿蒙内核源码分析(ELF格式) | 应用程序入口并非main](http://weharmonyos.com/blog/51.html) +* [v52.05 鸿蒙内核源码分析(静态站点) | 码农都不爱写注释和文档](http://weharmonyos.com/blog/52.html) +* [v53.03 鸿蒙内核源码分析(ELF解析) | 敢忘了她姐俩你就不是银](http://weharmonyos.com/blog/53.html) +* [v54.04 鸿蒙内核源码分析(静态链接) | 一个小项目看中间过程](http://weharmonyos.com/blog/54.html) +* [v55.04 鸿蒙内核源码分析(重定位) | 与国际接轨的对外发言人](http://weharmonyos.com/blog/55.html) +* [v56.05 鸿蒙内核源码分析(进程映像) | 程序是如何被加载运行的](http://weharmonyos.com/blog/56.html) +* [v57.02 鸿蒙内核源码分析(编译过程) | 简单案例说透中间过程](http://weharmonyos.com/blog/57.html) +* [v58.03 鸿蒙内核源码分析(环境脚本) | 编译鸿蒙原来很简单](http://weharmonyos.com/blog/58.html) +* [v59.04 鸿蒙内核源码分析(构建工具) | 顺瓜摸藤调试构建过程](http://weharmonyos.com/blog/59.html) +* [v60.04 鸿蒙内核源码分析(gn应用) | 如何构建鸿蒙系统](http://weharmonyos.comhttp://weharmonyos/blog/60.html) +* [v61.03 鸿蒙内核源码分析(忍者ninja) | 忍者的特点就是一个字](http://weharmonyos.comhttp://weharmonyos/blog/61.html) +* [v62.02 鸿蒙内核源码分析(文件概念) | 为什么说一切皆是文件](http://weharmonyos.com/blog/62.html) +* [v63.04 鸿蒙内核源码分析(文件系统) | 用图书管理说文件系统](http://weharmonyos.com/blog/63.html) +* [v64.06 鸿蒙内核源码分析(索引节点) | 谁是文件系统最重要的概念](http://weharmonyos.com/blog/64.html) +* [v65.05 鸿蒙内核源码分析(挂载目录) | 为何文件系统需要挂载](http://weharmonyos.com/blog/65.html) +* [v66.07 鸿蒙内核源码分析(根文件系统) | 谁先挂到/谁就是根总](http://weharmonyos.com/blog/66.html) +* [v67.03 鸿蒙内核源码分析(字符设备) | 绝大多数设备都是这类](http://weharmonyos.com/blog/67.html) +* [v68.02 鸿蒙内核源码分析(VFS) | 文件系统是个大家庭](http://weharmonyos.com/blog/68.html) +* [v69.04 鸿蒙内核源码分析(文件句柄) | 你为什么叫句柄](http://weharmonyos.com/blog/69.html) +* [v70.05 鸿蒙内核源码分析(管道文件) | 如何降低数据流动成本](http://weharmonyos.com/blog/70.html) +* [v71.03 鸿蒙内核源码分析(Shell编辑) | 两个任务 三个阶段](http://weharmonyos.com/blog/71.html) +* [v72.01 鸿蒙内核源码分析(Shell解析) | 应用窥伺内核的窗口](http://weharmonyos.com/blog/72.html) +* [v73.01 鸿蒙内核源码分析(注释文档) | 内核所有函数调用关系图](http://weharmonyos.com/blog/73.html) ### 关注不迷路.代码即人生 ![](https://gitee.com/weharmonyos/resources/raw/master/common/so1so.png) - **QQ群 790015635 | 入群密码 666** diff --git a/apps/config.mk b/apps/config.mk index 3668875b..51e9e219 100644 --- a/apps/config.mk +++ b/apps/config.mk @@ -30,7 +30,7 @@ include $(LITEOSTOPDIR)/config.mk # common flags config -BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE +BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_XOPEN_SOURCE=700 ASFLAGS := CFLAGS := $(LITEOS_COPTS) $(BASE_OPTS) -fPIE diff --git a/apps/shell/builtin/cd.c b/apps/shell/builtin/cd.c index 172eae82..83a051a0 100644 --- a/apps/shell/builtin/cd.c +++ b/apps/shell/builtin/cd.c @@ -29,9 +29,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _GNU_SOURCE #define _GNU_SOURCE -#endif #include "unistd.h" #include "shcmd.h" diff --git a/apps/shell/include/shcmd.h b/apps/shell/include/shcmd.h index b83784ba..57eb1008 100644 --- a/apps/shell/include/shcmd.h +++ b/apps/shell/include/shcmd.h @@ -53,7 +53,7 @@ typedef struct { } CmdKeyLink; #define NEED_NEW_LINE(timesPrint, lineCap) ((timesPrint) % (lineCap) == 0) -SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGNT)) +#define SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGNT)) extern unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr); extern unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size); diff --git a/apps/shell/src/main.c b/apps/shell/src/main.c index 8ba752c4..5c20cdab 100644 --- a/apps/shell/src/main.c +++ b/apps/shell/src/main.c @@ -29,6 +29,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE + #include "show.h" #include "shmsg.h" #include "shcmd.h" diff --git a/apps/shell/src/shmsg.c b/apps/shell/src/shmsg.c index 7c685c24..7fbc6953 100644 --- a/apps/shell/src/shmsg.c +++ b/apps/shell/src/shmsg.c @@ -29,6 +29,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE + #include "stdlib.h" #include "stdio.h" #include "unistd.h" diff --git a/compat/posix/src/misc.c b/compat/posix/src/misc.c index aa4b465f..9ed26de5 100644 --- a/compat/posix/src/misc.c +++ b/compat/posix/src/misc.c @@ -40,6 +40,7 @@ #include "los_process_pri.h" #include "los_hw.h" +static struct rlimit g_defaultLimit = { 0 }; /* * Supply some suitable values for constants that may not be present * in all configurations. @@ -154,7 +155,9 @@ pid_t getpid(void) int getrlimit(int resource, struct rlimit *rlim) { + unsigned int intSave; LosProcessCB *pcb = OsCurrProcessGet(); + struct rlimit *resourceLimit = pcb->resourceLimit; switch (resource) { case RLIMIT_NOFILE: @@ -163,8 +166,15 @@ int getrlimit(int resource, struct rlimit *rlim) default: return -EINVAL; } - rlim->rlim_cur = pcb->pl_rlimit[resource].rlim_cur; - rlim->rlim_max = pcb->pl_rlimit[resource].rlim_max; + + if (resourceLimit == NULL) { + resourceLimit = &g_defaultLimit; + } + + SCHEDULER_LOCK(intSave); + rlim->rlim_cur = resourceLimit[resource].rlim_cur; + rlim->rlim_max = resourceLimit[resource].rlim_max; + SCHEDULER_UNLOCK(intSave); return 0; } @@ -175,6 +185,8 @@ int getrlimit(int resource, struct rlimit *rlim) #endif int setrlimit(int resource, const struct rlimit *rlim) { + unsigned int intSave; + struct rlimit *resourceLimit = NULL; LosProcessCB *pcb = OsCurrProcessGet(); if (rlim->rlim_cur > rlim->rlim_max) { @@ -194,8 +206,23 @@ int setrlimit(int resource, const struct rlimit *rlim) default: return -EINVAL; } - pcb->pl_rlimit[resource].rlim_cur = rlim->rlim_cur; - pcb->pl_rlimit[resource].rlim_max = rlim->rlim_max; + if (pcb->resourceLimit == NULL) { + resourceLimit = LOS_MemAlloc((VOID *)m_aucSysMem0, RLIM_NLIMITS * sizeof(struct rlimit)); + if (resourceLimit == NULL) { + return -EINVAL; + } + } + + SCHEDULER_LOCK(intSave); + if (pcb->resourceLimit == NULL) { + pcb->resourceLimit = resourceLimit; + resourceLimit = NULL; + } + pcb->resourceLimit[resource].rlim_cur = rlim->rlim_cur; + pcb->resourceLimit[resource].rlim_max = rlim->rlim_max; + SCHEDULER_UNLOCK(intSave); + + (VOID)LOS_MemFree((VOID *)m_aucSysMem0, resourceLimit); return 0; } diff --git a/compat/posix/src/pthread.c b/compat/posix/src/pthread.c index d51ae288..acdfbb17 100644 --- a/compat/posix/src/pthread.c +++ b/compat/posix/src/pthread.c @@ -249,7 +249,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, taskInitParam.uwResved = LOS_TASK_STATUS_DETACHED; } else { /* Set the pthread default joinable */ - taskInitParam.uwResved = 0; + taskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE; } PthreadReap(); diff --git a/kernel/base/core/los_process.c b/kernel/base/core/los_process.c index 9924c36a..dc8e1b78 100644 --- a/kernel/base/core/los_process.c +++ b/kernel/base/core/los_process.c @@ -435,10 +435,15 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB) #ifdef LOSCFG_KERNEL_LITEIPC if (OsProcessIsUserMode(processCB)) {//当为用户进程 - LiteIpcPoolDelete(&(processCB->ipcInfo));//删除进程对lite IPC的开销 + LiteIpcPoolDelete(&(processCB->ipcInfo), processCB->processID); (VOID)memset_s(&(processCB->ipcInfo), sizeof(ProcIpcInfo), 0, sizeof(ProcIpcInfo)); } #endif + + if (processCB->resourceLimit != NULL) { + (VOID)LOS_MemFree((VOID *)m_aucSysMem0, processCB->resourceLimit); + processCB->resourceLimit = NULL; + } } //回收僵死状态进程的资源 LITE_OS_SEC_TEXT STATIC VOID OsRecycleZombiesProcess(LosProcessCB *childCB, ProcessGroup **group) @@ -1738,9 +1743,7 @@ STATIC VOID OsInitCopyTaskParam(LosProcessCB *childProcessCB, const CHAR *name, childPara->usTaskPrio = mainThread->priority; //优先级 childPara->processID = childProcessCB->processID; //进程ID if (mainThread->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) { - childPara->uwResved = OS_TASK_FLAG_PTHREAD_JOIN; - } else if (mainThread->taskStatus & OS_TASK_FLAG_DETACHED) { - childPara->uwResved = OS_TASK_FLAG_DETACHED; + childPara->uwResved = LOS_TASK_ATTR_JOINABLE; } SCHEDULER_UNLOCK(intSave); diff --git a/kernel/base/core/los_task.c b/kernel/base/core/los_task.c index 362873b3..4ba28720 100644 --- a/kernel/base/core/los_task.c +++ b/kernel/base/core/los_task.c @@ -210,7 +210,6 @@ LITE_OS_SEC_TEXT_INIT VOID OsTaskJoinPostUnsafe(LosTaskCB *taskCB) OsTaskWakeClearPendMask(resumedTask); OsSchedTaskWake(resumedTask); } - taskCB->taskStatus &= ~OS_TASK_FLAG_PTHREAD_JOIN;//去掉JOIN标签 } taskCB->taskStatus |= OS_TASK_STATUS_EXIT;//贴上任务退出标签 } @@ -226,11 +225,13 @@ LITE_OS_SEC_TEXT UINT32 OsTaskJoinPendUnsafe(LosTaskCB *taskCB) return LOS_EINVAL; } + if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) { + return LOS_OK; + } + if ((taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) && LOS_ListEmpty(&taskCB->joinList)) { OsTaskWaitSetPendMask(OS_TASK_WAIT_JOIN, taskCB->taskID, LOS_WAIT_FOREVER); return OsSchedTaskWait(&taskCB->joinList, LOS_WAIT_FOREVER, TRUE); - } else if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) { - return LOS_OK; } return LOS_EINVAL; @@ -247,7 +248,6 @@ LITE_OS_SEC_TEXT UINT32 OsTaskSetDetachUnsafe(LosTaskCB *taskCB) if (LOS_ListEmpty(&(taskCB->joinList))) {//joinlist中没有数据了 LOS_ListDelete(&(taskCB->joinList));//所谓删除就是自己指向自己 taskCB->taskStatus &= ~OS_TASK_FLAG_PTHREAD_JOIN;//去掉JOIN标签 - taskCB->taskStatus |= OS_TASK_FLAG_DETACHED;//贴上分离标签,自己独立存在,不和其他任务媾和,不能被别的任务回收和干掉,只能由系统回收 return LOS_OK; } /* This error code has a special purpose and is not allowed to appear again on the interface */ @@ -338,6 +338,88 @@ LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)//获取当前任务的ID return runTask->taskID; } +STATIC INLINE UINT32 OsTaskSyncCreate(LosTaskCB *taskCB) +{ +#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC + UINT32 ret = LOS_SemCreate(0, &taskCB->syncSignal); + if (ret != LOS_OK) { + return LOS_ERRNO_TSK_MP_SYNC_RESOURCE; + } +#else + (VOID)taskCB; +#endif + return LOS_OK; +} + +STATIC INLINE VOID OsTaskSyncDestroy(UINT32 syncSignal) +{ +#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC + (VOID)LOS_SemDelete(syncSignal); +#else + (VOID)syncSignal; +#endif +} + +#ifdef LOSCFG_KERNEL_SMP +STATIC INLINE UINT32 OsTaskSyncWait(const LosTaskCB *taskCB) +{ +#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC + UINT32 ret = LOS_OK; + + LOS_ASSERT(LOS_SpinHeld(&g_taskSpin)); + LOS_SpinUnlock(&g_taskSpin); + /* + * gc soft timer works every OS_MP_GC_PERIOD period, to prevent this timer + * triggered right at the timeout has reached, we set the timeout as double + * of the gc peroid. + */ + if (LOS_SemPend(taskCB->syncSignal, OS_MP_GC_PERIOD * 2) != LOS_OK) { + ret = LOS_ERRNO_TSK_MP_SYNC_FAILED; + } + + LOS_SpinLock(&g_taskSpin); + + return ret; +#else + (VOID)taskCB; + return LOS_OK; +#endif +} +#endif + +STATIC INLINE VOID OsTaskSyncWake(const LosTaskCB *taskCB) +{ +#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC + (VOID)OsSemPostUnsafe(taskCB->syncSignal, NULL); +#else + (VOID)taskCB; +#endif +} + +STATIC VOID OsTaskReleaseHoldLock(LosProcessCB *processCB, LosTaskCB *taskCB) +{ + LosMux *mux = NULL; + UINT32 ret; + + while (!LOS_ListEmpty(&taskCB->lockList)) { + mux = LOS_DL_LIST_ENTRY(LOS_DL_LIST_FIRST(&taskCB->lockList), LosMux, holdList); + ret = OsMuxUnlockUnsafe(taskCB, mux, NULL); + if (ret != LOS_OK) { + LOS_ListDelete(&mux->holdList); + PRINT_ERR("mux ulock failed! : %u\n", ret); + } + } + +#ifdef LOSCFG_KERNEL_VM + if (processCB->processMode == OS_USER_MODE) { + OsFutexNodeDeleteFromFutexHash(&taskCB->futex, TRUE, NULL, NULL); + } +#endif + + OsTaskJoinPostUnsafe(taskCB); + + OsTaskSyncWake(taskCB); +} //一个任务的退出过程 LITE_OS_SEC_TEXT VOID OsTaskToExit(LosTaskCB *taskCB, UINT32 status) { @@ -356,14 +438,14 @@ LITE_OS_SEC_TEXT VOID OsTaskToExit(LosTaskCB *taskCB, UINT32 status) return; } - /* The thread being killed must be able to exit automatically and will have the detached property */ - OsTaskJoinPostUnsafe(taskCB); - - if (taskCB->taskStatus & (OS_TASK_FLAG_DETACHED | OS_TASK_FLAG_EXIT_KILL)) { + if ((taskCB->taskStatus & OS_TASK_FLAG_EXIT_KILL) || !(taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN)) { UINT32 ret = OsTaskDeleteUnsafe(taskCB, status, intSave); LOS_Panic("Task delete failed! ERROR : 0x%x\n", ret); + return; } + OsTaskReleaseHoldLock(runProcess, taskCB); + OsSchedResched();//申请调度 SCHEDULER_UNLOCK(intSave); return; @@ -390,7 +472,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskID) taskCB = OS_TCB_FROM_TID(taskID); taskCB->joinRetval = taskCB->taskEntry(taskCB->args[0], taskCB->args[1],//调用任务的入口函数 taskCB->args[2], taskCB->args[3]); /* 2 & 3: just for args array index */ - if (taskCB->taskStatus & OS_TASK_FLAG_DETACHED) {//task有分离标签时 + if (!(taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN)) { taskCB->joinRetval = 0;//结合数为0 } @@ -451,67 +533,7 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskStackAlloc(VOID **topStack, UINT32 stack { *topStack = (VOID *)LOS_MemAllocAlign(pool, stackSize, LOSCFG_STACK_POINT_ALIGN_SIZE); } -//创建任务同步信号 -STATIC INLINE UINT32 OsTaskSyncCreate(LosTaskCB *taskCB) -{ -#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC - UINT32 ret = LOS_SemCreate(0, &taskCB->syncSignal);//创建一个syncSignal信号量 - if (ret != LOS_OK) { - return LOS_ERRNO_TSK_MP_SYNC_RESOURCE; - } -#else - (VOID)taskCB; -#endif - return LOS_OK; -} -//删除任务同步信号 -STATIC INLINE VOID OsTaskSyncDestroy(UINT32 syncSignal) -{ -#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC - (VOID)LOS_SemDelete(syncSignal); -#else - (VOID)syncSignal; -#endif -} -/****************************************** -等待任务的同步信号量, -A --发送syncSignal-- > B -B --回一个syncSignal-- > A -如此A就知道B此时还在 -*******************************************/ -LITE_OS_SEC_TEXT UINT32 OsTaskSyncWait(const LosTaskCB *taskCB) -{ -#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC - UINT32 ret = LOS_OK; - - LOS_ASSERT(LOS_SpinHeld(&g_taskSpin)); - LOS_SpinUnlock(&g_taskSpin); - /* - * gc soft timer works every OS_MP_GC_PERIOD period, to prevent this timer - * triggered right at the timeout has reached, we set the timeout as double - * of the gc peroid. - */ - if (LOS_SemPend(taskCB->syncSignal, OS_MP_GC_PERIOD * 2) != LOS_OK) {//发送同步信号量 - ret = LOS_ERRNO_TSK_MP_SYNC_FAILED; - } - - LOS_SpinLock(&g_taskSpin); - return ret; -#else - (VOID)taskCB; - return LOS_OK; -#endif -} -//任务同步唤醒 -STATIC INLINE VOID OsTaskSyncWake(const LosTaskCB *taskCB) -{ -#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC - (VOID)OsSemPostUnsafe(taskCB->syncSignal, NULL);//唤醒一个挂在信号量链表上的阻塞任务 -#else - (VOID)taskCB; -#endif -} //释放任务内核资源 STATIC VOID OsTaskKernelResourcesToFree(UINT32 syncSignal, UINTPTR topOfStack) { @@ -611,11 +633,9 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB, LOS_ListInit(&(taskCB->msgListHead));//初始化 liteipc的消息链表 #endif taskCB->policy = (initParam->policy == LOS_SCHED_FIFO) ? LOS_SCHED_FIFO : LOS_SCHED_RR;//调度模式 - taskCB->taskStatus = OS_TASK_STATUS_INIT;//任务初始状态 - if (initParam->uwResved & OS_TASK_FLAG_DETACHED) {//分离模式 代表任务与其他任务的关系 - taskCB->taskStatus |= OS_TASK_FLAG_DETACHED;//任务状态贴上分离标签 - } else {//参与模式 - taskCB->taskStatus |= OS_TASK_FLAG_PTHREAD_JOIN;//任务状态贴上联合标签 + taskCB->taskStatus = OS_TASK_STATUS_INIT; + if (initParam->uwResved & LOS_TASK_ATTR_JOINABLE) { + taskCB->taskStatus |= OS_TASK_FLAG_PTHREAD_JOIN; LOS_ListInit(&taskCB->joinList); } @@ -769,10 +789,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *in } else { initParam->processID = OsCurrProcessGet()->processID; } - initParam->uwResved &= ~OS_TASK_FLAG_PTHREAD_JOIN; - if (initParam->uwResved & LOS_TASK_STATUS_DETACHED) { - initParam->uwResved = OS_TASK_FLAG_DETACHED; - } ret = LOS_TaskCreateOnly(taskID, initParam); if (ret != LOS_OK) { @@ -938,30 +954,7 @@ STATIC INLINE VOID OsTaskStatusUnusedSet(LosTaskCB *taskCB) OS_MEM_CLEAR(taskCB->taskID); } -//task释放持有的所有锁,一个任务可以持有很多把锁 -STATIC INLINE VOID OsTaskReleaseHoldLock(LosProcessCB *processCB, LosTaskCB *taskCB) -{ - LosMux *mux = NULL; - UINT32 ret; - - while (!LOS_ListEmpty(&taskCB->lockList)) {//轮询任务锁链表 - mux = LOS_DL_LIST_ENTRY(LOS_DL_LIST_FIRST(&taskCB->lockList), LosMux, holdList);//取出第一个互斥锁 - ret = OsMuxUnlockUnsafe(taskCB, mux, NULL);//还锁 - if (ret != LOS_OK) {//换锁成功 - LOS_ListDelete(&mux->holdList);//从锁链表中将自己摘除 - PRINT_ERR("mux ulock failed! : %u\n", ret); - } - } - - if (processCB->processMode == OS_USER_MODE) {//如果是用户模式,会怎样? - OsTaskJoinPostUnsafe(taskCB);//把taskCB绑在一起的其他task唤醒. -#ifdef LOSCFG_KERNEL_VM - OsFutexNodeDeleteFromFutexHash(&taskCB->futex, TRUE, NULL, NULL); -#endif - } - OsTaskSyncWake(taskCB);//同步唤醒任务 -} //删除一个正在运行的任务 LITE_OS_SEC_TEXT VOID OsRunTaskToDelete(LosTaskCB *runTask) { @@ -1724,6 +1717,104 @@ LITE_OS_SEC_TEXT INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16 return LOS_OK; } +STATIC UINT32 OsTaskJoinCheck(UINT32 taskID) +{ + if (OS_TID_CHECK_INVALID(taskID)) { + return LOS_EINVAL; + } + + if (OS_INT_ACTIVE) { + return LOS_EINTR; + } + + if (!OsPreemptable()) { + return LOS_EINVAL; + } + + if (taskID == OsCurrTaskGet()->taskID) { + return LOS_EDEADLK; + } + return LOS_OK; +} + +UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval) +{ + UINT32 intSave; + LosTaskCB *runTask = OsCurrTaskGet(); + LosTaskCB *taskCB = NULL; + UINT32 errRet; + + errRet = OsTaskJoinCheck(taskID); + if (errRet != LOS_OK) { + return errRet; + } + + taskCB = OS_TCB_FROM_TID(taskID); + SCHEDULER_LOCK(intSave); + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { + SCHEDULER_UNLOCK(intSave); + return LOS_EINVAL; + } + + if (runTask->processID != taskCB->processID) { + SCHEDULER_UNLOCK(intSave); + return LOS_EPERM; + } + + errRet = OsTaskJoinPendUnsafe(taskCB); + SCHEDULER_UNLOCK(intSave); + + if (errRet == LOS_OK) { + LOS_Schedule(); + + if (retval != NULL) { + *retval = (UINTPTR)taskCB->joinRetval; + } + + (VOID)LOS_TaskDelete(taskID); + return LOS_OK; + } + + return errRet; +} + +UINT32 LOS_TaskDetach(UINT32 taskID) +{ + UINT32 intSave; + LosTaskCB *runTask = OsCurrTaskGet(); + LosTaskCB *taskCB = NULL; + UINT32 errRet; + + if (OS_TID_CHECK_INVALID(taskID)) { + return LOS_EINVAL; + } + + if (OS_INT_ACTIVE) { + return LOS_EINTR; + } + + taskCB = OS_TCB_FROM_TID(taskID); + SCHEDULER_LOCK(intSave); + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { + SCHEDULER_UNLOCK(intSave); + return LOS_EINVAL; + } + + if (runTask->processID != taskCB->processID) { + SCHEDULER_UNLOCK(intSave); + return LOS_EPERM; + } + + if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) { + SCHEDULER_UNLOCK(intSave); + return LOS_TaskJoin(taskID, NULL); + } + + errRet = OsTaskSetDetachUnsafe(taskCB); + SCHEDULER_UNLOCK(intSave); + return errRet; +} + LITE_OS_SEC_TEXT UINT32 LOS_GetSystemTaskMaximum(VOID) { return g_taskMaxNum; diff --git a/kernel/base/include/los_process_pri.h b/kernel/base/include/los_process_pri.h index f32106f8..1856b7cc 100644 --- a/kernel/base/include/los_process_pri.h +++ b/kernel/base/include/los_process_pri.h @@ -127,7 +127,7 @@ typedef struct ProcessCB { #ifdef LOSCFG_KERNEL_CPUP OsCpupBase processCpup; /**< Process cpu usage \n 进程占用CPU情况统计*/ #endif - struct rlimit pl_rlimit[RLIM_NLIMITS]; + struct rlimit *resourceLimit; } LosProcessCB; #define CLONE_VM 0x00000100 ///< 子进程与父进程运行于相同的内存空间 diff --git a/kernel/base/include/los_task_pri.h b/kernel/base/include/los_task_pri.h index 92b0b5b6..41d45a3d 100644 --- a/kernel/base/include/los_task_pri.h +++ b/kernel/base/include/los_task_pri.h @@ -183,15 +183,7 @@ extern SPIN_LOCK_S g_taskSpin;//任务自旋锁 * The task is joinable. */ #define OS_TASK_FLAG_PTHREAD_JOIN 0x0400U //主task和子task连在一块不分离 -//一个可结合的线程能够被其他线程收回其资源和杀死。在被其他线程回收之前,它的存储器资源(例如栈)是不释放的。 -/** - * @ingroup los_task - * Flag that indicates the task or task control block status. - * - * The task is status detached. - */ -#define OS_TASK_FLAG_DETACHED 0x0800U //任务分离 主task与子task分离,子task结束后,资源自动回收 -//一个分离的线程是不能被其他线程回收或杀死的,它的存储器资源在它终止时由系统自动释放。 + /** * @ingroup los_task * Flag that indicates the task property. @@ -364,7 +356,6 @@ typedef struct { UINT16 waitFlag; /**< The type of child process that is waiting, belonging to a group or parent, a specific child process, or any child process \n 以什么样的方式等待子进程结束(OS_TASK_WAIT_PROCESS | OS_TASK_WAIT_GID | ..) */ #ifdef LOSCFG_KERNEL_LITEIPC - UINT32 ipcStatus; ///< IPC状态 LOS_DL_LIST msgListHead; ///< 消息队列头结点,上面挂的都是任务要读的消息 BOOL accessMap[LOSCFG_BASE_CORE_TSK_LIMIT];///< 访问图,指的是task之间是否能访问的标识,LOSCFG_BASE_CORE_TSK_LIMIT 为任务池总数 #endif @@ -533,7 +524,6 @@ extern VOID OsTaskProcSignal(VOID); extern UINT32 OsTaskDeleteUnsafe(LosTaskCB *taskCB, UINT32 status, UINT32 intSave); extern VOID OsTaskResourcesToFree(LosTaskCB *taskCB); extern VOID OsRunTaskToDelete(LosTaskCB *taskCB); -extern UINT32 OsTaskSyncWait(const LosTaskCB *taskCB); extern UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam); extern INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName); extern VOID OsTaskCBRecycleToFree(VOID); diff --git a/kernel/base/ipc/los_signal.c b/kernel/base/ipc/los_signal.c index 32a9a938..81a3abee 100644 --- a/kernel/base/ipc/los_signal.c +++ b/kernel/base/ipc/los_signal.c @@ -75,37 +75,44 @@ STATIC VOID OsMoveTmpInfoToUnbInfo(sig_cb *sigcb, INT32 signo) { SigInfoListNode *tmpInfoNode = sigcb->tmpInfoListHead; SigInfoListNode **prevHook = &sigcb->tmpInfoListHead; - INT32 isFirstDel = 1; while (tmpInfoNode != NULL) { if (tmpInfoNode->info.si_signo == signo) { - /* In some case, many siginfos have same signo, only last one inserted list need copy to unbinfo. */ - if (isFirstDel) { - /* copy tmpinfo to unbinfo. */ - (VOID)memcpy_s(&sigcb->sigunbinfo, sizeof(siginfo_t), &tmpInfoNode->info, sizeof(siginfo_t)); - isFirstDel = 0; - } - /* delete tmpinfo from tmpList. */ + /* copy tmpinfo to unbinfo. */ + (VOID)memcpy_s(&sigcb->sigunbinfo, sizeof(siginfo_t), &tmpInfoNode->info, sizeof(siginfo_t)); + /* delete tmpinfo from tmpList. */ *prevHook = tmpInfoNode->next; (VOID)LOS_MemFree(m_aucSysMem0, tmpInfoNode); tmpInfoNode = *prevHook; - continue; + break; } prevHook = &tmpInfoNode->next; tmpInfoNode = tmpInfoNode->next; } - - return; } STATIC INT32 OsAddSigInfoToTmpList(sig_cb *sigcb, siginfo_t *info) { - SigInfoListNode *tmp = (SigInfoListNode *)LOS_MemAlloc(m_aucSysMem0, sizeof(SigInfoListNode)); + /* try to find the old siginfo */ + SigInfoListNode *tmp = sigcb->tmpInfoListHead; + while (tmp != NULL) { + if (tmp->info.si_signo == info->si_signo) { + /* found it, break. */ + break; + } + tmp = tmp->next; + } + if (tmp == NULL) { - return LOS_NOK; + /* none, alloc new one */ + tmp = (SigInfoListNode *)LOS_MemAlloc(m_aucSysMem0, sizeof(SigInfoListNode)); + if (tmp == NULL) { + return LOS_NOK; + } + tmp->next = sigcb->tmpInfoListHead; + sigcb->tmpInfoListHead = tmp; } + (VOID)memcpy_s(&tmp->info, sizeof(siginfo_t), info, sizeof(siginfo_t)); - tmp->next = sigcb->tmpInfoListHead; - sigcb->tmpInfoListHead = tmp; return LOS_OK; } @@ -153,13 +160,10 @@ STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo) case OS_TASK_WAIT_SIGNAL: OsSigWaitTaskWake(taskCB, signo); break; -#ifdef LOSCFG_KERNEL_LITEIPC case OS_TASK_WAIT_LITEIPC: - taskCB->ipcStatus &= ~IPC_THREAD_STATUS_PEND; OsTaskWakeClearPendMask(taskCB); OsSchedTaskWake(taskCB); break; -#endif case OS_TASK_WAIT_FUTEX: OsFutexNodeDeleteFromFutexHash(&taskCB->futex, TRUE, NULL, NULL); OsTaskWakeClearPendMask(taskCB); diff --git a/kernel/base/sched/sched_sq/los_sched.c b/kernel/base/sched/sched_sq/los_sched.c index aaa69d05..b146c96f 100644 --- a/kernel/base/sched/sched_sq/los_sched.c +++ b/kernel/base/sched/sched_sq/los_sched.c @@ -475,9 +475,6 @@ STATIC INLINE VOID OsSchedWakePendTimeTask(UINT64 currTime, LosTaskCB *taskCB, B if (tempStatus & (OS_TASK_STATUS_PENDING | OS_TASK_STATUS_DELAY)) { taskCB->taskStatus &= ~(OS_TASK_STATUS_PENDING | OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY); if (tempStatus & OS_TASK_STATUS_PENDING) { -#ifdef LOSCFG_KERNEL_LITEIPC - taskCB->ipcStatus &= ~IPC_THREAD_STATUS_PEND; -#endif taskCB->taskStatus |= OS_TASK_STATUS_TIMEOUT; LOS_ListDelete(&taskCB->pendList); taskCB->taskMux = NULL; diff --git a/kernel/common/los_printf.c b/kernel/common/los_printf.c index dc46bdcb..9703d021 100644 --- a/kernel/common/los_printf.c +++ b/kernel/common/los_printf.c @@ -36,6 +36,7 @@ #endif #include "los_hwi.h" #include "los_memory_pri.h" +#include "los_process_pri.h" #ifdef LOSCFG_FS_VFS #include "console.h" #endif diff --git a/kernel/extended/hilog/los_hilog.c b/kernel/extended/hilog/los_hilog.c index 5b51234f..2bea2939 100644 --- a/kernel/extended/hilog/los_hilog.c +++ b/kernel/extended/hilog/los_hilog.c @@ -202,6 +202,13 @@ static ssize_t HiLogRead(struct file *filep, char *buffer, size_t bufLen) HiLogBufferDec(header.len); retval = header.len + sizeof(header); out: + if (retval == -ENOMEM) { + // clean ring buffer + g_hiLogDev.writeOffset = 0; + g_hiLogDev.headOffset = 0; + g_hiLogDev.size = 0; + g_hiLogDev.count = 0; + } (VOID)LOS_MuxRelease(&g_hiLogDev.mtx);//临界区操作结束 return retval; } diff --git a/kernel/extended/liteipc/hm_liteipc.c b/kernel/extended/liteipc/hm_liteipc.c index 6e210008..8648435e 100644 --- a/kernel/extended/liteipc/hm_liteipc.c +++ b/kernel/extended/liteipc/hm_liteipc.c @@ -255,11 +255,10 @@ LITE_OS_SEC_TEXT UINT32 LiteIpcPoolReInit(ProcIpcInfo *child, const ProcIpcInfo return LOS_OK; } -LITE_OS_SEC_TEXT VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo) +LITE_OS_SEC_TEXT VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo, UINT32 processID) { UINT32 intSave; IpcUsedNode *node = NULL; - UINT32 processID = LOS_GetCurrProcessID(); if (ipcInfo->pool.kvaddr != NULL) { LOS_VFree(ipcInfo->pool.kvaddr); ipcInfo->pool.kvaddr = NULL; @@ -955,9 +954,8 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcWrite(IpcContent *content) SCHEDULER_LOCK(intSave); LosTaskCB *tcb = OS_TCB_FROM_TID(dstTid);//找到目标任务ID,需要哪些任务去读 LOS_ListTailInsert(&(tcb->msgListHead), &(buf->listNode));//从尾部挂入任务的消息链表 - OsHookCall(LOS_HOOK_TYPE_IPC_WRITE, &buf->msg, dstTid, tcb->processID, tcb->ipcStatus); - if (tcb->ipcStatus & IPC_THREAD_STATUS_PEND) { - tcb->ipcStatus &= ~IPC_THREAD_STATUS_PEND; + OsHookCall(LOS_HOOK_TYPE_IPC_WRITE, &buf->msg, dstTid, tcb->processID, tcb->waitFlag); + if (tcb->waitFlag == OS_TASK_WAIT_LITEIPC) { OsTaskWakeClearPendMask(tcb); OsSchedTaskWake(tcb); SCHEDULER_UNLOCK(intSave); @@ -1013,11 +1011,11 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckRecievedMsg(IpcListNode *node, IpcContent *c ret = -EINVAL; } if (ret != LOS_OK) { - OsHookCall(LOS_HOOK_TYPE_IPC_READ_DROP, &node->msg, tcb->ipcStatus); + OsHookCall(LOS_HOOK_TYPE_IPC_READ_DROP, &node->msg, tcb->waitFlag); (VOID)HandleSpecialObjects(LOS_CurTaskIDGet(), node, TRUE); (VOID)LiteIpcNodeFree(LOS_GetCurrProcessID(), (VOID *)node); } else { - OsHookCall(LOS_HOOK_TYPE_IPC_READ, &node->msg, tcb->ipcStatus); + OsHookCall(LOS_HOOK_TYPE_IPC_READ, &node->msg, tcb->waitFlag); } return ret; } @@ -1037,18 +1035,17 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcRead(IpcContent *content) do { SCHEDULER_LOCK(intSave); if (LOS_ListEmpty(listHead)) { - OsHookCall(LOS_HOOK_TYPE_IPC_TRY_READ, syncFlag ? MT_REPLY : MT_REQUEST, tcb->ipcStatus); - tcb->ipcStatus |= IPC_THREAD_STATUS_PEND; OsTaskWaitSetPendMask(OS_TASK_WAIT_LITEIPC, OS_INVALID_VALUE, timeout); + OsHookCall(LOS_HOOK_TYPE_IPC_TRY_READ, syncFlag ? MT_REPLY : MT_REQUEST, tcb->waitFlag); ret = OsSchedTaskWait(&g_ipcPendlist, timeout, TRUE); if (ret == LOS_ERRNO_TSK_TIMEOUT) { - OsHookCall(LOS_HOOK_TYPE_IPC_READ_TIMEOUT, syncFlag ? MT_REPLY : MT_REQUEST, tcb->ipcStatus); + OsHookCall(LOS_HOOK_TYPE_IPC_READ_TIMEOUT, syncFlag ? MT_REPLY : MT_REQUEST, tcb->waitFlag); SCHEDULER_UNLOCK(intSave); return -ETIME; } if (OsTaskIsKilled(tcb)) { - OsHookCall(LOS_HOOK_TYPE_IPC_KILL, syncFlag ? MT_REPLY : MT_REQUEST, tcb->ipcStatus); + OsHookCall(LOS_HOOK_TYPE_IPC_KILL, syncFlag ? MT_REPLY : MT_REQUEST, tcb->waitFlag); SCHEDULER_UNLOCK(intSave); return -ERFKILL; } diff --git a/kernel/extended/liteipc/hm_liteipc.h b/kernel/extended/liteipc/hm_liteipc.h index 81be5ab7..322e10f0 100644 --- a/kernel/extended/liteipc/hm_liteipc.h +++ b/kernel/extended/liteipc/hm_liteipc.h @@ -174,11 +174,6 @@ typedef struct { //IPC消息内容回路,记录消息周期 VOID *buffToFree; } IpcContent; -#define IPC_THREAD_STATUS_INVAL 0x0001U -#define IPC_THREAD_STATUS_START 0x0002U -#define IPC_THREAD_STATUS_PEND 0x0004U -#define IPC_THREAD_STATUS_STOP 0x0008U - /* init liteipc driver */ extern UINT32 OsLiteIpcInit(VOID); @@ -189,7 +184,7 @@ extern UINT32 LiteIpcPoolInit(ProcIpcInfo *ipcInfo); extern UINT32 LiteIpcPoolReInit(ProcIpcInfo *childIpcInfo, const ProcIpcInfo *parentIpcInfo); /* delete process liteipc memory pool */ -extern VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo); +extern VOID LiteIpcPoolDelete(ProcIpcInfo *ipcInfo, UINT32 processID); /* remove service handle and send death notify */ extern VOID LiteIpcRemoveServiceHandle(LosTaskCB *taskCB); diff --git a/kernel/include/los_task.h b/kernel/include/los_task.h index 6cde7faf..cd99bd7a 100644 --- a/kernel/include/los_task.h +++ b/kernel/include/los_task.h @@ -59,7 +59,15 @@ extern "C" { * * The task is automatically deleted. */ -#define LOS_TASK_STATUS_DETACHED 0x0800U //任务被自动删除 +#define LOS_TASK_STATUS_DETACHED 0x0U + +/** + * @ingroup los_task + * Flag that indicates the task or task control block status. + * + * The task is joinable. + */ +#define LOS_TASK_ATTR_JOINABLE 0x80000000 /** * @ingroup los_task @@ -1065,6 +1073,49 @@ extern INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16 priority); */ extern VOID LOS_Schedule(VOID); +/** + * @ingroup los_task + * @brief Wait for the specified task to finish and reclaim its resources. + * + * @par Description: + * This API is used to wait for the specified task to finish and reclaim its resources. + * + * @attention None. + * + * @param taskID [IN] task ID. + * @param retval [OUT] wait for the return value of the task. + * + * @retval LOS_OK successful + * @retval LOS_EINVAL Invalid parameter or invalid operation + * @retval LOS_EINTR Disallow calls in interrupt handlers + * @retval LOS_EPERM Waiting tasks and calling tasks do not belong to the same process + * @retval LOS_EDEADLK The waiting task is the same as the calling task + * @par Dependency: + * + */ +extern UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval); + +/** + * @ingroup los_task + * @brief Change the joinable attribute of the task to detach. + * + * @par Description: + * This API is used to change the joinable attribute of the task to detach. + * + * @attention None. + * + * @param taskID [IN] task ID. + * + * @retval LOS_OK successful + * @retval LOS_EINVAL Invalid parameter or invalid operation + * @retval LOS_EINTR Disallow calls in interrupt handlers + * @retval LOS_EPERM Waiting tasks and calling tasks do not belong to the same process + * @retval LOS_ESRCH Cannot modify the Joinable attribute of a task that is waiting for completion. + * @par Dependency: + * + */ +extern UINT32 LOS_TaskDetach(UINT32 taskID); + #ifdef __cplusplus #if __cplusplus } diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index 5e54413f..d473f450 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -2610,4 +2610,51 @@ int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, cons PointerFree(sigMaskbak); return (ret == -1) ? -get_errno() : ret; } + +int SysPselect6(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + const struct timespec *timeout, const long data[2]) +{ + int ret; + int retVal; + sigset_t_l origMask; + sigset_t_l setl; + + CHECK_ASPACE(readfds, sizeof(fd_set)); + CHECK_ASPACE(writefds, sizeof(fd_set)); + CHECK_ASPACE(exceptfds, sizeof(fd_set)); + CHECK_ASPACE(timeout, sizeof(struct timeval)); + + CPY_FROM_USER(readfds); + CPY_FROM_USER(writefds); + CPY_FROM_USER(exceptfds); + DUP_FROM_USER(timeout, sizeof(struct timeval)); + + ((struct timeval *)timeout)->tv_usec = timeout->tv_nsec / 1000; /* 1000, convert ns to us */ + + if (data != NULL) { + retVal = LOS_ArchCopyFromUser(&(setl.sig[0]), (int *)data[0], sizeof(sigset_t)); + if (retVal != 0) { + ret = -EFAULT; + FREE_DUP(timeout); + return ret; + } + } + + OsSigprocMask(SIG_SETMASK, &setl, &origMask); + ret = do_select(nfds, readfds, writefds, exceptfds, (struct timeval *)timeout, UserPoll); + if (ret < 0) { + /* do not copy parameter back to user mode if do_select failed */ + ret = -get_errno(); + FREE_DUP(timeout); + return ret; + } + OsSigprocMask(SIG_SETMASK, &origMask, NULL); + + CPY_TO_USER(readfds); + CPY_TO_USER(writefds); + CPY_TO_USER(exceptfds); + FREE_DUP(timeout); + + return ret; +} #endif diff --git a/syscall/los_syscall.h b/syscall/los_syscall.h index d5cd23ea..94f81968 100644 --- a/syscall/los_syscall.h +++ b/syscall/los_syscall.h @@ -130,7 +130,7 @@ extern int SysSetProcessGroupID(unsigned int pid, unsigned int gid); extern unsigned int SysCreateUserThread(const TSK_ENTRY_FUNC func, const UserTaskParam *userParam, bool joinable); extern int SysSetThreadArea(const char *area); extern char *SysGetThreadArea(void); -extern int SysUserThreadSetDeatch(unsigned int taskID); +extern int SysUserThreadSetDetach(unsigned int taskID); extern int SysUserThreadDetach(unsigned int taskID); extern int SysThreadJoin(unsigned int taskID); extern void SysUserExitGroup(int status); @@ -281,6 +281,8 @@ extern int SysIoctl(int fd, int req, void *arg); extern int SysFcntl(int fd, int cmd, void *arg); extern int SysDup2(int fd1, int fd2); extern int SysSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); +extern int SysPselect6(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + const struct timespec *timeout, const long data[2]); extern int SysTruncate(const char *path, off_t length); extern int SysFtruncate(int fd, off_t length); extern int SysStatfs(const char *path, struct statfs *buf); diff --git a/syscall/process_syscall.c b/syscall/process_syscall.c index 12f5dbec..30061793 100644 --- a/syscall/process_syscall.c +++ b/syscall/process_syscall.c @@ -884,9 +884,9 @@ unsigned int SysCreateUserThread(const TSK_ENTRY_FUNC func, const UserTaskParam param.pfnTaskEntry = func; if (joinable == TRUE) { - param.uwResved = OS_TASK_FLAG_PTHREAD_JOIN; + param.uwResved = LOS_TASK_ATTR_JOINABLE; } else { - param.uwResved = OS_TASK_FLAG_DETACHED; + param.uwResved = LOS_TASK_STATUS_DETACHED; } return OsCreateUserTask(OS_INVALID_VALUE, ¶m); @@ -922,7 +922,7 @@ char *SysGetThreadArea(void) return (char *)(OsCurrTaskGet()->userArea); } -int SysUserThreadSetDeatch(unsigned int taskID) +int SysUserThreadSetDetach(unsigned int taskID) { unsigned int intSave; int ret; diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index da1ca1a7..d023e2ef 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -83,6 +83,7 @@ SYSCALL_HAND_DEF(__NR_fstatat64, SysFstatat64, int, ARG_NUM_4) SYSCALL_HAND_DEF(__NR_fsync, SysFsync, int, ARG_NUM_1) SYSCALL_HAND_DEF(__NR__llseek, SysLseek64, off64_t, ARG_NUM_5) /* current only support 32bit max 4G file */ SYSCALL_HAND_DEF(__NR__newselect, SysSelect, int, ARG_NUM_5) +SYSCALL_HAND_DEF(__NR_pselect6, SysPselect6, int, ARG_NUM_6) SYSCALL_HAND_DEF(__NR_readv, SysReadv, ssize_t, ARG_NUM_3) SYSCALL_HAND_DEF(__NR_writev, SysWritev, ssize_t, ARG_NUM_3) SYSCALL_HAND_DEF(__NR_poll, SysPoll, int, ARG_NUM_3) @@ -254,7 +255,7 @@ SYSCALL_HAND_DEF(__NR_shmctl, SysShmCtl, int, ARG_NUM_3) SYSCALL_HAND_DEF(__NR_statx, SysStatx, int, ARG_NUM_5) /* LiteOS customized syscalls, not compatible with ARM EABI */ -SYSCALL_HAND_DEF(__NR_pthread_set_detach, SysUserThreadSetDeatch, int, ARG_NUM_1) +SYSCALL_HAND_DEF(__NR_pthread_set_detach, SysUserThreadSetDetach, int, ARG_NUM_1) SYSCALL_HAND_DEF(__NR_pthread_join, SysThreadJoin, int, ARG_NUM_1) SYSCALL_HAND_DEF(__NR_pthread_deatch, SysUserThreadDetach, int, ARG_NUM_1) SYSCALL_HAND_DEF(__NR_creat_user_thread, SysCreateUserThread, unsigned int, ARG_NUM_3) diff --git a/testsuites/unittest/IO/BUILD.gn b/testsuites/unittest/IO/BUILD.gn index e9095106..7eb948e4 100644 --- a/testsuites/unittest/IO/BUILD.gn +++ b/testsuites/unittest/IO/BUILD.gn @@ -85,6 +85,8 @@ sources_full = [ "full/IO_test_strncasecmp_l_002.cpp", "full/IO_test_ppoll_001.cpp", "full/IO_test_ppoll_002.cpp", + "full/IO_test_pselect_001.cpp", + "full/IO_test_pselect_002.cpp", ] if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) { diff --git a/testsuites/unittest/IO/It_test_IO.h b/testsuites/unittest/IO/It_test_IO.h index c64683df..5c763ca3 100644 --- a/testsuites/unittest/IO/It_test_IO.h +++ b/testsuites/unittest/IO/It_test_IO.h @@ -130,6 +130,7 @@ extern VOID IO_TEST_GETTEXT_001(VOID); extern VOID IO_TEST_PPOLL_001(void); extern VOID IO_TEST_PPOLL_002(void); extern VOID IO_TEST_PSELECT_001(void); +extern VOID IO_TEST_PSELECT_002(void); extern VOID IO_TEST_STRFMON_L_001(VOID); extern VOID IO_TEST_STRFMON_L_002(VOID); extern VOID IO_TEST_PPOLL_001(VOID); diff --git a/testsuites/unittest/IO/full/IO_test_pselect_001.cpp b/testsuites/unittest/IO/full/IO_test_pselect_001.cpp index 8cfbe3f5..d6cfa95d 100644 --- a/testsuites/unittest/IO/full/IO_test_pselect_001.cpp +++ b/testsuites/unittest/IO/full/IO_test_pselect_001.cpp @@ -36,34 +36,85 @@ #include #include "sys/select.h" +static UINT32 Testcase1(VOID) +{ + static const int TAR_STR_LEN = 12; /* 12, str len */ + int pipeFd[2], ret; /* 2, pipe return 2 file descirpter */ + fd_set reads; + ret = pipe(pipeFd); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + ret = write(pipeFd[1], "Hello World", TAR_STR_LEN); + ICUNIT_GOTO_EQUAL(ret, TAR_STR_LEN, ret, EXIT); + FD_ZERO(&reads); + FD_SET(pipeFd[0], &reads); + ret = select(pipeFd[0] + 1, &reads, nullptr, nullptr, nullptr); + ICUNIT_GOTO_EQUAL(ret, 1, ret, EXIT); + ret = FD_ISSET(pipeFd[0], &reads); + ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT); + close(pipeFd[0]); + close(pipeFd[1]); + return LOS_OK; +EXIT: + close(pipeFd[0]); + close(pipeFd[1]); + return LOS_NOK; +} + +#define V_SIGMASK 0x5555 static UINT32 testcase(VOID) { fd_set rfds; - //struct timeval tv; struct timespec tv; int retval; + pid_t pid; + int pipeFd[2]; /* 2, pipe id num */ + char buffer[40]; /* 40, buffer size */ + int i = 0; + int status; + + sigset_t mask; - /* Watch stdin (fd 0) to see when it has input. */ + retval = Testcase1(); /* first check select works */ + ICUNIT_GOTO_EQUAL(retval, 0, retval, OUT); + + retval = pipe(pipeFd); + ICUNIT_GOTO_EQUAL(retval, 0, retval, OUT); + + /* Watch fd to see when it has input. */ FD_ZERO(&rfds); - FD_SET(0, &rfds); + FD_SET(pipeFd[0], &rfds); /* Wait up to three seconds. */ - //tv.tv_sec = 3; - //tv.tv_usec = 0; - tv.tv_sec = 3; - tv.tv_nsec = 0; + tv.tv_sec = 3; /* 3, wait timer, second */ + tv.tv_nsec = 5; /* 5, wait timer, nano second */ + + pid = fork(); + if (pid == 0) { + close(pipeFd[1]); + + retval = pselect(pipeFd[0] + 1, &rfds, nullptr, nullptr, &tv, &mask); + close(pipeFd[0]); - retval = pselect(1, &rfds, nullptr, nullptr, &tv, ((long[]){ 0, _NSIG/8 })); + if (retval) { + exit(LOS_OK); + } else { + exit(LOS_NOK); + } + } else { + sleep(1); + close(pipeFd[0]); + retval = write(pipeFd[1], "0123456789012345678901234567890123456789", 40); /* write 40 bytes to stdin(fd 0) */ + ICUNIT_GOTO_EQUAL(retval, 40, retval, OUT); + close(pipeFd[1]); - if (retval == -1) { - perror("select()"); - } else if (retval) { - printf("Data is available now.\n"); - } else { /* FD_ISSET(0, &rfds) will be true. */ - printf("No data within three seconds.\n"); + wait(&status); + status = WEXITSTATUS(status); + ICUNIT_ASSERT_EQUAL(status, LOS_OK, status); } return LOS_OK; +OUT: + return LOS_NOK; } VOID IO_TEST_PSELECT_001(VOID) diff --git a/testsuites/unittest/IO/full/IO_test_pselect_002.cpp b/testsuites/unittest/IO/full/IO_test_pselect_002.cpp new file mode 100644 index 00000000..bf2148b8 --- /dev/null +++ b/testsuites/unittest/IO/full/IO_test_pselect_002.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * 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_test_IO.h" +#include +#include +#include +#include +#include "sys/select.h" + +static void SigPrint(int sig) +{ + return; +} + +static UINT32 testcase(VOID) +{ + fd_set rfds; + struct timespec tv; + int retval; + pid_t pid; + int pipeFd[2]; /* 2, pipe id num */ + char buffer[40]; /* 40, buffer size */ + + int i = 0; + int status; + + void (*retSig)(int); + sigset_t mask; + + retSig = signal(SIGALRM, SigPrint); + ICUNIT_ASSERT_NOT_EQUAL(retSig, NULL, retSig); + + retSig = signal(SIGUSR1, SigPrint); + ICUNIT_ASSERT_NOT_EQUAL(retSig, NULL, retSig); + + retval = sigemptyset(&mask); + ICUNIT_ASSERT_EQUAL(retval, 0, retval); + + retval = sigaddset(&mask, SIGALRM); + ICUNIT_ASSERT_EQUAL(retval, 0, retval); + + retval = sigaddset(&mask, SIGUSR1); + ICUNIT_ASSERT_EQUAL(retval, 0, retval); + + retval = pipe(pipeFd); + ICUNIT_GOTO_EQUAL(retval, 0, retval, OUT); + + /* Watch fd to see when it has input. */ + FD_ZERO(&rfds); + FD_SET(pipeFd[0], &rfds); + + /* Wait up to three seconds. */ + tv.tv_sec = 3; /* 3, wait timer, second */ + tv.tv_nsec = 5; /* 5, wait timer, nano second */ + + pid = fork(); + if (pid == 0) { + close(pipeFd[1]); + + retval = pselect(pipeFd[0] + 1, &rfds, nullptr, nullptr, &tv, &mask); + + close(pipeFd[0]); + + if (retval != 0) { + exit(LOS_OK); + } else { + exit(LOS_NOK); + } + } else { + sleep(1); + close(pipeFd[0]); + + retval = kill(pid, SIGALRM); + ICUNIT_ASSERT_EQUAL(retval, 0, retval); + + retval = kill(pid, SIGUSR1); + ICUNIT_ASSERT_EQUAL(retval, 0, retval); + close(pipeFd[1]); + + wait(&status); + status = WEXITSTATUS(status); + ICUNIT_ASSERT_EQUAL(status, LOS_OK, status); + } + + return LOS_OK; +OUT: + return LOS_NOK; +} + +VOID IO_TEST_PSELECT_002(VOID) +{ + TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION); +} + diff --git a/testsuites/unittest/IO/io_test.cpp b/testsuites/unittest/IO/io_test.cpp index 1556beb4..5b8f668d 100644 --- a/testsuites/unittest/IO/io_test.cpp +++ b/testsuites/unittest/IO/io_test.cpp @@ -93,6 +93,28 @@ HWTEST_F(IoTest, ItTestIo013, TestSize.Level0) #endif #if defined(LOSCFG_USER_TEST_FULL) +/* * + * @tc.name: IO_TEST_PSELECT_001 + * @tc.desc: function for IoTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_PSELECT_001, TestSize.Level0) +{ + IO_TEST_PSELECT_001(); +} + +/* * + * @tc.name: IO_TEST_PSELECT_002 + * @tc.desc: function for IoTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_PSELECT_002, TestSize.Level0) +{ + IO_TEST_PSELECT_002(); +} + /* * * @tc.name: IO_TEST_PPOLL_001 * @tc.desc: function for IoTest diff --git a/testsuites/unittest/common/include/osTest.h b/testsuites/unittest/common/include/osTest.h index 3ee6fb5d..c902d829 100644 --- a/testsuites/unittest/common/include/osTest.h +++ b/testsuites/unittest/common/include/osTest.h @@ -107,6 +107,8 @@ #define HWI_NUM_INTVALID OS_HWI_MAX_NUM #define writel(value, address) WRITE_UINT32(value, address) +extern UINT32 PrepareFileEnv(CHAR *pathList[], CHAR *streamList[], INT32 streamLen[], INT32 listCnt); +extern UINT32 RecoveryFileEnv(CHAR *pathList[], INT32 listCnt); extern UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri); extern UINT32 PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread); @@ -233,18 +235,6 @@ UINT32 LosTaskDelay(UINT32 tick); #define TEST_TASKDELAY_20TICK 20 #define TEST_TASKDELAY_50TICK 50 -#ifdef TEST3731 -#define TestTimer2ValueGet(temp) READ_UINT32(temp, TIMER1_REG_BASE + TIMER_VALUE) -#elif defined TEST3559 -#define TestTimer2ValueGet(temp) READ_UINT32(temp, TIMER3_REG_BASE + TIMER_VALUE) -#else -#define TestTimer2ValueGet(temp) READ_UINT32(temp, TIMER2_REG_BASE + TIMER_VALUE) -#endif -extern void TestTimer2Config(void); - -#define REALTIME(time) (UINT32)((UINT64)(0xffffffff - time) * 1000 / OS_SYS_CLOCK) /* accuracy:ms */ -#define HW_TMI(time) (UINT32)((UINT64)(0xffffffff - time) * 1000 / (OS_SYS_CLOCK / 1000000)) /* accuracy:ns */ - #define uart_printf_func printf #ifndef VFS_STAT_PRINTF @@ -268,7 +258,6 @@ extern void TestTimer2Config(void); #endif extern UINT32 g_shellTestQueueID; -extern int g_min_mempool_size; extern UINT32 g_testCount; extern UINT32 g_testCount1; extern UINT32 g_testCount2; @@ -400,10 +389,6 @@ void Test_usb_shellcmd(controller_type ctype, device_type dtype, usb_test_type t extern int Gettid(void); -#define COLOR(c) "\033[" c "m" -#define COLOR_RED(text) COLOR("1;31") text COLOR("0") -#define COLOR_GREEN(text) COLOR("1;32") text COLOR("0") - /* like the ctime/asctime api, use static buffer, though not thread-safe. */ static inline const char *Curtime() { diff --git a/testsuites/unittest/common/osTest.cpp b/testsuites/unittest/common/osTest.cpp index 0c02e5e6..ada54c52 100644 --- a/testsuites/unittest/common/osTest.cpp +++ b/testsuites/unittest/common/osTest.cpp @@ -129,6 +129,70 @@ VOID test_init_spinor(VOID); VOID test_deinit_jffs(VOID); VOID test_mtd_jffs(VOID); +UINT32 PrepareFileEnv(CHAR *pathList[], CHAR *streamList[], INT32 streamLen[], INT32 listCnt) +{ + CHAR nameBuf[256] = {0}; + for (UINT32 i = 0; i < listCnt; i++) { + UINT32 ret = access(pathList[i], 0); + if (ret == 0) { + ret = memcpy_s(nameBuf, sizeof(nameBuf), pathList[i], strlen(pathList[i]) + 1); + if (ret != 0) { + return -1; + } + ret = strcat_s(nameBuf, sizeof(nameBuf), "_bak_for_test"); + if (ret != 0) { + return -1; + } + ret = rename(pathList[i], nameBuf); + if (ret != 0) { + return -1; + } + } + FILE *fp = fopen(pathList[i], "w"); + if (fp == NULL) { + return -1; + } + ret = fwrite(streamList[i], 1, streamLen[i], fp); + if (ret != streamLen[i]) { + (VOID)fclose(fp); + return -1; + } + ret = fclose(fp); + if (ret != 0) { + printf("%d\n", errno); + } + } + return 0; +} + +UINT32 RecoveryFileEnv(CHAR *pathList[], INT32 listCnt) +{ + UINT32 ret; + CHAR nameBuf[256] = {0}; + for (UINT32 i = 0; i < listCnt; i++) { + ret = remove(pathList[i]); + if (ret != 0) { + printf("ret = %d, err = %d\n", ret, errno); + } + ret = memcpy_s(nameBuf, sizeof(nameBuf), pathList[i], strlen(pathList[i]) + 1); + if (ret != 0) { + return -1; + } + ret = strcat_s(nameBuf, sizeof(nameBuf), "_bak_for_test"); + if (ret != 0) { + return -1; + } + ret = access(nameBuf, 0); + if (ret == 0) { + ret = rename(nameBuf, pathList[i]); + if (ret != 0) { + return -1; + } + } + } + return 0; +} + VOID Wfi(VOID) { __asm__ __volatile__("wfi" : : : "memory"); diff --git a/testsuites/unittest/config.gni b/testsuites/unittest/config.gni index f2a2257f..9a5139eb 100644 --- a/testsuites/unittest/config.gni +++ b/testsuites/unittest/config.gni @@ -63,15 +63,15 @@ LOSCFG_USER_TEST_POSIX_MQUEUE = true LOSCFG_USER_TEST_POSIX_MEM = true LOSCFG_USER_TEST_SPINLOCK = true LOSCFG_USER_TEST_RWLOCK = true -LOSCFG_USER_TEST_PTHREAD = false -LOSCFG_USER_TEST_PROCESS = false +LOSCFG_USER_TEST_PTHREAD = true +LOSCFG_USER_TEST_PROCESS = true LOSCFG_USER_TEST_MUTEX = true LOSCFG_USER_TEST_SECURITY_CAPABILITY = true LOSCFG_USER_TEST_SECURITY_VID = true LOSCFG_USER_TEST_SECURITY_REUGID = true LOSCFG_USER_TEST_SIGNAL = true LOSCFG_USER_TEST_SYS = true -LOSCFG_USER_TEST_TIME_CLOCK = true +LOSCFG_USER_TEST_TIME_CLOCK = true LOSCFG_USER_TEST_TIME_TIMER = true LOSCFG_USER_TEST_UTIL = true LOSCFG_USER_TEST_TRACE = false diff --git a/testsuites/unittest/misc/full/misc_test_009.cpp b/testsuites/unittest/misc/full/misc_test_009.cpp index c8dcf10e..cc4c6518 100644 --- a/testsuites/unittest/misc/full/misc_test_009.cpp +++ b/testsuites/unittest/misc/full/misc_test_009.cpp @@ -30,14 +30,29 @@ */ #include "It_test_misc.h" -static UINT32 TestCase(VOID) +STATIC UINT32 TestCase(VOID) { - long ret; + INT32 ret; + CHAR *hostsFileStream = "127.0.0.1 localhost\n192.168.1.3 hisilicon\n::1 localhost\n"; + CHAR *pathList[] = {"/etc/hosts"}; + CHAR *streamList[] = {hostsFileStream}; + INT32 streamLen[] = {strlen(hostsFileStream)}; - ret = gethostid(); - ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); + ret = PrepareFileEnv(pathList, streamList, streamLen, 1); + if (ret != 0) { + printf("error: need some env files, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 1); + return -1; + } + ret = gethostid(); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, ERROUT); + (VOID)RecoveryFileEnv(pathList, 1); return 0; + +ERROUT: + (VOID)RecoveryFileEnv(pathList, 1); + return -1; } VOID ItTestMisc009(VOID) diff --git a/testsuites/unittest/process/process/BUILD.gn b/testsuites/unittest/process/process/BUILD.gn index 8923ca0c..05c26d51 100644 --- a/testsuites/unittest/process/process/BUILD.gn +++ b/testsuites/unittest/process/process/BUILD.gn @@ -47,7 +47,6 @@ sources_smoke = [ "smoke/process_test_004.cpp", "smoke/process_test_005.cpp", "smoke/process_test_006.cpp", - "smoke/process_test_007.cpp", "smoke/process_test_008.cpp", "smoke/process_test_009.cpp", "smoke/process_test_010.cpp", @@ -70,39 +69,16 @@ sources_smoke = [ "smoke/process_test_027.cpp", "smoke/process_test_029.cpp", "smoke/process_test_030.cpp", - "smoke/process_test_031.cpp", - "smoke/process_test_032.cpp", - "smoke/process_test_033.cpp", - "smoke/process_test_034.cpp", - "smoke/process_test_035.cpp", - "smoke/process_test_036.cpp", - "smoke/process_test_037.cpp", "smoke/process_test_038.cpp", "smoke/process_test_039.cpp", - "smoke/process_test_040.cpp", - "smoke/process_test_041.cpp", - "smoke/process_test_042.cpp", "smoke/process_test_043.cpp", "smoke/process_test_044.cpp", "smoke/process_test_045.cpp", "smoke/process_test_046.cpp", "smoke/process_test_047.cpp", "smoke/process_test_048.cpp", - "smoke/process_test_049.cpp", - "smoke/process_test_050.cpp", - "smoke/process_test_051.cpp", - "smoke/process_test_056.cpp", - "smoke/process_test_057.cpp", - "smoke/process_test_058.cpp", - "smoke/process_test_059.cpp", - "smoke/process_test_060.cpp", - "smoke/process_test_063.cpp", - "smoke/process_test_064.cpp", - "smoke/process_test_065.cpp", - "smoke/process_test_066.cpp", - "smoke/process_test_067.cpp", - "smoke/process_test_068.cpp", - "smoke/process_test_069.cpp", + "smoke/process_test_054.cpp", + "smoke/process_test_061.cpp", "smp/process_test_smp_001.cpp", "smp/process_test_smp_002.cpp", "smp/process_test_smp_003.cpp", @@ -114,10 +90,34 @@ sources_smoke = [ ] sources_full = [ - "full/process_test_053.cpp", - "full/process_test_054.cpp", + "full/process_test_007.cpp", + "full/process_test_031.cpp", + "full/process_test_032.cpp", + "full/process_test_033.cpp", + "full/process_test_034.cpp", + "full/process_test_035.cpp", + "full/process_test_036.cpp", + "full/process_test_037.cpp", + "full/process_test_040.cpp", + "full/process_test_041.cpp", + "full/process_test_042.cpp", + "full/process_test_049.cpp", + "full/process_test_050.cpp", + "full/process_test_051.cpp", "full/process_test_055.cpp", - "full/process_test_061.cpp", + "full/process_test_056.cpp", + "full/process_test_057.cpp", + "full/process_test_058.cpp", + "full/process_test_059.cpp", + "full/process_test_060.cpp", + "full/process_test_063.cpp", + "full/process_test_064.cpp", + "full/process_test_065.cpp", + "full/process_test_066.cpp", + "full/process_test_067.cpp", + "full/process_test_068.cpp", + "full/process_test_069.cpp", + "full/process_test_053.cpp", "full/process_test_062.cpp", ] diff --git a/testsuites/unittest/process/process/smoke/process_test_007.cpp b/testsuites/unittest/process/process/full/process_test_007.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_007.cpp rename to testsuites/unittest/process/process/full/process_test_007.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_031.cpp b/testsuites/unittest/process/process/full/process_test_031.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_031.cpp rename to testsuites/unittest/process/process/full/process_test_031.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_032.cpp b/testsuites/unittest/process/process/full/process_test_032.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_032.cpp rename to testsuites/unittest/process/process/full/process_test_032.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_033.cpp b/testsuites/unittest/process/process/full/process_test_033.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_033.cpp rename to testsuites/unittest/process/process/full/process_test_033.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_034.cpp b/testsuites/unittest/process/process/full/process_test_034.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_034.cpp rename to testsuites/unittest/process/process/full/process_test_034.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_035.cpp b/testsuites/unittest/process/process/full/process_test_035.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_035.cpp rename to testsuites/unittest/process/process/full/process_test_035.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_036.cpp b/testsuites/unittest/process/process/full/process_test_036.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_036.cpp rename to testsuites/unittest/process/process/full/process_test_036.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_037.cpp b/testsuites/unittest/process/process/full/process_test_037.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_037.cpp rename to testsuites/unittest/process/process/full/process_test_037.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_040.cpp b/testsuites/unittest/process/process/full/process_test_040.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_040.cpp rename to testsuites/unittest/process/process/full/process_test_040.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_041.cpp b/testsuites/unittest/process/process/full/process_test_041.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_041.cpp rename to testsuites/unittest/process/process/full/process_test_041.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_042.cpp b/testsuites/unittest/process/process/full/process_test_042.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_042.cpp rename to testsuites/unittest/process/process/full/process_test_042.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_049.cpp b/testsuites/unittest/process/process/full/process_test_049.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_049.cpp rename to testsuites/unittest/process/process/full/process_test_049.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_050.cpp b/testsuites/unittest/process/process/full/process_test_050.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_050.cpp rename to testsuites/unittest/process/process/full/process_test_050.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_051.cpp b/testsuites/unittest/process/process/full/process_test_051.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_051.cpp rename to testsuites/unittest/process/process/full/process_test_051.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_052.cpp b/testsuites/unittest/process/process/full/process_test_052.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_052.cpp rename to testsuites/unittest/process/process/full/process_test_052.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_056.cpp b/testsuites/unittest/process/process/full/process_test_056.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_056.cpp rename to testsuites/unittest/process/process/full/process_test_056.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_057.cpp b/testsuites/unittest/process/process/full/process_test_057.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_057.cpp rename to testsuites/unittest/process/process/full/process_test_057.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_058.cpp b/testsuites/unittest/process/process/full/process_test_058.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_058.cpp rename to testsuites/unittest/process/process/full/process_test_058.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_059.cpp b/testsuites/unittest/process/process/full/process_test_059.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_059.cpp rename to testsuites/unittest/process/process/full/process_test_059.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_060.cpp b/testsuites/unittest/process/process/full/process_test_060.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_060.cpp rename to testsuites/unittest/process/process/full/process_test_060.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_063.cpp b/testsuites/unittest/process/process/full/process_test_063.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_063.cpp rename to testsuites/unittest/process/process/full/process_test_063.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_064.cpp b/testsuites/unittest/process/process/full/process_test_064.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_064.cpp rename to testsuites/unittest/process/process/full/process_test_064.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_065.cpp b/testsuites/unittest/process/process/full/process_test_065.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_065.cpp rename to testsuites/unittest/process/process/full/process_test_065.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_066.cpp b/testsuites/unittest/process/process/full/process_test_066.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_066.cpp rename to testsuites/unittest/process/process/full/process_test_066.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_067.cpp b/testsuites/unittest/process/process/full/process_test_067.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_067.cpp rename to testsuites/unittest/process/process/full/process_test_067.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_068.cpp b/testsuites/unittest/process/process/full/process_test_068.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_068.cpp rename to testsuites/unittest/process/process/full/process_test_068.cpp diff --git a/testsuites/unittest/process/process/smoke/process_test_069.cpp b/testsuites/unittest/process/process/full/process_test_069.cpp similarity index 100% rename from testsuites/unittest/process/process/smoke/process_test_069.cpp rename to testsuites/unittest/process/process/full/process_test_069.cpp diff --git a/testsuites/unittest/process/process/process_process_test.cpp b/testsuites/unittest/process/process/process_process_test.cpp index 4f602173..d2040487 100644 --- a/testsuites/unittest/process/process/process_process_test.cpp +++ b/testsuites/unittest/process/process/process_process_test.cpp @@ -126,17 +126,6 @@ HWTEST_F(ProcessProcessTest, ItTestProcess006, TestSize.Level0) ItTestProcess006(); } -/* * - * @tc.name: it_test_process_007 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess007, TestSize.Level0) -{ - ItTestProcess007(); -} - /* * * @tc.name: it_test_process_008 * @tc.desc: function for ProcessProcessTest @@ -379,83 +368,6 @@ HWTEST_F(ProcessProcessTest, ItTestProcess030, TestSize.Level0) ItTestProcess030(); } -/* * - * @tc.name: it_test_process_031 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess031, TestSize.Level0) -{ - ItTestProcess031(); -} - -/* * - * @tc.name: it_test_process_032 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess032, TestSize.Level0) -{ - ItTestProcess032(); -} - -/* * - * @tc.name: it_test_process_033 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess033, TestSize.Level0) -{ - ItTestProcess033(); -} - -/* * - * @tc.name: it_test_process_034 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess034, TestSize.Level0) -{ - ItTestProcess034(); -} - -/* * - * @tc.name: it_test_process_035 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess035, TestSize.Level0) -{ - ItTestProcess035(); -} - -/* * - * @tc.name: it_test_process_036 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess036, TestSize.Level0) -{ - ItTestProcess036(); -} - -/* * - * @tc.name: it_test_process_037 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess037, TestSize.Level0) -{ - ItTestProcess037(); -} - /* * * @tc.name: it_test_process_038 * @tc.desc: function for ProcessProcessTest @@ -478,39 +390,6 @@ HWTEST_F(ProcessProcessTest, ItTestProcess039, TestSize.Level0) ItTestProcess039(); } -/* * - * @tc.name: it_test_process_040 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess040, TestSize.Level0) -{ - ItTestProcess040(); -} - -/* * - * @tc.name: it_test_process_041 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess041, TestSize.Level0) -{ - ItTestProcess041(); -} - -/* * - * @tc.name: it_test_process_042 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess042, TestSize.Level0) -{ - ItTestProcess042(); -} - /* * * @tc.name: it_test_process_043 * @tc.desc: function for ProcessProcessTest @@ -578,266 +457,240 @@ HWTEST_F(ProcessProcessTest, ItTestProcess048, TestSize.Level0) } /* * - * @tc.name: it_test_process_049 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: DTS202101040I5J4KP0H00 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess049, TestSize.Level0) -{ - ItTestProcess049(); -} - -/* * - * @tc.name: it_test_process_050 - * @tc.desc: function for ProcessProcessTest - * @tc.type: FUNC - * @tc.require: DTS202101040I5J4KP0H00 - */ -HWTEST_F(ProcessProcessTest, ItTestProcess050, TestSize.Level0) -{ - ItTestProcess050(); -} - -/* * - * @tc.name: it_test_process_051 - * @tc.desc: function for ProcessProcessTest + * @tc.name: it_test_process_054 + * @tc.desc: function for waitid: The waitid parameter is incorrect and the error code is verified. * @tc.type: FUNC - * @tc.require: DTS202101040I5J4KP0H00 + * @tc.require: AR000E0QAB */ -HWTEST_F(ProcessProcessTest, ItTestProcess051, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess054, TestSize.Level0) { - ItTestProcess051(); + ItTestProcess054(); } /* * - * @tc.name: it_test_process_056 - * @tc.desc: function for posix_spawn:Verifying Basic Functions + * @tc.name: it_test_process_061 + * @tc.desc: function for killpg: The killpg parameter is incorrect and the error code is verified. * @tc.type: FUNC * @tc.require: AR000E0QAB */ -HWTEST_F(ProcessProcessTest, ItTestProcess056, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess061, TestSize.Level0) { - ItTestProcess056(); + ItTestProcess061(); } +#ifdef LOSCFG_USER_TEST_SMP /* * - * @tc.name: it_test_process_057 - * @tc.desc: function for posix_spawnp:Verifying Basic Functions + * @tc.name: it_test_process_smp_001 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess057, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcessSmp001, TestSize.Level0) { - ItTestProcess057(); + ItTestProcessSmp001(); } /* * - * @tc.name: it_test_process_058 - * @tc.desc: function for posix_spawn: The attr parameter is correctly transferred and the flag is set. + * @tc.name: it_test_process_smp_002 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess058, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcessSmp002, TestSize.Level0) { - ItTestProcess058(); + ItTestProcessSmp002(); } /* * - * @tc.name: it_test_process_059 - * @tc.desc: function for posix_spawnp: The attr parameter is correctly transferred and the flag is set. + * @tc.name: it_test_process_smp_003 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess059, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcessSmp003, TestSize.Level0) { - ItTestProcess059(); + ItTestProcessSmp003(); } /* * - * @tc.name: it_test_process_060 - * @tc.desc: function for posix_spawnp: Error code verification for the attr setting function. - * The attr parameter is incorrect and the error code is verified. + * @tc.name: it_test_process_smp_004 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess060, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcessSmp004, TestSize.Level0) { - ItTestProcess060(); + ItTestProcessSmp004(); } /* * - * @tc.name: it_test_process_063 - * @tc.desc: function for posix_spawn: The file path, argv command, and envp environment variable are invalid. - * Error code verification is performed. + * @tc.name: it_test_process_smp_005 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess063, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcessSmp005, TestSize.Level0) { - ItTestProcess063(); + ItTestProcessSmp005(); } /* * - * @tc.name: it_test_process_064 - * @tc.desc: function for posix_spawnp: The file path, argv command, and envp environment variable are invalid. - * Error code verification is performed. + * @tc.name: it_test_process_smp_006 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess064, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcessSmp006, TestSize.Level0) { - ItTestProcess064(); + ItTestProcessSmp006(); } /* * - * @tc.name: it_test_process_065 - * @tc.desc: function for posix_spawn: Error code verification for the attr setting function. - * The attr parameter is incorrect and the error code is verified. + * @tc.name: it_test_process_smp_007 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess065, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcessSmp007, TestSize.Level0) { - ItTestProcess065(); + ItTestProcessSmp007(); } /* * - * @tc.name: it_test_process_066 - * @tc.desc: function for posix_spawn: Check the effect of subprocess settings when attr is valid. + * @tc.name: it_test_process_smp_008 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess066, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcessSmp008, TestSize.Level0) { - ItTestProcess066(); + ItTestProcessSmp008(); } +#endif +#endif +#if defined(LOSCFG_USER_TEST_FULL) /* * - * @tc.name: it_test_process_067 - * @tc.desc: function for posix_spawn: Check the effect of subprocess settings when attr is valid. + * @tc.name: it_test_process_007 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess067, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess007, TestSize.Level0) { - ItTestProcess067(); + ItTestProcess007(); } /* * - * @tc.name: it_test_process_068 - * @tc.desc: function for posix_spawn: Verify the effect of the argv and envp parameters in subprocesses. + * @tc.name: it_test_process_031 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess068, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess031, TestSize.Level0) { - ItTestProcess068(); + ItTestProcess031(); } /* * - * @tc.name: it_test_process_069 - * @tc.desc: function for posix_spawnp: Verify the effect of the argv and envp parameters in subprocesses. + * @tc.name: it_test_process_032 + * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC - * @tc.require: AR000E0QAB + * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcess069, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess032, TestSize.Level0) { - ItTestProcess069(); + ItTestProcess032(); } -#ifdef LOSCFG_USER_TEST_SMP /* * - * @tc.name: it_test_process_smp_001 + * @tc.name: it_test_process_033 * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcessSmp001, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess033, TestSize.Level0) { - ItTestProcessSmp001(); + ItTestProcess033(); } /* * - * @tc.name: it_test_process_smp_002 + * @tc.name: it_test_process_034 * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcessSmp002, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess034, TestSize.Level0) { - ItTestProcessSmp002(); + ItTestProcess034(); } /* * - * @tc.name: it_test_process_smp_003 + * @tc.name: it_test_process_035 * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcessSmp003, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess035, TestSize.Level0) { - ItTestProcessSmp003(); + ItTestProcess035(); } /* * - * @tc.name: it_test_process_smp_004 + * @tc.name: it_test_process_036 * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcessSmp004, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess036, TestSize.Level0) { - ItTestProcessSmp004(); + ItTestProcess036(); } /* * - * @tc.name: it_test_process_smp_005 + * @tc.name: it_test_process_037 * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcessSmp005, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess037, TestSize.Level0) { - ItTestProcessSmp005(); + ItTestProcess037(); } /* * - * @tc.name: it_test_process_smp_006 + * @tc.name: it_test_process_040 * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcessSmp006, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess040, TestSize.Level0) { - ItTestProcessSmp006(); + ItTestProcess040(); } /* * - * @tc.name: it_test_process_smp_007 + * @tc.name: it_test_process_041 * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcessSmp007, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess041, TestSize.Level0) { - ItTestProcessSmp007(); + ItTestProcess041(); } /* * - * @tc.name: it_test_process_smp_008 + * @tc.name: it_test_process_042 * @tc.desc: function for ProcessProcessTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessProcessTest, ItTestProcessSmp008, TestSize.Level0) +HWTEST_F(ProcessProcessTest, ItTestProcess042, TestSize.Level0) { - ItTestProcessSmp008(); + ItTestProcess042(); } -#endif -#endif -#if defined(LOSCFG_USER_TEST_FULL) /* * * @tc.name: it_test_process_053 * @tc.desc: function for killpg:Sends a signal to the process group, @@ -850,17 +703,6 @@ HWTEST_F(ProcessProcessTest, ItTestProcess053, TestSize.Level0) ItTestProcess053(); } -/* * - * @tc.name: it_test_process_054 - * @tc.desc: function for waitid: The waitid parameter is incorrect and the error code is verified. - * @tc.type: FUNC - * @tc.require: AR000E0QAB - */ -HWTEST_F(ProcessProcessTest, ItTestProcess054, TestSize.Level0) -{ - ItTestProcess054(); -} - /* * * @tc.name: it_test_process_055 * @tc.desc: function for waitid:To test the function of transferring different parameters of the waitid. @@ -872,17 +714,6 @@ HWTEST_F(ProcessProcessTest, ItTestProcess055, TestSize.Level0) ItTestProcess055(); } -/* * - * @tc.name: it_test_process_061 - * @tc.desc: function for killpg: The killpg parameter is incorrect and the error code is verified. - * @tc.type: FUNC - * @tc.require: AR000E0QAB - */ -HWTEST_F(ProcessProcessTest, ItTestProcess061, TestSize.Level0) -{ - ItTestProcess061(); -} - /* * * @tc.name: it_test_process_062 * @tc.desc: function for killpg:Fork two processes. The killpg sends a signal to the current process group. diff --git a/testsuites/unittest/process/process/smoke/process_test_045.cpp b/testsuites/unittest/process/process/smoke/process_test_045.cpp index 6a82ae7b..a094cb7e 100644 --- a/testsuites/unittest/process/process/smoke/process_test_045.cpp +++ b/testsuites/unittest/process/process/smoke/process_test_045.cpp @@ -59,11 +59,11 @@ static UINT32 Testcase(VOID) ICUNIT_ASSERT_EQUAL(ret, -1, ret); ICUNIT_ASSERT_EQUAL(errno, EPERM, errno); - ret = sched_setaffinity(60, sizeof(cpu_set_t), &cpuset); // 60, pid num + ret = sched_setaffinity(128, sizeof(cpu_set_t), &cpuset); // 128, pid num ICUNIT_ASSERT_EQUAL(ret, -1, ret); ICUNIT_ASSERT_EQUAL(errno, ESRCH, errno); - ret = sched_getaffinity(60, sizeof(cpu_set_t), &cpuset); // 60, pid num + ret = sched_getaffinity(128, sizeof(cpu_set_t), &cpuset); // 128, pid num ICUNIT_ASSERT_EQUAL(ret, -1, ret); ICUNIT_ASSERT_EQUAL(errno, ESRCH, errno); diff --git a/testsuites/unittest/process/process/full/process_test_054.cpp b/testsuites/unittest/process/process/smoke/process_test_054.cpp similarity index 100% rename from testsuites/unittest/process/process/full/process_test_054.cpp rename to testsuites/unittest/process/process/smoke/process_test_054.cpp diff --git a/testsuites/unittest/process/process/full/process_test_061.cpp b/testsuites/unittest/process/process/smoke/process_test_061.cpp similarity index 100% rename from testsuites/unittest/process/process/full/process_test_061.cpp rename to testsuites/unittest/process/process/smoke/process_test_061.cpp diff --git a/testsuites/unittest/process/pthread/BUILD.gn b/testsuites/unittest/process/pthread/BUILD.gn index d32e2bba..728a6fe4 100644 --- a/testsuites/unittest/process/pthread/BUILD.gn +++ b/testsuites/unittest/process/pthread/BUILD.gn @@ -46,12 +46,10 @@ sources_smoke = [ "smoke/pthread_atfork_test_002.cpp", "smoke/pthread_cond_test_001.cpp", "smoke/pthread_cond_test_002.cpp", + "smoke/pthread_cond_test_003.cpp", + "smoke/pthread_cond_test_004.cpp", "smoke/pthread_once_test_001.cpp", - "smoke/pthread_test_001.cpp", - "smoke/pthread_test_002.cpp", "smoke/pthread_test_003.cpp", - "smoke/pthread_test_004.cpp", - "smoke/pthread_test_005.cpp", "smoke/pthread_test_006.cpp", "smoke/pthread_test_007.cpp", "smoke/pthread_test_008.cpp", @@ -60,7 +58,6 @@ sources_smoke = [ "smoke/pthread_test_011.cpp", "smoke/pthread_test_012.cpp", "smoke/pthread_test_013.cpp", - "smoke/pthread_test_014.cpp", "smoke/pthread_test_015.cpp", "smoke/pthread_test_016.cpp", "smoke/pthread_test_017.cpp", @@ -69,6 +66,11 @@ sources_smoke = [ ] sources_full = [ + "full/pthread_test_001.cpp", + "full/pthread_test_002.cpp", + "full/pthread_test_004.cpp", + "full/pthread_test_005.cpp", + "full/pthread_test_014.cpp", ] if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) { diff --git a/testsuites/unittest/process/pthread/smoke/pthread_test_001.cpp b/testsuites/unittest/process/pthread/full/pthread_test_001.cpp similarity index 100% rename from testsuites/unittest/process/pthread/smoke/pthread_test_001.cpp rename to testsuites/unittest/process/pthread/full/pthread_test_001.cpp diff --git a/testsuites/unittest/process/pthread/smoke/pthread_test_002.cpp b/testsuites/unittest/process/pthread/full/pthread_test_002.cpp similarity index 100% rename from testsuites/unittest/process/pthread/smoke/pthread_test_002.cpp rename to testsuites/unittest/process/pthread/full/pthread_test_002.cpp diff --git a/testsuites/unittest/process/pthread/smoke/pthread_test_004.cpp b/testsuites/unittest/process/pthread/full/pthread_test_004.cpp similarity index 99% rename from testsuites/unittest/process/pthread/smoke/pthread_test_004.cpp rename to testsuites/unittest/process/pthread/full/pthread_test_004.cpp index b3cce7e4..18bc242e 100644 --- a/testsuites/unittest/process/pthread/smoke/pthread_test_004.cpp +++ b/testsuites/unittest/process/pthread/full/pthread_test_004.cpp @@ -245,6 +245,10 @@ static void *threadFunc(void *arg) ret = pthread_create(&newPthread, &a, threadFunc2, 0); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); +#ifdef LOSCFG_USER_TEST_SMP + sleep(1); +#endif + ret = pthread_spin_lock(&g_spinTestLock); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(g_pthreadTestCount, 4, g_pthreadTestCount, EXIT); // 4, here assert the result. diff --git a/testsuites/unittest/process/pthread/smoke/pthread_test_005.cpp b/testsuites/unittest/process/pthread/full/pthread_test_005.cpp similarity index 100% rename from testsuites/unittest/process/pthread/smoke/pthread_test_005.cpp rename to testsuites/unittest/process/pthread/full/pthread_test_005.cpp diff --git a/testsuites/unittest/process/pthread/smoke/pthread_test_014.cpp b/testsuites/unittest/process/pthread/full/pthread_test_014.cpp similarity index 100% rename from testsuites/unittest/process/pthread/smoke/pthread_test_014.cpp rename to testsuites/unittest/process/pthread/full/pthread_test_014.cpp diff --git a/testsuites/unittest/process/pthread/it_pthread_test.h b/testsuites/unittest/process/pthread/it_pthread_test.h index 1bd3f098..5a285732 100644 --- a/testsuites/unittest/process/pthread/it_pthread_test.h +++ b/testsuites/unittest/process/pthread/it_pthread_test.h @@ -79,4 +79,6 @@ extern void ItTestPthreadAtfork002(void); extern void ItTestPthreadOnce001(void); extern void ItTestPthreadCond001(void); extern void ItTestPthreadCond002(void); -#endif \ No newline at end of file +extern void ItTestPthreadCond003(void); +extern void ItTestPthreadCond004(void); +#endif diff --git a/testsuites/unittest/process/pthread/process_pthread_test.cpp b/testsuites/unittest/process/pthread/process_pthread_test.cpp index ac6f1076..cf49b316 100644 --- a/testsuites/unittest/process/pthread/process_pthread_test.cpp +++ b/testsuites/unittest/process/pthread/process_pthread_test.cpp @@ -52,30 +52,6 @@ public: }; #if defined(LOSCFG_USER_TEST_SMOKE) -/* * - * @tc.name: it_test_pthread_001 - * @tc.desc: function for ProcessPthreadTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessPthreadTest, ItTestPthread001, TestSize.Level0) -{ - ItTestPthread001(); -} - -#ifndef LOSCFG_USER_TEST_SMP -/* * - * @tc.name: it_test_pthread_002 - * @tc.desc: function for ProcessPthreadTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessPthreadTest, ItTestPthread002, TestSize.Level0) -{ - ItTestPthread002(); -} - -#endif /* * * @tc.name: it_test_pthread_003 * @tc.desc: function for ProcessPthreadTest @@ -87,28 +63,6 @@ HWTEST_F(ProcessPthreadTest, ItTestPthread003, TestSize.Level0) ItTestPthread003(); } -/* * - * @tc.name: it_test_pthread_004 - * @tc.desc: function for ProcessPthreadTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessPthreadTest, ItTestPthread004, TestSize.Level0) -{ - ItTestPthread004(); -} - -/* * - * @tc.name: it_test_pthread_005 - * @tc.desc: function for ProcessPthreadTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessPthreadTest, ItTestPthread005, TestSize.Level0) -{ - ItTestPthread005(); -} - #ifndef LOSCFG_USER_TEST_SMP /* * * @tc.name: it_test_pthread_006 @@ -201,19 +155,6 @@ HWTEST_F(ProcessPthreadTest, ItTestPthread013, TestSize.Level0) ItTestPthread013(); } -#ifndef LOSCFG_USER_TEST_SMP -/* * - * @tc.name: it_test_pthread_014 - * @tc.desc: function for ProcessPthreadTest - * @tc.type: FUNC - * @tc.require: AR000EEMQ9 - */ -HWTEST_F(ProcessPthreadTest, ItTestPthread014, TestSize.Level0) -{ - ItTestPthread014(); -} -#endif - /* * * @tc.name: it_test_pthread_015 * @tc.desc: function for ProcessPthreadTest @@ -237,38 +178,39 @@ HWTEST_F(ProcessPthreadTest, ItTestPthread016, TestSize.Level0) } /* * - * @tc.name: it_test_pthread_017 + * @tc.name: it_test_pthread_018 * @tc.desc: function for ProcessPthreadTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessPthreadTest, ItTestPthread017, TestSize.Level0) +HWTEST_F(ProcessPthreadTest, ItTestPthread018, TestSize.Level0) { - ItTestPthread017(); + ItTestPthread018(); } /* * - * @tc.name: it_test_pthread_018 + * @tc.name: it_test_pthread_019 * @tc.desc: function for ProcessPthreadTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessPthreadTest, ItTestPthread018, TestSize.Level0) +HWTEST_F(ProcessPthreadTest, ItTestPthread019, TestSize.Level0) { - ItTestPthread018(); + ItTestPthread019(); } /* * - * @tc.name: it_test_pthread_019 + * @tc.name: it_test_pthread_017 * @tc.desc: function for ProcessPthreadTest * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(ProcessPthreadTest, ItTestPthread019, TestSize.Level0) +HWTEST_F(ProcessPthreadTest, ItTestPthread017, TestSize.Level0) { - ItTestPthread019(); + ItTestPthread017(); } + /* * * @tc.name: it_test_pthread_once_001 * @tc.desc: function for ProcessPthreadTest @@ -323,5 +265,89 @@ HWTEST_F(ProcessPthreadTest, ItTestPthreadCond002, TestSize.Level0) { ItTestPthreadCond002(); } + +/* * + * @tc.name: it_test_pthread_cond_003 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(ProcessPthreadTest, ItTestPthreadCond003, TestSize.Level0) +{ + ItTestPthreadCond003(); +} + +/* * + * @tc.name: it_test_pthread_cond_004 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(ProcessPthreadTest, ItTestPthreadCond004, TestSize.Level0) +{ + ItTestPthreadCond004(); +} + +#endif + +#if defined(LOSCFG_USER_TEST_FULL) +/* * + * @tc.name: it_test_pthread_001 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread001, TestSize.Level0) +{ + ItTestPthread001(); +} + +#ifndef LOSCFG_USER_TEST_SMP +/* * + * @tc.name: it_test_pthread_002 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread002, TestSize.Level0) +{ + ItTestPthread002(); +} +#endif +/* * + * @tc.name: it_test_pthread_004 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread004, TestSize.Level0) +{ + ItTestPthread004(); +} + +/* * + * @tc.name: it_test_pthread_005 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread005, TestSize.Level0) +{ + ItTestPthread005(); +} + +#ifndef LOSCFG_USER_TEST_SMP +/* * + * @tc.name: it_test_pthread_014 + * @tc.desc: function for ProcessPthreadTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(ProcessPthreadTest, ItTestPthread014, TestSize.Level0) +{ + ItTestPthread014(); +} +#endif + #endif } // namespace OHOS diff --git a/testsuites/unittest/process/pthread/smoke/pthread_cond_test_001.cpp b/testsuites/unittest/process/pthread/smoke/pthread_cond_test_001.cpp index 42336efc..ed5debca 100644 --- a/testsuites/unittest/process/pthread/smoke/pthread_cond_test_001.cpp +++ b/testsuites/unittest/process/pthread/smoke/pthread_cond_test_001.cpp @@ -41,7 +41,7 @@ static void *PthreadF01(void *t) ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT); g_testCount++; - LosTaskDelay(1); + LosTaskDelay(100); ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, here assert the result. g_testCount++; diff --git a/testsuites/unittest/process/pthread/smoke/pthread_cond_test_003.cpp b/testsuites/unittest/process/pthread/smoke/pthread_cond_test_003.cpp new file mode 100644 index 00000000..736d7d5a --- /dev/null +++ b/testsuites/unittest/process/pthread/smoke/pthread_cond_test_003.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * 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_pthread_test.h" + +static pthread_cond_t g_pthread_cond; +static pthread_mutex_t g_pthread_mutex; +#define TEST_THREAD_COUNT 5 +static void *pthread_cond_func001(void *arg) +{ + int ret; + struct timespec ts; + + g_testCount++; + + ret = pthread_mutex_lock(&g_pthread_mutex); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += 60; /* 60: wait 1 minute */ + + ret = pthread_cond_timedwait(&g_pthread_cond, &g_pthread_mutex, &ts); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_mutex_unlock(&g_pthread_mutex); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + g_testCount++; +EXIT: + return NULL; +} + +static VOID *pthread_f06(void *argument) +{ + int policy; + int ret; + int i; + pthread_attr_t attr; + struct sched_param schedParam = { 0 }; + pthread_t thread[TEST_THREAD_COUNT]; + + g_testCount = 0; + + ret = pthread_attr_init(&attr); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_getschedparam(pthread_self(), &policy, &schedParam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + schedParam.sched_priority -= 1; + ret = pthread_attr_setschedparam(&attr, &schedParam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + for (i = 0; i < TEST_THREAD_COUNT; i++) { + ret = pthread_create(&thread[i], &attr, pthread_cond_func001, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + } + + sleep(1); + + ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); /* 5: Five threads */ + + ret = pthread_mutex_lock(&g_pthread_mutex); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_cond_broadcast(&g_pthread_cond); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_mutex_unlock(&g_pthread_mutex); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + for (i = 0; i < TEST_THREAD_COUNT; i++) { + ret = pthread_join(thread[i], NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + } + + ICUNIT_GOTO_EQUAL(g_testCount, 10, g_testCount, EXIT); /* 10: Twice per thread */ +EXIT: + return NULL; +} + +static int TestCase(void) +{ + int policy; + pthread_attr_t attr; + pthread_t newTh; + struct sched_param schedParam = { 0 }; + int ret; + + ret = pthread_mutex_init(&g_pthread_mutex, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_cond_init(&g_pthread_cond, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_init(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_getschedparam(pthread_self(), &policy, &schedParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + schedParam.sched_priority -= 1; + ret = pthread_attr_setschedparam(&attr, &schedParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_create(&newTh, &attr, pthread_f06, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return 0; +} + +void ItTestPthreadCond003(void) +{ + TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_003", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/unittest/process/pthread/smoke/pthread_cond_test_004.cpp b/testsuites/unittest/process/pthread/smoke/pthread_cond_test_004.cpp new file mode 100644 index 00000000..65480312 --- /dev/null +++ b/testsuites/unittest/process/pthread/smoke/pthread_cond_test_004.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * 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_pthread_test.h" +static pthread_cond_t g_pthread_cond; +static pthread_mutex_t g_pthread_mutex; +#define TEST_THREAD_COUNT 5 + +static void *pthread_cond_func002(void *arg) +{ + int ret; + struct timespec ts; + + g_testCount++; + + ret = pthread_mutex_lock(&g_pthread_mutex); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += 2; /* 2: wait 2 seconds */ + + ret = pthread_cond_timedwait(&g_pthread_cond, &g_pthread_mutex, &ts); + ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT); + + ret = pthread_mutex_unlock(&g_pthread_mutex); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + g_testCount++; +EXIT: + return NULL; +} + +static VOID *pthread_f07(void *argument) +{ + int policy; + int ret; + int i; + pthread_attr_t attr; + struct sched_param schedParam = { 0 }; + pthread_t thread[TEST_THREAD_COUNT]; + + g_testCount = 0; + + ret = pthread_attr_init(&attr); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_getschedparam(pthread_self(), &policy, &schedParam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + schedParam.sched_priority -= 1; + ret = pthread_attr_setschedparam(&attr, &schedParam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + for (i = 0; i < TEST_THREAD_COUNT; i++) { + ret = pthread_create(&thread[i], &attr, pthread_cond_func002, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + } + + sleep(1); + + ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); /* 5: Five threads */ + + for (i = 0; i < TEST_THREAD_COUNT; i++) { + ret = pthread_join(thread[i], NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + } + + ICUNIT_GOTO_EQUAL(g_testCount, 10, g_testCount, EXIT); /* 10: Twice per thread */ + +EXIT: + return NULL; +} + +static int TestCase(void) +{ + int policy; + pthread_attr_t attr; + pthread_t newTh; + struct sched_param schedParam = { 0 }; + int ret; + + ret = pthread_mutex_init(&g_pthread_mutex, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_cond_init(&g_pthread_cond, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_init(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_getschedparam(pthread_self(), &policy, &schedParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + schedParam.sched_priority -= 1; + ret = pthread_attr_setschedparam(&attr, &schedParam); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_create(&newTh, &attr, pthread_f07, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return 0; +} + +void ItTestPthreadCond004(void) +{ + TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_004", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/unittest/process/pthread/smoke/pthread_test_006.cpp b/testsuites/unittest/process/pthread/smoke/pthread_test_006.cpp index 460370e2..3846c74f 100644 --- a/testsuites/unittest/process/pthread/smoke/pthread_test_006.cpp +++ b/testsuites/unittest/process/pthread/smoke/pthread_test_006.cpp @@ -125,6 +125,8 @@ static int Testcase(void) ret = pthread_create(&newPthread[index], &a, ThreadFuncTest2, &threadParam[index]); ICUNIT_ASSERT_EQUAL(ret, 0, ret); + sleep(1); + ICUNIT_ASSERT_EQUAL(g_testToCount001, testCount, g_testToCount001); index = 0; diff --git a/testsuites/unittest/process/pthread/smoke/pthread_test_009.cpp b/testsuites/unittest/process/pthread/smoke/pthread_test_009.cpp index 9fd1436f..bd1968b4 100644 --- a/testsuites/unittest/process/pthread/smoke/pthread_test_009.cpp +++ b/testsuites/unittest/process/pthread/smoke/pthread_test_009.cpp @@ -53,10 +53,6 @@ static UINT32 Testcase(VOID) #ifdef LOSCFG_USER_TEST_SMP sleep(1); #endif - - ret = pthread_join(g_th, NULL); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - ICUNIT_ASSERT_EQUAL(g_testCount, 2, g_testCount); // 2, assert the exit code. return 0; } diff --git a/testsuites/unittest/sys/It_test_sys.h b/testsuites/unittest/sys/It_test_sys.h index 80da9fad..4bc6ad5d 100644 --- a/testsuites/unittest/sys/It_test_sys.h +++ b/testsuites/unittest/sys/It_test_sys.h @@ -51,6 +51,8 @@ #define FE_UPWARD 0x800 #define FE_TOWARDZERO 0xc00 +extern CHAR *g_groupFileStream; +extern CHAR *g_passwdFileStream; extern VOID ItTestSys001(VOID); extern VOID IT_TEST_SYS_002(VOID); extern VOID IT_TEST_SYS_003(VOID); @@ -78,7 +80,7 @@ extern VOID ItTestSys024(VOID); extern VOID ItTestSys025(VOID); extern VOID ItTestSys026(VOID); extern VOID ItTestSys027(VOID); -extern VOID IT_TEST_SYS_028(VOID); +extern VOID ItTestSys028(VOID); extern VOID ItTestSys029(VOID); extern VOID IT_TEST_SYS_030(VOID); extern VOID IT_TEST_SYS_031(VOID); diff --git a/testsuites/unittest/sys/full/sys_test_018.cpp b/testsuites/unittest/sys/full/sys_test_018.cpp index eaa6f368..f6490a59 100644 --- a/testsuites/unittest/sys/full/sys_test_018.cpp +++ b/testsuites/unittest/sys/full/sys_test_018.cpp @@ -30,51 +30,66 @@ */ #include "It_test_sys.h" -static UINT32 TestCase(VOID) +STATIC UINT32 TestCase(VOID) { struct passwd *user1 = nullptr; struct passwd *user2 = nullptr; struct passwd *user3 = nullptr; struct passwd *user4 = nullptr; + INT32 ret; + CHAR *pathList[] = {"/etc/group", "/etc/passwd"}; + CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream}; + INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)}; + + ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */ + if (ret != 0) { + printf("error: need some env file, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; + } user1 = getpwnam("root"); - ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1); - ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1); + ICUNIT_GOTO_NOT_EQUAL(user1, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT); user2 = getpwnam("daemon"); - ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1); - ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1); + ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT); user3 = getpwnam("bin"); - ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1); - ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1); + ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT); user4 = getpwnam("lyw"); - ICUNIT_ASSERT_EQUAL(user4, nullptr, -1); + ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT); user4 = getpwnam(""); - ICUNIT_ASSERT_EQUAL(user4, nullptr, -1); + ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ return 0; +ERROUT: + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; } VOID ItTestSys018(VOID) diff --git a/testsuites/unittest/sys/full/sys_test_019.cpp b/testsuites/unittest/sys/full/sys_test_019.cpp index 464a2aad..2460ccda 100644 --- a/testsuites/unittest/sys/full/sys_test_019.cpp +++ b/testsuites/unittest/sys/full/sys_test_019.cpp @@ -30,7 +30,7 @@ */ #include "It_test_sys.h" -static UINT32 TestCase(VOID) +STATIC UINT32 TestCase(VOID) { struct passwd pwd; struct passwd *user1 = nullptr; @@ -38,61 +38,75 @@ static UINT32 TestCase(VOID) struct passwd *user3 = nullptr; struct passwd *user4 = nullptr; struct passwd *user5 = nullptr; - char buf1[1024] = { 0 }; - char buf2[2] = { 0 }; - int ret; + CHAR buf1[1024] = { 0 }; /* 1024, buffer for test */ + CHAR buf2[2] = { 0 }; /* 2, for test,this buffer is not enough large to save data */ + INT32 ret; + CHAR *pathList[] = {"/etc/group", "/etc/passwd"}; + CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream}; + INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)}; + + ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */ + if (ret != 0) { + printf("error: need some env file, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; + } ret = getpwnam_r("root", &pwd, buf1, sizeof(buf1), &user1); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1); - ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT); + ICUNIT_GOTO_NOT_EQUAL(user1, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_name, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(pwd.pw_uid, 0, -1); - ICUNIT_ASSERT_EQUAL(pwd.pw_gid, 0, -1); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_gecos, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_dir, "/root", -1); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_name, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(pwd.pw_uid, 0, -1, ERROUT); + ICUNIT_GOTO_EQUAL(pwd.pw_gid, 0, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_gecos, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_dir, "/root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1, ERROUT); ret = getpwnam_r("daemon", &pwd, buf1, sizeof(buf1), &user2); - ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1); - ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1); + ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT); ret = getpwnam_r("bin", &pwd, buf1, sizeof(buf1), &user3); - ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1); - ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1); + ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT); ret = getpwnam_r("root", &pwd, buf2, sizeof(buf2), &user4); - ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret); - ICUNIT_ASSERT_EQUAL(user4, nullptr, -1); + ICUNIT_GOTO_EQUAL(ret, ERANGE, ret, ERROUT); + ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT); ret = getpwnam_r(nullptr, &pwd, buf1, sizeof(buf1), &user5); - ICUNIT_ASSERT_EQUAL(ret, 0, -1); + ICUNIT_GOTO_EQUAL(ret, 0, -1, ERROUT); ret = getpwnam_r("", &pwd, buf1, sizeof(buf1), &user5); - ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1); + ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT); ret = getpwnam_r("sssssss", &pwd, buf1, sizeof(buf1), &user5); - ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1); + ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ return 0; +ERROUT: + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; } VOID ItTestSys019(VOID) diff --git a/testsuites/unittest/sys/full/sys_test_020.cpp b/testsuites/unittest/sys/full/sys_test_020.cpp index 21d3508d..89438972 100644 --- a/testsuites/unittest/sys/full/sys_test_020.cpp +++ b/testsuites/unittest/sys/full/sys_test_020.cpp @@ -30,53 +30,68 @@ */ #include "It_test_sys.h" -static UINT32 TestCase(VOID) +STATIC UINT32 TestCase(VOID) { struct passwd *user1 = nullptr; struct passwd *user2 = nullptr; struct passwd *user3 = nullptr; struct passwd *user4 = nullptr; + INT32 ret; + CHAR *pathList[] = {"/etc/group", "/etc/passwd"}; + CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream}; + INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)}; + + ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */ + if (ret != 0) { + printf("error: need some env file, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; + } user1 = getpwuid(0); - ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1); - ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1); + ICUNIT_GOTO_NOT_EQUAL(user1, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT); user2 = getpwuid(1); - ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1); - ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1); + ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT); - user3 = getpwuid(2); - ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1); - ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1); + user3 = getpwuid(2); /* 2, from etc/group */ + ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT); user4 = getpwuid(200); - ICUNIT_ASSERT_EQUAL(user4, nullptr, -1); + ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT); user4 = getpwuid(-100); - ICUNIT_ASSERT_EQUAL(user4, nullptr, -1); + ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT); user4 = getpwuid(100000); - ICUNIT_ASSERT_EQUAL(user4, nullptr, -1); + ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ return 0; +ERROUT: + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; } VOID ItTestSys020(VOID) diff --git a/testsuites/unittest/sys/full/sys_test_021.cpp b/testsuites/unittest/sys/full/sys_test_021.cpp index 8a830bcc..03e07091 100644 --- a/testsuites/unittest/sys/full/sys_test_021.cpp +++ b/testsuites/unittest/sys/full/sys_test_021.cpp @@ -30,7 +30,7 @@ */ #include "It_test_sys.h" -static UINT32 TestCase(VOID) +STATIC UINT32 TestCase(VOID) { struct passwd pwd; struct passwd *user1 = nullptr; @@ -38,69 +38,83 @@ static UINT32 TestCase(VOID) struct passwd *user3 = nullptr; struct passwd *user4 = nullptr; struct passwd *user5 = nullptr; - char buf1[1024] = { 0 }; - char buf2[2] = { 0 }; - int ret; + CHAR buf1[1024] = { 0 }; /* 1024, buffer for test */ + CHAR buf2[2] = { 0 }; /* 2, for test,this buffer is not enough large to save data */ + INT32 ret; + CHAR *pathList[] = {"/etc/group", "/etc/passwd"}; + CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream}; + INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)}; + + ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */ + if (ret != 0) { + printf("error: need some env file, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; + } ret = getpwuid_r(0, &pwd, buf1, sizeof(buf1), &user1); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1); - ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT); + ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_name, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(pwd.pw_uid, 0, -1); - ICUNIT_ASSERT_EQUAL(pwd.pw_gid, 0, -1); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_gecos, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_dir, "/root", -1); - ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_name, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(pwd.pw_uid, 0, -1, ERROUT); + ICUNIT_GOTO_EQUAL(pwd.pw_gid, 0, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_gecos, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_dir, "/root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1, ERROUT); ret = getpwuid_r(1, &pwd, buf1, sizeof(buf1), &user2); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1); - ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT); + ICUNIT_GOTO_NOT_EQUAL(user2, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user2->pw_uid, 1, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user2->pw_gid, 1, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_gecos, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1, ERROUT); - ret = getpwuid_r(2, &pwd, buf1, sizeof(buf1), &user3); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); - ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1); - ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1); + ret = getpwuid_r(2, &pwd, buf1, sizeof(buf1), &user3); /* 2, from etc/group */ + ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT); + ICUNIT_GOTO_NOT_EQUAL(user3, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_name, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user3->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_EQUAL(user3->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_STRING_EQUAL(user3->pw_gecos, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_dir, "/bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1, ERROUT); ret = getpwuid_r(0, &pwd, buf2, sizeof(buf2), &user4); - ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret); - ICUNIT_ASSERT_EQUAL(user4, nullptr, -1); + ICUNIT_GOTO_EQUAL(ret, ERANGE, ret, ERROUT); + ICUNIT_GOTO_EQUAL(user4, nullptr, -1, ERROUT); - ret = getpwuid_r(200, &pwd, buf1, sizeof(buf1), &user5); - ICUNIT_ASSERT_EQUAL(user5, nullptr, -1); - ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1); + ret = getpwuid_r(200, &pwd, buf1, sizeof(buf1), &user5); /* 200, invalid param for test */ + ICUNIT_GOTO_EQUAL(user5, nullptr, -1, ERROUT); + ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT); - ret = getpwuid_r(100000, &pwd, buf1, sizeof(buf1), &user5); - ICUNIT_ASSERT_EQUAL(user5, nullptr, -1); - ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1); + ret = getpwuid_r(100000, &pwd, buf1, sizeof(buf1), &user5); /* 100000, invalid param for test */ + ICUNIT_GOTO_EQUAL(user5, nullptr, -1, ERROUT); + ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT); - ret = getpwuid_r(-100, &pwd, buf1, sizeof(buf1), &user5); - ICUNIT_ASSERT_EQUAL(user5, nullptr, -1); - ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1); + ret = getpwuid_r(-100, &pwd, buf1, sizeof(buf1), &user5); /* -100, invalid param for test */ + ICUNIT_GOTO_EQUAL(user5, nullptr, -1, ERROUT); + ICUNIT_GOTO_NOT_EQUAL(ret, 0, -1, ERROUT); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ return 0; +ERROUT: + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; } VOID ItTestSys021(VOID) diff --git a/testsuites/unittest/sys/full/sys_test_022.cpp b/testsuites/unittest/sys/full/sys_test_022.cpp index ae28f530..fc9814ce 100644 --- a/testsuites/unittest/sys/full/sys_test_022.cpp +++ b/testsuites/unittest/sys/full/sys_test_022.cpp @@ -30,47 +30,64 @@ */ #include "It_test_sys.h" -static UINT32 TestCase(VOID) +STATIC UINT32 TestCase(VOID) { struct passwd *user1 = nullptr; struct passwd *user2 = nullptr; + INT32 ret; + CHAR *pathList[] = {"/etc/group", "/etc/passwd"}; + CHAR *streamList[] = {g_groupFileStream, g_passwdFileStream}; + INT32 streamLen[] = {strlen(g_groupFileStream), strlen(g_passwdFileStream)}; + + ret = PrepareFileEnv(pathList, streamList, streamLen, 2); /* 2, group & passwd */ + if (ret != 0) { + printf("error: need some env file, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; + } user1 = getpwent(); - ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1); - ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1); + ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_uid, 0, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_gid, 0, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1, ERROUT); user1 = getpwent(); - ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user1->pw_uid, 1, -1); - ICUNIT_ASSERT_EQUAL(user1->pw_gid, 1, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/usr/sbin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1); + ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_uid, 1, -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_gid, 1, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/usr/sbin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1, ERROUT); user1 = getpwent(); - ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(user1->pw_uid, 2, -1); - ICUNIT_ASSERT_EQUAL(user1->pw_gid, 2, -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1); + ICUNIT_GOTO_NOT_EQUAL(user1, NULL, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_name, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(user1->pw_uid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_EQUAL(user1->pw_gid, 2, -1, ERROUT); /* 2, from etc/group */ + ICUNIT_GOTO_STRING_EQUAL(user1->pw_gecos, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_dir, "/bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1, ERROUT); setpwent(); user2 = getpwent(); - ICUNIT_ASSERT_NOT_EQUAL(user2, NULL, -1); - ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, user1->pw_name, -1); + ICUNIT_GOTO_NOT_EQUAL(user2, NULL, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(user2->pw_name, user1->pw_name, -1, ERROUT); + setpwent(); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ return 0; +ERROUT: + setpwent(); + (VOID)RecoveryFileEnv(pathList, 2); /* 2, group & passwd */ + return -1; } VOID ItTestSys022(VOID) diff --git a/testsuites/unittest/sys/full/sys_test_023.cpp b/testsuites/unittest/sys/full/sys_test_023.cpp index 92f953c2..4972e261 100644 --- a/testsuites/unittest/sys/full/sys_test_023.cpp +++ b/testsuites/unittest/sys/full/sys_test_023.cpp @@ -31,39 +31,55 @@ #include "It_test_sys.h" #include "grp.h" -static UINT32 TestCase(VOID) +STATIC UINT32 TestCase(VOID) { struct group *grp1 = nullptr; struct group *grp2 = nullptr; struct group *grp3 = nullptr; struct group *grp4 = nullptr; + INT32 ret; + CHAR *pathList[] = {"/etc/group"}; + CHAR *streamList[] = {g_groupFileStream}; + INT32 streamLen[] = {strlen(g_groupFileStream)}; + + ret = PrepareFileEnv(pathList, streamList, streamLen, 1); + if (ret != 0) { + printf("error: need some env file, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 1); + return -1; + } grp1 = getgrent(); - ICUNIT_ASSERT_NOT_EQUAL(grp1, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_name, "root", -1); - ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(grp1->gr_gid, 0, -1); + ICUNIT_GOTO_NOT_EQUAL(grp1, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(grp1->gr_name, "root", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(grp1->gr_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(grp1->gr_gid, 0, -1, ERROUT); grp2 = getgrent(); - ICUNIT_ASSERT_NOT_EQUAL(grp2, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(grp2->gr_name, "daemon", -1); - ICUNIT_ASSERT_STRING_EQUAL(grp2->gr_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(grp2->gr_gid, 1, -1); + ICUNIT_GOTO_NOT_EQUAL(grp2, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(grp2->gr_name, "daemon", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(grp2->gr_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(grp2->gr_gid, 1, -1, ERROUT); grp3 = getgrent(); - ICUNIT_ASSERT_NOT_EQUAL(grp3, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(grp3->gr_name, "bin", -1); - ICUNIT_ASSERT_STRING_EQUAL(grp3->gr_passwd, "x", -1); - ICUNIT_ASSERT_EQUAL(grp3->gr_gid, 2, -1); + ICUNIT_GOTO_NOT_EQUAL(grp3, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(grp3->gr_name, "bin", -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(grp3->gr_passwd, "x", -1, ERROUT); + ICUNIT_GOTO_EQUAL(grp3->gr_gid, 2, -1, ERROUT); /* 2, from etc/group */ setgrent(); grp4 = getgrent(); - ICUNIT_ASSERT_NOT_EQUAL(grp4, nullptr, -1); - ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_name, grp4->gr_name, -1); + ICUNIT_GOTO_NOT_EQUAL(grp4, nullptr, -1, ERROUT); + ICUNIT_GOTO_STRING_EQUAL(grp1->gr_name, grp4->gr_name, -1, ERROUT); setgrent(); + (VOID)RecoveryFileEnv(pathList, 1); return 0; +ERROUT: + setgrent(); + (VOID)RecoveryFileEnv(pathList, 1); + return -1; } VOID ItTestSys023(VOID) diff --git a/testsuites/unittest/sys/full/sys_test_025.cpp b/testsuites/unittest/sys/full/sys_test_025.cpp index 0a2d4343..95ea0554 100644 --- a/testsuites/unittest/sys/full/sys_test_025.cpp +++ b/testsuites/unittest/sys/full/sys_test_025.cpp @@ -34,17 +34,17 @@ #define GROUPFILE "/etc/group" -static int TestCase0(void) +STATIC INT32 TestCase0(void) { struct group getNam1 = { nullptr }; struct group *getNam2 = nullptr; struct group getData1 = { nullptr }; struct group *getData2 = nullptr; struct group *groupRet = nullptr; - char buf[1000]; - size_t len = 1000; + CHAR buf[1000]; /* 1000, buffer for test */ + size_t len = sizeof(buf); - int ret = getgrgid_r(0, &getNam1, buf, len, &getNam2); + INT32 ret = getgrgid_r(0, &getNam1, buf, len, &getNam2); ICUNIT_ASSERT_EQUAL(ret, 0, ret); ICUNIT_ASSERT_NOT_EQUAL(getNam2, nullptr, getNam2); @@ -73,17 +73,17 @@ static int TestCase0(void) return 0; } -static int TestCase1(void) +STATIC INT32 TestCase1(void) { - int len = 1000; - char buf[1000]; + INT32 len = 1000; + CHAR buf[1000]; struct group getNam1 = { nullptr }; struct group *getNam2 = nullptr; struct group getData1 = { nullptr }; struct group *getData2 = nullptr; struct group *groupRet = nullptr; - int ret = getgrgid_r(-1, &getNam1, buf, len, &getNam2); + INT32 ret = getgrgid_r(-1, &getNam1, buf, len, &getNam2); ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret); ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno); errno = 0; @@ -103,39 +103,33 @@ static int TestCase1(void) ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno); errno = 0; - remove(GROUPFILE); - - ret = getgrgid_r(0, &getNam1, buf, len, &getNam2); - ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret); - ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno); - errno = 0; - - groupRet = getgrgid(0); - ICUNIT_ASSERT_EQUAL(groupRet, 0, ret); - ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno); - errno = 0; - - groupRet = getgrnam("root"); - ICUNIT_ASSERT_EQUAL(groupRet, 0, ret); - ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno); - errno = 0; - - ret = getgrnam_r("root", &getData1, buf, len, &getData2); - ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret); - ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno); - return 0; } -static int TestCase(void) +STATIC INT32 TestCase(void) { - int ret = TestCase0(); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); + CHAR *pathList[] = {"/etc/group"}; + CHAR *streamList[] = {g_groupFileStream}; + INT32 streamLen[] = {strlen(g_groupFileStream)}; + + INT32 ret = PrepareFileEnv(pathList, streamList, streamLen, 1); + if (ret != 0) { + printf("error: need some env file, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 1); + return -1; + } + + ret = TestCase0(); + ICUNIT_GOTO_EQUAL(ret, 0, ret, ERROUT); ret = TestCase1(); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_GOTO_EQUAL(ret, 0, re, ERROUT); + (VOID)RecoveryFileEnv(pathList, 1); return 0; +ERROUT: + (VOID)RecoveryFileEnv(pathList, 1); + return -1; } VOID ItTestSys025(VOID) diff --git a/testsuites/unittest/sys/full/sys_test_028.cpp b/testsuites/unittest/sys/full/sys_test_028.cpp index f2c7813a..c95d8d24 100644 --- a/testsuites/unittest/sys/full/sys_test_028.cpp +++ b/testsuites/unittest/sys/full/sys_test_028.cpp @@ -31,20 +31,30 @@ static UINT32 TestCase(VOID) { - int ret; + int ret, status; + pid_t pid = fork(); if (pid == 0) { + ret = setpriority(PRIO_PROCESS, 0, 15); /* 15, set priority for test */ + if (ret != 0) { + exit(0); + } ret = nice(0); - ICUNIT_ASSERT_EQUAL(ret, 15, ret); + exit(ret); } else { - ret = nice(-15); + ret = waitpid(pid, &status, 0); + ICUNIT_ASSERT_EQUAL(ret, pid, ret); + status = WEXITSTATUS(status); + ICUNIT_ASSERT_EQUAL(status, 15, status); /* 15, set priority for test */ + + ret = nice(-40); /* -40, set invaild priority for test */ ICUNIT_ASSERT_EQUAL(ret, -1, ret); ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno); } return 0; } -VOID IT_TEST_SYS_028(VOID) +VOID ItTestSys028(VOID) { - TEST_ADD_CASE(IT_TEST_SYS_028, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION); + TEST_ADD_CASE(ItTestSys028, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION); } diff --git a/testsuites/unittest/sys/sys_unit_test.cpp b/testsuites/unittest/sys/sys_unit_test.cpp index fc126673..48ee0b9c 100644 --- a/testsuites/unittest/sys/sys_unit_test.cpp +++ b/testsuites/unittest/sys/sys_unit_test.cpp @@ -34,6 +34,10 @@ #include "It_test_sys.h" +CHAR *g_groupFileStream = "root:x:0:\ndaemon:x:1:\nbin:x:2:\n"; +CHAR *g_passwdFileStream = "root:x:0:0:root:/root:/bin/bash\n" \ + "daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\nbin:x:2:2:bin:/bin:/usr/sbin/nologin\n"; + using namespace testing::ext; namespace OHOS { class SysTest : public testing::Test { @@ -343,14 +347,14 @@ HWTEST_F(SysTest, ItTestSys027, TestSize.Level0) } /* * - * @tc.name: IT_TEST_SYS_028 + * @tc.name: ItTestSys028 * @tc.desc: function for nice:set pthread priority * @tc.type: FUNC * @tc.require: AR000EEMQ9 */ -HWTEST_F(SysTest, IT_TEST_SYS_028, TestSize.Level0) +HWTEST_F(SysTest, ItTestSys028, TestSize.Level0) { - IT_TEST_SYS_028(); + ItTestSys028(); } #endif } // namespace OHOS diff --git a/zzz/git/push.sh b/zzz/git/push.sh index 13544c45..4da4ef94 100644 --- a/zzz/git/push.sh +++ b/zzz/git/push.sh @@ -1,5 +1,5 @@ git add -A -git commit -m ' 修改注解方式,支持doxygen格式 +git commit -m ' 同步官方仓库,本次改动不大,对process,task模块进行了微调 百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码 博客输出站点(国内):http://weharmonyos.com 博客输出站点(国外):https://weharmony.github.io -- GitLab