提交 042e87da 编写于 作者: 鸿蒙内核源码分析's avatar 鸿蒙内核源码分析

同步下官方源码,近半个月官方改动很小.

    百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码
    博客输出站点(国内):http://weharmonyos.com
    博客输出站点(国外):https://weharmony.github.io
    注解文件系统:https://gitee.com/weharmony/third_party_NuttX
    注解协议栈:https://gitee.com/weharmony/third_party_lwip
    注解编译子系统:https://gitee.com/weharmony/build_lite
上级 78590d52
子曰:“里仁为美。择不处仁,焉得知?”《论语》:里仁篇
[![在这里插入图片描述](https://gitee.com/weharmony/docs/raw/master/pic/other/io1.png)](http://weharmonyos.com/)
百篇博客系列篇.本篇为:
v13.xx 鸿蒙内核源码分析(源码注释篇) | 每天死磕一点点
前因后果相关篇为:
* [v08.03 鸿蒙内核源码分析(总目录) | 百万汉字注解 百篇博客分析](https://my.oschina.net/weharmony/blog/4626852)
......@@ -12,15 +14,15 @@ v13.xx 鸿蒙内核源码分析(源码注释篇) | 每天死磕一点点
* [v10.03 鸿蒙内核源码分析(内存主奴) | 皇上和奴才如何相处](https://my.oschina.net/weharmony/blog/4646802)
* [v13.05 鸿蒙内核源码分析(源码注释) | 每天死磕一点点](https://my.oschina.net/weharmony/blog/4686747)
* [v18.02 鸿蒙内核源码分析(源码结构) | 内核文件各自含义](https://my.oschina.net/weharmony/blog/4869137)
* [v52.05 鸿蒙内核源码分析(静态站点) | 五一哪也没去在干这事](https://my.oschina.net/weharmony/blog/5042657)
* [v52.05 鸿蒙内核源码分析(静态站点) | 码农都不爱写注释和文档](https://my.oschina.net/weharmony/blog/5042657)
#### 几点说明
### 几点说明
**中文注解鸿蒙内核 | [kernel_liteos_a_note](https://gitee.com/weharmony/kernel_liteos_a_note)**
是在 `OpenHarmony`[kernel_liteos_a](https://gitee.com/openharmony/kernel_liteos_a) 基础上给内核源码加上中文注解的版本.与官方源码按月保持同步,同步历史如下:
* `2021/10/09` -- 增加性能优化模块`perf`,优化了文件映射模块
* `2021/10/21` -- 增加性能优化模块`perf`,优化了文件映射模块
* `2021/09/14` -- common,extended等几个目录结构和Makefile调整
* `2021/08/19` -- 各目录增加了`BUILD.gn`文件,文件系统部分文件调整
* `2021/07/15` -- 改动不大,新增`blackbox`,`hidumper`,对一些宏规范化使用
......@@ -48,20 +50,20 @@ v13.xx 鸿蒙内核源码分析(源码注释篇) | 每天死磕一点点
* [文件系统 | NuttX](https://gitee.com/weharmony/third_party_NuttX)
* [标准库 | musl](https://gitee.com/weharmony/third_party_musl)
#### 为何要精读内核源码?
### 为何要精读内核源码?
* 码农的学职生涯,都应精读一遍内核源码。以浇筑好计算机知识大厦的地基,地基纵深的坚固程度,很大程度能决定未来大厦能盖多高。那为何一定要精读细品呢?
* 因为内核代码本身并不太多,都是浓缩的精华,精读是让各个知识点高频出现,不孤立成点状记忆,没有足够连接点的知识点是很容易忘的,点点成线,线面成体,连接越多,记得越牢,如此短时间内容易结成一张高浓度,高密度的系统化知识网,训练大脑肌肉记忆,驻入大脑直觉区,想抹都抹不掉,终生携带,随时调取。跟骑单车一样,一旦学会,即便多年不骑,照样跨上就走,游刃有余。
#### 热爱是所有的理由和答案
### 热爱是所有的理由和答案
* 因大学时阅读 `linux 2.6` 内核痛并快乐的经历,一直有个心愿,如何让更多对内核感兴趣的朋友减少阅读时间,加速对计算机系统级的理解,而不至于过早的放弃。但因过程种种,多年一直没有行动,基本要放弃这件事了。恰逢 `2020/9/10` 鸿蒙正式开源,重新激活了多年的心愿,就有那么点如黄河之水一发不可收拾了。
* 目前对内核源码的注解已完成了 `70%` ,对内核源码的博客分析已完成了`70+篇`, 每天都很充实,很兴奋,连做梦内核代码都在鱼贯而入。如此疯狂地做一件事还是当年谈恋爱的时候, 只因热爱, 热爱是所有的理由和答案。 :P
#### (〃・ิ‿・ิ)ゞ鸿蒙内核开发者
### (〃・ิ‿・ิ)ゞ鸿蒙内核开发者
* 感谢开放原子开源基金会,致敬鸿蒙内核开发者提供了如此优秀的源码,一了多年的夙愿,津津乐道于此。精读内核源码加注并整理成档是件很有挑战的事,时间上要以月甚至年为单位,但正因为很难才值得去做! 干困难事,方有所得;专注聚焦,必有所获。
* 从内核一行行的代码中能深深感受到开发者各中艰辛与坚持,及鸿蒙生态对未来的价值,这些是张嘴就来的网络喷子们永远不能体会到的。可以毫不夸张的说鸿蒙内核源码可作为大学: C语言,数据结构,操作系统,汇编语言,计算机系统结构,计算机组成原理 六门课程的教学项目。如此宝库,不深入研究实在是暴殄天物,于心不忍,注者坚信鸿蒙大势所趋,未来可期,其必定成功,也必然成功,誓做其坚定的追随者和传播者。
#### 理解内核的三个层级
### 理解内核的三个层级
* 普通概念映射级: 这一级不涉及专业知识,用大众所熟知的公共认知就能听明白是个什么概念,也就是说用一个普通人都懂的概念去诠释或者映射一个他们从没听过的概念。让陌生的知识点与大脑中烂熟于心的知识点建立多重链接,加深记忆。说别人能听得懂的话这很重要!!! 一个没学过计算机知识的卖菜大妈就不可能知道内核的基本运作了吗? 不一定!在系列篇中试图用 v08.xx 鸿蒙内核源码分析(总目录) 之故事篇 去引导这一层级的认知,希望能卷入更多的人来关注基础软件,尤其是那些资本大鳄,加大对基础软件的投入。
* 专业概念抽象级: 对抽象的专业逻辑概念具体化认知, 比如虚拟内存,老百姓是听不懂的,学过计算机的人都懂,具体怎么实现的很多人又都不懂了,但这并不妨碍成为一个优秀的上层应用开发者,因为虚拟内存已经被抽象出来,目的是要屏蔽上层对它具体实现的认知。试图用 鸿蒙内核源码分析(总目录 去拆解那些已经被抽象出来的专业概念, 希望能卷入更多对内核感兴趣的应用软件人才流入基础软硬件生态, 应用软件咱们是无敌宇宙,但基础软件却很薄弱。
* 具体微观代码级: 这一级是具体到每一行代码的实现,到了用代码指令级的地步,这段代码是什么意思?为什么要这么设计?有没有更好的方案? [鸿蒙内核源码注解分析](https://gitee.com/weharmony/kernel_liteos_a_note) 试图从细微处去解释代码实现层,英文真的是天生适合设计成编程语言的人类语言,计算机的01码映射到人类世界的26个字母,诞生了太多的伟大奇迹。但我们的母语注定了很大部分人存在着自然语言层级的理解映射,希望鸿蒙内核源码注解分析能让更多爱好者快速的理解内核,共同进步。
#### 加注方式是怎样的?
### 加注方式是怎样的?
* 因鸿蒙内核6W+代码量,本身只有较少的注释, 中文注解以不对原有代码侵入为前提,源码中所有英文部分都是原有注释,所有中文部分都是中文版的注释,同时为方便同步官方版本的更新,尽量不去增加代码的行数,不破坏文件的结构,注释多类似以下的方式:
......@@ -78,7 +80,7 @@ v13.xx 鸿蒙内核源码分析(源码注释篇) | 每天死磕一点点
* 另外画了一些字符图方便理解,直接嵌入到头文件中,比如虚拟内存的全景图,因没有这些图是很难理解虚拟内存是如何管理的。
![在这里插入图片描述](https://gitee.com/weharmony/docs/raw/master/pic/other/vm.png)
#### 有哪些特殊的记号
### 有哪些特殊的记号
- [x] 搜索 `@note_pic` 可查看绘制的全部字符图
- [x] 搜索 `@note_why` 是尚未看明白的地方,有看明白的,请Pull Request完善
- [x] 搜索 `@note_thinking` 是一些的思考和建议
......@@ -86,7 +88,7 @@ v13.xx 鸿蒙内核源码分析(源码注释篇) | 每天死磕一点点
- [x] 搜索 `@note_link` 是网址链接,方便理解模块信息,来源于官方文档,百篇博客,外部链接
- [x] 搜索 `@note_good` 是给源码点赞的地方
#### 目录结构
### 目录结构
```
/kernel/liteos_a
├── apps # 用户态的init和shell应用程序
......@@ -129,7 +131,17 @@ v13.xx 鸿蒙内核源码分析(源码注释篇) | 每天死磕一点点
# 它与内核代码无关,大家可以忽略它,取名zzz是为了排在最后,减少对原有代码目录级的侵入,
# zzz 的想法源于微信中名称为AAA的那帮朋友,你的微信里应该也有他们熟悉的身影吧 :|P
```
#### **百篇博客分析.深挖内核地基**
### **参与贡献**
* [新建 Pull Request](https://gitee.com/weharmony/kernel_liteos_a_note/pull/new/weharmony:master...weharmony:master)
* [新建 Issue](https://gitee.com/weharmony/kernel_liteos_a_note/issues)
### 微信 | QQ 群
前往 >> [http://weharmonyos.com/qun.html](http://weharmonyos.com/qun.html)
### 捐赠记录,再次感谢!!!
前往 >> [http://weharmonyos.com/donate.html](http://weharmonyos.com/donate.html)
### **百篇博客分析.深挖内核地基**
* 给鸿蒙内核源码加注释过程中,整理出以下文章。内容立足源码,常以生活场景打比方尽可能多的将内核知识点置入某种场景,具有画面感,容易理解记忆。说别人能听得懂的话很重要! 百篇博客绝不是百度教条式的在说一堆诘屈聱牙的概念,那没什么意思。更希望让内核变得栩栩如生,倍感亲切.确实有难度,自不量力,但已经出发,回头已是不可能的了。 😛
* 与代码有bug需不断debug一样,文章和注解内容会存在不少错漏之处,请多包涵,但会反复修正,持续更新,v**.xx 代表文章序号和修改的次数,精雕细琢,言简意赅,力求打造精品内容。
......@@ -186,7 +198,7 @@ v13.xx 鸿蒙内核源码分析(源码注释篇) | 每天死磕一点点
* [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)
* [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)
......@@ -206,26 +218,25 @@ v13.xx 鸿蒙内核源码分析(源码注释篇) | 每天死磕一点点
* [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/5269307)
* [v72.01 鸿蒙内核源码分析(Shell解析) | 应用窥伺内核的窗口](https://my.oschina.net/weharmony/blog/5282207)
按功能模块:
|前因后果|基础工具|加载运行|进程管理
|:-:|:-:|:-:|:-:|
[总目录](https://my.oschina.net/weharmony/blog/4626852) [调度故事](https://my.oschina.net/weharmony/blog/4634668) [内存主奴](https://my.oschina.net/weharmony/blog/4646802) [源码注释](https://my.oschina.net/weharmony/blog/4686747) [源码结构](https://my.oschina.net/weharmony/blog/4869137) [静态站点](https://my.oschina.net/weharmony/blog/5042657) |[双向链表](https://my.oschina.net/weharmony/blog/4572304) [位图管理](https://my.oschina.net/weharmony/blog/4888467) [用栈方式](https://my.oschina.net/weharmony/blog/4893388) [定时器](https://my.oschina.net/weharmony/blog/4951625) [原子操作](https://my.oschina.net/weharmony/blog/4955290) [时间管理](https://my.oschina.net/weharmony/blog/4956163) |[ELF格式](https://my.oschina.net/weharmony/blog/5030288) [ELF解析](https://my.oschina.net/weharmony/blog/5048746) [静态链接](https://my.oschina.net/weharmony/blog/5049918) [重定位](https://my.oschina.net/weharmony/blog/5055124) [进程映像](https://my.oschina.net/weharmony/blog/5060359) |[进程管理](https://my.oschina.net/weharmony/blog/4574429) [进程概念](https://my.oschina.net/weharmony/blog/4937521) [Fork](https://my.oschina.net/weharmony/blog/5010301) [特殊进程](https://my.oschina.net/weharmony/blog/5014444) [进程回收](https://my.oschina.net/weharmony/blog/5017716) [信号生产](https://my.oschina.net/weharmony/blog/5022149) [信号消费](https://my.oschina.net/weharmony/blog/5027224) [Shell编辑](https://my.oschina.net/weharmony/blog/5269307) [Shell解析](https://my.oschina.net/weharmony/blog/5269307) |
[总目录](https://my.oschina.net/weharmony/blog/4626852) [调度故事](https://my.oschina.net/weharmony/blog/4634668) [内存主奴](https://my.oschina.net/weharmony/blog/4646802) [源码注释](https://my.oschina.net/weharmony/blog/4686747) [源码结构](https://my.oschina.net/weharmony/blog/4869137) [静态站点](https://my.oschina.net/weharmony/blog/5042657) |[双向链表](https://my.oschina.net/weharmony/blog/4572304) [位图管理](https://my.oschina.net/weharmony/blog/4888467) [用栈方式](https://my.oschina.net/weharmony/blog/4893388) [定时器](https://my.oschina.net/weharmony/blog/4951625) [原子操作](https://my.oschina.net/weharmony/blog/4955290) [时间管理](https://my.oschina.net/weharmony/blog/4956163) |[ELF格式](https://my.oschina.net/weharmony/blog/5030288) [ELF解析](https://my.oschina.net/weharmony/blog/5048746) [静态链接](https://my.oschina.net/weharmony/blog/5049918) [重定位](https://my.oschina.net/weharmony/blog/5055124) [进程映像](https://my.oschina.net/weharmony/blog/5060359) |[进程管理](https://my.oschina.net/weharmony/blog/4574429) [进程概念](https://my.oschina.net/weharmony/blog/4937521) [Fork](https://my.oschina.net/weharmony/blog/5010301) [特殊进程](https://my.oschina.net/weharmony/blog/5014444) [进程回收](https://my.oschina.net/weharmony/blog/5017716) [信号生产](https://my.oschina.net/weharmony/blog/5022149) [信号消费](https://my.oschina.net/weharmony/blog/5027224) [Shell编辑](https://my.oschina.net/weharmony/blog/5269307) [Shell解析](https://my.oschina.net/weharmony/blog/5282207) |
|编译构建|进程通讯|内存管理|任务管理
[编译环境](https://my.oschina.net/weharmony/blog/5028613) [编译过程](https://my.oschina.net/weharmony/blog/5064209) [环境脚本](https://my.oschina.net/weharmony/blog/5132725) [构建工具](https://my.oschina.net/weharmony/blog/5135157) [gn应用](https://my.oschina.net/weharmony/blog/5137565) [忍者ninja](https://my.oschina.net/weharmony/blog/5139034) |[自旋锁](https://my.oschina.net/weharmony/blog/4944129) [互斥锁](https://my.oschina.net/weharmony/blog/4945465) [进程通讯](https://my.oschina.net/weharmony/blog/4947398) [信号量](https://my.oschina.net/weharmony/blog/4949720) [事件控制](https://my.oschina.net/weharmony/blog/4950956) [消息队列](https://my.oschina.net/weharmony/blog/4952961) |[内存分配](https://my.oschina.net/weharmony/blog/4646802) [内存管理](https://my.oschina.net/weharmony/blog/4652284) [内存汇编](https://my.oschina.net/weharmony/blog/4692156) [内存映射](https://my.oschina.net/weharmony/blog/4694841) [内存规则](https://my.oschina.net/weharmony/blog/4698384) [物理内存](https://my.oschina.net/weharmony/blog/4842408) |[时钟任务](https://my.oschina.net/weharmony/blog/4574493) [任务调度](https://my.oschina.net/weharmony/blog/4595539) [任务管理](https://my.oschina.net/weharmony/blog/4603919) [调度队列](https://my.oschina.net/weharmony/blog/4606916) [调度机制](https://my.oschina.net/weharmony/blog/4623040) [线程概念](https://my.oschina.net/weharmony/blog/4915543) [并发并行](https://my.oschina.net/weharmony/blog/4940329) [CPU](https://my.oschina.net/weharmony/blog/4952034) [系统调用](https://my.oschina.net/weharmony/blog/4967613) [任务切换](https://my.oschina.net/weharmony/blog/4988628) |
|文件系统|硬件架构
[文件概念](https://my.oschina.net/weharmony/blog/5152858) [文件系统](https://my.oschina.net/weharmony/blog/5165752) [索引节点](https://my.oschina.net/weharmony/blog/5168716) [挂载目录](https://my.oschina.net/weharmony/blog/5172566) [根文件系统](https://my.oschina.net/weharmony/blog/5177087) [字符设备](https://my.oschina.net/weharmony/blog/5200946) [VFS](https://my.oschina.net/weharmony/blog/5211662) [文件句柄](https://my.oschina.net/weharmony/blog/5253251) [管道文件](https://my.oschina.net/weharmony/blog/5258434) |[汇编基础](https://my.oschina.net/weharmony/blog/4920361) [汇编传参](https://my.oschina.net/weharmony/blog/4927892) [工作模式](https://my.oschina.net/weharmony/blog/4965052) [寄存器](https://my.oschina.net/weharmony/blog/4969487) [异常接管](https://my.oschina.net/weharmony/blog/4973016) [汇编汇总](https://my.oschina.net/weharmony/blog/4977924) [中断切换](https://my.oschina.net/weharmony/blog/4990948) [中断概念](https://my.oschina.net/weharmony/blog/4992750) [中断管理](https://my.oschina.net/weharmony/blog/4995800) |
#### **百万汉字注解.精读内核源码**
### **百万汉字注解.精读内核源码**
四大码仓中文注解 . 定期同步官方代码
[![WeHarmony/kernel_liteos_a_note](https://gitee.com/weharmony/kernel_liteos_a_note/widgets/widget_card.svg?colors=4183c4,ffffff,ffffff,e3e9ed,666666,9b9b9b)](https://gitee.com/weharmony/kernel_liteos_a_note)
#### **关注不迷路.代码即人生**
鸿蒙研究站( weharmonyos ) | 每天死磕一点点,原创不易,欢迎转载,请注明出处。若能支持点赞则更佳,感谢每一份支持。
### **关注不迷路.代码即人生**
![鸿蒙内核源码分析](https://gitee.com/weharmony/docs/raw/master/pic/other/so1so.png)
**QQ群 790015635 | 入群密码 666**
鸿蒙研究站( weharmonyos ) | 每天死磕一点点,原创不易,欢迎转载,请注明出处。若能支持点赞则更佳,感谢每一份支持。
\ No newline at end of file
......@@ -626,7 +626,7 @@ int fatfs_open(struct file *filep)
FIL *fp;
int ret;
fp = (FIL *)zalloc(sizeof(FIL));
fp = (FIL *)zalloc(sizeof(FIL) + SS(fs));
if (fp == NULL) {
ret = ENOMEM;
goto ERROR_EXIT;
......@@ -650,19 +650,13 @@ int fatfs_open(struct file *filep)
fp->err = 0;
fp->sect = 0;
fp->fptr = 0;
fp->buf = (BYTE*) ff_memalloc(SS(fs));
if (fp->buf == NULL) {
ret = ENOMEM;
goto ERROR_UNLOCK;
}
fp->buf = (BYTE *)fp + sizeof(FIL);
LOS_ListAdd(&finfo->fp_list, &fp->fp_entry);
unlock_fs(fs, FR_OK);
filep->f_priv = fp;
return fatfs_sync(vp->originMount->mountFlags, fs);
return 0;
ERROR_UNLOCK:
unlock_fs(fs, FR_OK);
ERROR_FREE:
free(fp);
ERROR_EXIT:
......@@ -692,7 +686,6 @@ int fatfs_close(struct file *filep)
}
#endif
LOS_ListDelete(&fp->fp_entry);
ff_memfree(fp->buf);
free(fp);
filep->f_priv = NULL;
EXIT:
......
......@@ -224,6 +224,7 @@ int VnodeDevInit(void);
int VnodeAlloc(struct VnodeOps *vop, struct Vnode **vnode);
int VnodeFree(struct Vnode *vnode);
int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags);
int VnodeLookupFullpath(const char *fullpath, struct Vnode **vnode, uint32_t flags);
int VnodeLookupAt(const char *path, struct Vnode **vnode, uint32_t flags, struct Vnode *orgVnode);
int VnodeHold(void);
int VnodeDrop(void);
......
......@@ -423,7 +423,7 @@ int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struc
}
}
if (normalizedPath[0] == '/' && normalizedPath[1] == '\0') {//如果是根节点
if (normalizedPath[1] == '\0' && normalizedPath[0] == '/') {
*result = g_rootVnode;//啥也不说了,还找啥呀,直接返回根节点
free(normalizedPath);
return LOS_OK;
......@@ -469,7 +469,6 @@ int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struc
currentVnode->filePath[vnodePathLen] = 0;
}
}
return ret;
OUT_FREE_PATH:
if (normalizedPath) {
......@@ -484,6 +483,10 @@ int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags)
return VnodeLookupAt(path, vnode, flags, NULL);
}
//根节点内部改变
int VnodeLookupFullpath(const char *fullpath, struct Vnode **vnode, uint32_t flags)
{
return VnodeLookupAt(fullpath, vnode, flags, g_rootVnode);
}
static void ChangeRootInternal(struct Vnode *rootOld, char *dirname)
{
......
......@@ -352,6 +352,11 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
OsCurrProcessGet()->processID, processCB->processID);
}
#ifdef LOSCFG_KERNEL_VM
if (OsProcessIsUserMode(processCB)) {
(VOID)OsVmSpaceRegionFree(processCB->vmSpace);
}
#endif
#ifdef LOSCFG_FS_VFS
if (OsProcessIsUserMode(processCB)) {//用户进程
delete_files(processCB->files);//归还进程占用的进程描述符`profd`,如果是最后一个占用的系统描述符的进程,则同时归还系统文件描述符`sysfd`
......@@ -562,11 +567,11 @@ LITE_OS_SEC_TEXT VOID OsProcessCBRecycleToFree(VOID)
/* Clear the bottom 4 bits of process status */
OsInsertPCBToFreeList(processCB);//进程回到可分配池中,再分配利用
}
SCHEDULER_UNLOCK(intSave);
#ifdef LOSCFG_KERNEL_VM
SCHEDULER_UNLOCK(intSave);
(VOID)LOS_VmSpaceFree(space);//释放用户态进程的虚拟内存空间,因为内核只有一个虚拟空间,因此不需要释放虚拟空间.
#endif
SCHEDULER_LOCK(intSave);
#endif
}
SCHEDULER_UNLOCK(intSave);
......
......@@ -121,9 +121,9 @@ typedef struct ProcessCB {
TimerIdMap timerIdMap;
#endif
#ifdef LOSCFG_DRIVERS_TZDRIVER
struct file *execFile; /**< Exec bin of the process *///进程的可执行文件
struct Vnode *execVnode; /**< Exec bin of the process *///进程的可执行文件
#endif
mode_t umask;//umask(user file-creatiopn mode mask)为用户文件创建掩码,是创建文件或文件夹时默认权限的基础。
mode_t umask;//umask(user file-creatiopn mode mask)为用户文件创建掩码,是创建文件或文件夹时默认权限的基础。
#ifdef LOSCFG_KERNEL_CPUP
OsCpupBase processCpup; /**< Process cpu usage *///进程占用CPU情况统计
#endif
......
......@@ -316,6 +316,7 @@ LosVmSpace *OsCreateUserVmSpace(VOID);
STATUS_T LOS_VmSpaceClone(LosVmSpace *oldVmSpace, LosVmSpace *newVmSpace);
LosMux *OsGVmSpaceMuxGet(VOID);
STATUS_T OsUnMMap(LosVmSpace *space, VADDR_T addr, size_t size);
STATUS_T OsVmSpaceRegionFree(LosVmSpace *space);
/**
* thread safety
* it is used to malloc continuous virtual memory, no sure for continuous physical memory.
......
......@@ -525,7 +525,6 @@ STATIC INT32 OsFutexWaitParamCheck(const UINT32 *userVaddr, UINT32 flags, UINT32
}
if (!absTime) {
PRINT_ERR("Futex wait param check failed! error absTime: %u\n", absTime);
return LOS_EINVAL;
}
......
......@@ -852,14 +852,48 @@ ERR_REGION_SPLIT:
(VOID)LOS_MuxRelease(&space->regionMux);
return status;
}
//释放虚拟空间,注意内核空间不能被释放掉,永驻内存
STATUS_T LOS_VmSpaceFree(LosVmSpace *space)
STATIC VOID OsVmSpaceAllRegionFree(LosVmSpace *space)
{
LosVmMapRegion *region = NULL;
LosRbNode *pstRbNode = NULL;
LosRbNode *pstRbNodeNext = NULL;
STATUS_T ret;
/* free all of the regions */
RB_SCAN_SAFE(&space->regionRbTree, pstRbNode, pstRbNodeNext)
LosVmMapRegion *region = (LosVmMapRegion *)pstRbNode;
if (region->range.size == 0) {
VM_ERR("space free, region: %#x flags: %#x, base:%#x, size: %#x",
region, region->regionFlags, region->range.base, region->range.size);
}
STATUS_T ret = LOS_RegionFree(space, region);
if (ret != LOS_OK) {
VM_ERR("free region error, space %p, region %p", space, region);
}
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNode, pstRbNodeNext)
return;
}
STATUS_T OsVmSpaceRegionFree(LosVmSpace *space)
{
if (space == NULL) {
return LOS_ERRNO_VM_INVALID_ARGS;
}
if (space == &g_kVmSpace) {
VM_ERR("try to free kernel aspace, not allowed");
return LOS_OK;
}
(VOID)LOS_MuxAcquire(&space->regionMux);
OsVmSpaceAllRegionFree(space);
(VOID)LOS_MuxRelease(&space->regionMux);
return LOS_OK;
}
//释放虚拟空间,注意内核空间不能被释放掉,永驻内存
STATUS_T LOS_VmSpaceFree(LosVmSpace *space)
{
if (space == NULL) {
return LOS_ERRNO_VM_INVALID_ARGS;
}
......@@ -872,18 +906,8 @@ STATUS_T LOS_VmSpaceFree(LosVmSpace *space)
/* pop it out of the global aspace list */
(VOID)LOS_MuxAcquire(&space->regionMux);
LOS_ListDelete(&space->node);//从g_vmSpaceList链表里删除,g_vmSpaceList记录了所有空间节点。
/* free all of the regions */
RB_SCAN_SAFE(&space->regionRbTree, pstRbNode, pstRbNodeNext)//释放空间中所有线性区 ,RB_SCAN_SAFE是个for循环宏
region = (LosVmMapRegion *)pstRbNode;
if (region->range.size == 0) {
VM_ERR("space free, region: %#x flags: %#x, base:%#x, size: %#x",
region, region->regionFlags, region->range.base, region->range.size);
}
ret = LOS_RegionFree(space, region);//
if (ret != LOS_OK) {
VM_ERR("free region error, space %p, region %p", space, region);
}
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNode, pstRbNodeNext)
OsVmSpaceAllRegionFree(space);
/* make sure the current thread does not map the aspace */
LosProcessCB *currentProcess = OsCurrProcessGet();
......
......@@ -1442,8 +1442,6 @@ BOOL ConsoleEnable(VOID)
if (g_uart_fputc_en == 0) {
if ((g_console[CONSOLE_TELNET - 1] != NULL) && OsPreemptable()) {
return TRUE;
} else {
return FALSE;
}
}
......@@ -1560,8 +1558,6 @@ INT32 ConsoleUpdateFd(VOID)
if (g_uart_fputc_en == 0) {
if (g_console[CONSOLE_TELNET - 1] != NULL) {
consoleID = CONSOLE_TELNET;
} else {
return -1;
}
} else if (consoleID == 0) {
if (g_console[CONSOLE_SERIAL - 1] != NULL) {
......
......@@ -279,7 +279,9 @@ VOID LOS_LkPrint(INT32 level, const CHAR *func, INT32 line, const CHAR *fmt, ...
}
if ((level != LOS_COMMON_LEVEL) && ((level > LOS_EMG_LEVEL) && (level <= LOS_TRACE_LEVEL))) {
dprintf("[%s]", g_logString[level]);//日志格式,先打印日志头 INFO .....
dprintf("[%s][%s:%s]", g_logString[level],
((OsCurrProcessGet() == NULL) ? "NULL" : OsCurrProcessGet()->processName),
((OsCurrTaskGet() == NULL) ? "NULL" : OsCurrTaskGet()->taskName));
}
va_start(ap, fmt);
......
......@@ -47,10 +47,12 @@
#include "tzdriver.h"
#endif
static int OsELFOpen(const CHAR *fileName, INT32 oflags)
STATIC BOOL g_srandInit;
STATIC INT32 OsELFOpen(const CHAR *fileName, INT32 oflags)
{
int ret = -LOS_NOK;
int procFd;
INT32 ret = -LOS_NOK;
INT32 procFd;
procFd = AllocProcessFd();
if (procFd < 0) {
......@@ -71,11 +73,11 @@ static int OsELFOpen(const CHAR *fileName, INT32 oflags)
return procFd;
}
static int OsELFClose(int procFd)
STATIC INT32 OsELFClose(INT32 procFd)
{
int ret;
INT32 ret;
/* Process procfd convert to system global procfd */
int sysfd = DisassociateProcessFd(procFd);
INT32 sysfd = DisassociateProcessFd(procFd);
if (sysfd < 0) {
return -EBADF;
}
......@@ -223,12 +225,14 @@ STATIC INT32 OsReadEhdr(const CHAR *fileName, ELFInfo *elfInfo, BOOL isExecFile)
#ifdef LOSCFG_DRIVERS_TZDRIVER
if (isExecFile) {
ret = fs_getfilep(GetAssociatedSystemFd(elfInfo->procfd), &OsCurrProcessGet()->execFile);
struct file *filep;
ret = fs_getfilep(GetAssociatedSystemFd(elfInfo->procfd), &filep);
if (ret) {
PRINT_ERR("%s[%d], Failed to get struct file %s!\n", __FUNCTION__, __LINE__, fileName);
/* File will be closed by OsLoadELFFile */
return ret;
}
OsCurrProcessGet()->execVnode = filep->f_vnode;
}
#endif
ret = OsReadELFInfo(elfInfo->procfd, (UINT8 *)&elfInfo->elfEhdr, sizeof(LD_ELF_EHDR), 0);
......@@ -720,7 +724,7 @@ STATIC UINT32 OsGetRndOffset(const ELFLoadInfo *loadInfo)
if (read(loadInfo->randomDevFD, &randomValue, sizeof(UINT32)) == sizeof(UINT32)) {
randomValue &= RANDOM_MASK;
} else {
randomValue = 0;
randomValue = (UINT32)random() & RANDOM_MASK;
}
#else
(VOID)loadInfo;
......@@ -791,7 +795,10 @@ STATIC INT32 OsSetArgParams(ELFLoadInfo *loadInfo, CHAR *const *argv, CHAR *cons
loadInfo->randomDevFD = open("/dev/urandom", O_RDONLY);
if (loadInfo->randomDevFD < 0) {
PRINT_ERR("%s: open /dev/urandom failed\n", __FUNCTION__);
if (!g_srandInit) {
srand((UINT32)time(NULL));
g_srandInit = TRUE;
}
}
(VOID)OsGetStackProt(loadInfo);
......@@ -879,7 +886,8 @@ STATIC INT32 OsGetRndNum(const ELFLoadInfo *loadInfo, UINT32 *rndVec, UINT32 vec
for (i = 0; i < vecSize; ++i) {
ret = read(loadInfo->randomDevFD, &randomValue, sizeof(UINT32));
if (ret != sizeof(UINT32)) {
return -EIO;
rndVec[i] = (UINT32)random();
continue;
}
rndVec[i] = randomValue;
}
......
......@@ -211,7 +211,7 @@ STATIC VOID LOS_TraceSwtmrExpired(const SWTMR_CTRL_S *swtmr)
STATIC VOID LOS_TraceSwtmrStart(const SWTMR_CTRL_S *swtmr)
{
LOS_TRACE(SWTMR_START, swtmr->usTimerID, swtmr->ucMode, swtmr->uwCount, swtmr->uwInterval, 0);
LOS_TRACE(SWTMR_START, swtmr->usTimerID, swtmr->ucMode, swtmr->uwInterval);
}
STATIC VOID LOS_TraceSwtmrStop(const SWTMR_CTRL_S *swtmr)
......
......@@ -265,10 +265,15 @@ STATIC UINT32 OsTraceInit(VOID)
}
#endif
#ifdef LOSCFG_RECORDER_MODE_OFFLINE
ret = OsTraceBufInit(LOSCFG_TRACE_BUFFER_SIZE);
if (ret != LOS_OK) {
goto LOS_RELEASE;
#ifdef LOSCFG_TRACE_CONTROL_AGENT
(VOID)LOS_TaskDelete(g_traceTaskId);
#endif
goto LOS_ERREND;
}
#endif
OsTraceHookInstall();
OsTraceCnvInit();
......@@ -283,10 +288,6 @@ STATIC UINT32 OsTraceInit(VOID)
g_traceState = TRACE_STARTED;
#endif
return LOS_OK;
LOS_RELEASE:
#ifdef LOSCFG_TRACE_CONTROL_AGENT
LOS_TaskDelete(g_traceTaskId);
#endif
LOS_ERREND:
return ret;
}
......
......@@ -120,7 +120,6 @@ typedef struct {
extern UINT32 OsTraceGetMaskTid(UINT32 taskId);
extern VOID OsTraceSetObj(ObjData *obj, const LosTaskCB *tcb);
extern VOID OsTraceWriteOrSendEvent(const TraceEventFrame *frame);
extern UINT32 OsTraceBufInit(UINT32 size);
extern VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId);
extern BOOL OsTraceIsEnable(VOID);
extern OfflineHead *OsTraceRecordGet(VOID);
......@@ -143,6 +142,7 @@ extern VOID OsTraceSendNotify(UINT32 type, UINT32 value);
#define OsTraceReset()
#define OsTraceRecordDump(toClient)
#else
extern UINT32 OsTraceBufInit(UINT32 size);
extern VOID OsTraceReset(VOID);
extern VOID OsTraceRecordDump(BOOL toClient);
#define OsTraceNotifyStart()
......
......@@ -37,12 +37,6 @@ UINT32 OsTraceGetMaskTid(UINT32 taskId)
return taskId;
}
UINT32 OsTraceBufInit(UINT32 size)
{
(VOID)size;
return LOS_OK;
}
VOID OsTraceSendHead(VOID)
{
TraceBaseHeaderInfo head = {
......
......@@ -347,7 +347,7 @@ extern TRACE_EVENT_HOOK g_traceEventHook;
#define TASK_RESUME_PARAMS(taskId, taskStatus, prio) taskId, taskStatus, prio
#define TASK_SIGNAL_PARAMS(taskId, signal, schedFlag) // taskId, signal, schedFlag
#define SWTMR_START_PARAMS(swtmrId, mode, overrun, interval, expiry) swtmrId, mode, overrun, interval, expiry
#define SWTMR_START_PARAMS(swtmrId, mode, interval) swtmrId, mode, interval
#define SWTMR_DELETE_PARAMS(swtmrId) swtmrId
#define SWTMR_EXPIRED_PARAMS(swtmrId) swtmrId
#define SWTMR_STOP_PARAMS(swtmrId) swtmrId
......@@ -496,13 +496,13 @@ extern UINT32 LOS_TraceStart(VOID);
/**
* @ingroup los_trace
* @brief Stop trace sample.
* @brief Stop trace.
*
* @par Description:
* This API is used to start trace sample.
* This API is used to stop trace.
* @attention
* <ul>
* <li>Stop trace sample</li>
* <li>Stop trace</li>
* </ul>
*
* @param None.
......
......@@ -137,15 +137,15 @@ static int lwip_socket_wrap(int domain, int type, int protocol)
#endif
return lwip_socket2(domain, type, protocol);
}
//设置选项
static int lwip_setsockopt_wrap(int s, int level, int optname, const void *optval, socklen_t optlen)
{
#if LWIP_ENABLE_NET_CAPABILITY
if (level == SOL_SOCKET) {
switch (optname) {
#if LWIP_ENABLE_CAP_NET_BROADCAST
case SO_BROADCAST: //广播消息
if (!IsCapPermit(CAP_NET_BROADCAST)) {//鉴权,是否广播权限
case SO_BROADCAST:
if (!IsCapPermit(CAP_NET_BROADCAST)) {
set_errno(EPERM);
return -1;
}
......@@ -1175,6 +1175,25 @@ static u8_t lwip_ioctl_internal_SIOCGIFMTU(struct ifreq *ifr)
}
}
static u8_t lwip_ioctl_internal_SIOCGIFBRDADDR(struct ifreq *ifr)
{
struct netif *netif = NULL;
struct sockaddr_in *sock_in = NULL;
/* get netif subnet broadcast addr */
netif = netif_find(ifr->ifr_name);
if (netif == NULL) {
return ENODEV;
}
if (ip4_addr_isany_val(*(ip_2_ip4(&netif->netmask)))) {
return ENXIO;
}
sock_in = (struct sockaddr_in *)&ifr->ifr_addr;
sock_in->sin_family = AF_INET;
sock_in->sin_addr.s_addr = (ip_2_ip4(&((netif)->ip_addr))->addr | ~(ip_2_ip4(&netif->netmask)->addr));
return 0;
}
#endif /* LWIP_IOCTL_IF */
#if LWIP_NETIF_ETHTOOL
......@@ -1437,6 +1456,13 @@ static u8_t lwip_ioctl_impl(const struct lwip_sock *sock, long cmd, void *argp)
case SIOCSIFMTU:
err = lwip_ioctl_internal_SIOCSIFMTU(ifr);
break;
case SIOCGIFBRDADDR:
if (is_ipv6 != 0) {
err = EINVAL;
} else {
err = lwip_ioctl_internal_SIOCGIFBRDADDR(ifr);
}
break;
#endif /* LWIP_IOCTL_IF */
#if LWIP_NETIF_ETHTOOL
case SIOCETHTOOL:
......@@ -1550,6 +1576,7 @@ int socks_ioctl(int sockfd, long cmd, void *argp)
case SIOCGIFMTU:
case SIOCSIFMTU:
case SIOCETHTOOL:
case SIOCGIFBRDADDR:
nbytes = sizeof(struct ifreq);
break;
default:
......
/*
* 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_fs_jffs.h"
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
static UINT32 Testcase(VOID)
{
int ret = 0;
int argc = 2;
char *argv[2];
argv[1] = (char *)"/lib/libc.so";
if (argc != 2) {
printf("Usage: %s <pathname>\n", argv[0]);
exit(1);
}
ret = faccessat(AT_FDCWD, argv[1], R_OK, AT_EACCESS);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
if (ret < 0) {
printf("faccessat error for %s\n", argv[1]);
} else {
printf("read access OK\n");
}
if (open(argv[1], O_RDONLY) < 0) {
printf("open error for %s\n", argv[1]);
} else {
printf("open for reading OK\n");
}
return LOS_OK;
}
VOID IoTestFaccessat001(void)
{
TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* 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_fs_jffs.h"
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
static UINT32 testcase(VOID)
{
int ret = 0;
ret = faccessat(AT_FDCWD, FILEPATH_000, R_OK, AT_EACCESS);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
ret = open(FILEPATH_000, O_RDONLY);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
VOID IO_TEST_FACCESSAT_002(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* 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_fs_jffs.h"
#include "sys/stat.h"
static UINT32 testcase1(VOID)
{
struct stat buf;
char *pathname = (char *)FILEPATH_775;
int ret = 0;
int fd = 0;
errno = 0;
fd = open(pathname, O_RDWR | O_CREAT);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, fd, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, OUT);
errno = 0;
ret = fstatat(fd, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, OUT);
ICUNIT_GOTO_EQUAL(buf.st_ino, 0, -1, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase2(VOID)
{
struct stat buf;
char *pathname = (char *)FILEPATH_RELATIVE;
int ret = 0;
int fd = 0;
errno = 0;
ret = fstatat(AT_FDCWD, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, OUT);
ICUNIT_GOTO_EQUAL(buf.st_ino, 0, -1, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase3(VOID)
{
struct stat buf;
char *pathname = (char *)FILEPATH_775;
int ret = 0;
int fd = 0;
errno = 0;
fd = open(pathname, O_RDWR | O_CREAT);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, fd, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, OUT);
errno = 0;
ret = fstatat(fd, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, OUT);
ICUNIT_GOTO_EQUAL(buf.st_ino, 0, -1, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase4(VOID)
{
struct stat buf;
char *pathname = (char *)FILEPATH_775;
int ret = 0;
int fd = 0;
errno = 0;
fd = open(pathname, O_RDWR | O_CREAT);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, fd, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, OUT);
errno = 0;
ret = fstatat(fd, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, OUT);
ICUNIT_GOTO_EQUAL(buf.st_ino, 0, -1, OUT);
ICUNIT_GOTO_EQUAL(errno, 0, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
testcase2();
testcase3();
testcase4();
return LOS_OK;
}
VOID IO_TEST_FSTATAT_001(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* 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_fs_jffs.h"
#include <fcntl.h>
#include "sys/stat.h"
#include "string.h"
static UINT32 testcase8(VOID)
{
struct stat buf;
char pathname[200] = FILEPATH_775;
int ret = 0;
int fd = 0;
/* omit to create test file dynamicly,use prepared test files in /storage instand. */
#if 0
errno = 0;
sprintf(pathname, "%s%s", __func__, ".tmp");
#endif
errno = 0;
fd = open(pathname, O_CREAT, 0777);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, fd, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, OUT);
errno = 0;
//ret = fstatat(fd, pathname, &buf, 0);
ret = fstatat(fd, FILEPATH_RELATIVE, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, ENOTDIR, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase7(VOID)
{
struct stat buf;
char *pathname = FILEPATH_NOACCESS;
char *dirname = DIRPATH_775;
DIR *dir = NULL;
int ret = 0;
int fd = 0;
errno = 0;
dir = opendir(dirname);
fd = dirfd(dir);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, fd, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, OUT);
errno = 0;
//ret = fstatat(AT_FDCWD, pathname, &buf, 0);
ret = fstatat(fd, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, EACCES, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase6(VOID)
{
struct stat buf;
/* let the pathname more than 4096 characters,to generate the ENAMETOOLONG errno. */
char pathname[] = PATHNAME_ENAMETOOLONG;
int ret = 0;
char *dirname = DIRPATH_775;
DIR *dir = NULL;
int fd = 0;
errno = 0;
dir = opendir(dirname);
fd = dirfd(dir);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, fd, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, OUT);
errno = 0;
ret = fstatat(fd, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, ENAMETOOLONG, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase5(VOID)
{
struct stat buf;
char pathname[] = FILEPATH_ENOENT;
int ret = 0;
errno = 0;
ret = fstatat(FD_EBADF, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, ENOENT, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase4(VOID)
{
struct stat buf;
char pathname[] = FILEPATH_775;
errno = 0;
int ret = fstatat(FD_EFAULT, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, EFAULT, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase3(VOID)
{
struct stat buf;
char pathname[] = "";
int ret = 0;
errno = 0;
ret = fstatat(AT_FDCWD, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, ENOENT, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase2(VOID)
{
struct stat buf;
char pathname[] = FILEPATH_ENOENT;
int ret = 0;
errno = 0;
ret = fstatat(AT_FDCWD, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, ENOENT, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase1(VOID)
{
struct stat buf;
char pathname[] = FILEPATH_000;
int ret = 0;
errno = 0;
ret = fstatat(1, pathname, &buf, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, EACCES, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase8(); /* CASE:fd is no a dirfd */
testcase7();
testcase6();
testcase5();
testcase4();
testcase3();
testcase2();
testcase1(); /* CASE:no access */
return LOS_OK;
}
VOID IO_TEST_FSTATAT_002(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* 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_fs_jffs.h"
#include <stdlib.h>
#include "fcntl.h"
#include "sys/vfs.h"
static UINT32 testcase1(VOID)
{
int fd;
struct statfs buf;
int ret;
errno = 0;
fd = open("/lib/libc.so", O_RDONLY);
ret = fstatfs(fd, &buf);
ICUNIT_GOTO_EQUAL(ret, 0, ret, OUT);
TEST_PRINT("[INFO]The \"/lib/libc.so\" 's,buf->f_type=0x%x\n", buf.f_type);
TEST_PRINT("[INFO]Check the file's filesystem type:./musl/kernel/include/sys/statfs.h:#define JFFS2_SUPER_MAGIC 0x72b6\n");
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_ASSERT_EQUAL(buf.f_type, 0x72b6, -1);
ICUNIT_GOTO_EQUAL(buf.f_type, 0x72b6, -1, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
return LOS_OK;
}
VOID IO_TEST_FSTATFS_001(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* 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_fs_jffs.h"
#include <stdlib.h>
#include "fcntl.h"
#include "sys/vfs.h"
static UINT32 testcase1(VOID)
{
struct statfs buf;
char *pathname = (char *)"./fstatfs.tmp";
int ret = 0;
int fd = 0;
errno = 0;
fd = open(pathname, O_RDWR | O_CREAT);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, fd, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, OUT);
errno = 0;
ret = chmod(pathname, 0);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, OUT);
errno = 0;
ret = fstatfs(fd, &buf);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
ICUNIT_GOTO_EQUAL(errno, EACCES, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase2(VOID)
{
struct statfs buf;
int ret;
errno = 0;
//ret = fstatfs(0xffffffff513, &buf);
ret = fstatfs(0xffffffff, &buf);
ICUNIT_GOTO_EQUAL(ret, -1, ret, OUT);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(errno, EBADF, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase3(VOID)
{
struct statfs buf;
int ret;
int fd;
errno = 0;
fd = open("/lib/libc.so", O_RDONLY);
errno = 0;
ret = fstatfs(fd, &buf);
ICUNIT_GOTO_EQUAL(ret, 0, ret, OUT);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase4(VOID)
{
struct statfs buf;
int ret;
int fd;
errno = 0;
fd = open("/lib/libc.so", O_RDONLY);
errno = 0;
ret = fstatfs(fd, nullptr);
ICUNIT_GOTO_EQUAL(ret, 0, ret, OUT);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, OUT);
return LOS_OK;
OUT:
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
testcase2();
testcase3(); /* EINVAL-参数错误--编译器有对类型进行保护无法测,如果强制类型转换方式传入可能会踩栈也无法识别 */
testcase4();
return LOS_OK;
}
VOID IO_TEST_FSTATFS_002(void)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
/*
* 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_fs_jffs.h"
static int TestCase(void)
{
INT32 ret, dirFd, fd, len;
CHAR pathname1[JFFS_STANDARD_NAME_LENGTH] = JFFS_PATH_NAME01;
CHAR pathname2[JFFS_STANDARD_NAME_LENGTH] = JFFS_PATH_NAME01;
DIR *dir = NULL;
struct dirent *ptr = NULL;
ret = mkdir(pathname1, 0777);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
dir = opendir(pathname1);
ICUNIT_GOTO_NOT_EQUAL(dir, NULL, dir, EXIT1);
dirFd = dirfd(dir);
ICUNIT_GOTO_NOT_EQUAL(dirFd, JFFS_IS_ERROR, dirFd, EXIT1);
ret = closedir(dir);
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT);
ret = rmdir(JFFS_PATH_NAME01);
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT);
return JFFS_NO_ERROR;
EXIT1:
close(fd);
unlink(pathname1);
closedir(dir);
EXIT:
rmdir(JFFS_PATH_NAME01);
return JFFS_IS_ERROR;
}
void ItTestFsJffs100(void)
{
TEST_ADD_CASE("It_Test_Fs_Jffs_100", TestCase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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_fs_jffs.h"
#define TEST_STRLEN 30
static int TestCase(void)
{
INT32 fd = 0;
INT32 ret = 0;
CHAR pathname[TEST_STRLEN] = JFFS_MAIN_DIR0;
CHAR pathname1[TEST_STRLEN] = JFFS_PATH_NAME0;
CHAR pathname2[TEST_STRLEN] = JFFS_PATH_NAME0;
CHAR *pathname3 = NULL;
CHAR buf1[TEST_STRLEN] = "";
CHAR buf2[TEST_STRLEN] = "";
CHAR *pret = NULL;
DIR *dir = NULL;
ret = mkdir(pathname1, 0777);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
pathname3 = pathname2;
strcat_s(pathname2, TEST_STRLEN, "/test1");
ret = mkdir(pathname2, 0777);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
fd = open(pathname2, O_DIRECTORY);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
pret = getcwd(buf1, TEST_STRLEN);
ICUNIT_GOTO_NOT_EQUAL(pret, NULL, pret, EXIT1);
ICUNIT_GOTO_STRING_EQUAL(buf1, pathname, buf1, EXIT1);
ret = fchdir(fd);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
pret = getcwd(buf2, TEST_STRLEN);
ICUNIT_GOTO_NOT_EQUAL(pret, NULL, pret, EXIT1);
ICUNIT_GOTO_STRING_EQUAL(buf2, pathname3, buf2, EXIT1);
ret = chdir(pathname);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
ret = close(fd);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
ret = rmdir(pathname2);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
ret = rmdir(pathname1);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
return JFFS_NO_ERROR;
EXIT1:
if (fd > 0) {
close(fd);
}
unlink(pathname2);
EXIT:
rmdir(pathname2);
rmdir(pathname1);
return JFFS_IS_ERROR;
}
void ItTestFsJffs101(void)
{
TEST_ADD_CASE("It_Test_Fs_Jffs_101", TestCase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_fs_jffs.h"
#define TEST_STR "abcdefghijk"
static int TestCase(void)
{
INT32 ret = JFFS_IS_ERROR;
INT32 fd = 0;
INT32 len = 0;
CHAR pathname1[JFFS_STANDARD_NAME_LENGTH] = JFFS_PATH_NAME0;
CHAR buf[JFFS_STANDARD_NAME_LENGTH] = TEST_STR;
CHAR str[JFFS_STANDARD_NAME_LENGTH] = "";
FILE *ptr = NULL;
fd = open(pathname1, O_CREAT | O_RDWR, 0777);
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, EXIT);
len = write(fd, buf, JFFS_STANDARD_NAME_LENGTH);
ICUNIT_GOTO_NOT_EQUAL(len, -1, len, EXIT);
ret = close(fd);
ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1);
ptr = freopen(pathname1, "rb", stdin);
ICUNIT_GOTO_NOT_EQUAL(ptr, NULL, ptr, EXIT1);
ret = scanf_s("%s", JFFS_STANDARD_NAME_LENGTH, str);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT1);
ret = strcmp(buf, str);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
fclose(ptr);
ret = unlink(pathname1);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
return JFFS_NO_ERROR;
EXIT1:
if (fd > 0) {
close(fd);
}
EXIT:
unlink(pathname1);
return JFFS_IS_ERROR;
}
void ItTestFsJffs106(void)
{
TEST_ADD_CASE("It_Test_Fs_Jffs_106", TestCase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_fs_jffs.h"
static int TestCase(void)
{
CHAR pathname1[JFFS_STANDARD_NAME_LENGTH] = JFFS_MAIN_DIR0;
CHAR pathname2[JFFS_STANDARD_NAME_LENGTH] = JFFS_MAIN_DIR0;
CHAR *dname = NULL;
INT32 ret;
INT32 fd = 0;
DIR *dir1 = NULL;
DIR *dir2 = NULL;
dir1 = opendir(pathname1);
ICUNIT_GOTO_NOT_EQUAL(dir1, NULL, dir1, EXIT);
ret = closedir(dir1);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
strcat_s(pathname2, JFFS_STANDARD_NAME_LENGTH, "/test123");
ret = mkdir(pathname2, 0777);
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT1);
fd = open(pathname2, O_DIRECTORY);
ICUNIT_GOTO_NOT_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT1);
dir2 = fdopendir(fd);
ICUNIT_GOTO_NOT_EQUAL(dir2, NULL, dir2, EXIT2);
ret = closedir(dir2);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT2);
ret = rmdir(pathname2);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
return JFFS_NO_ERROR;
EXIT2:
if (fd) {
close(fd);
}
if (dir2) {
closedir(dir2);
}
EXIT1:
remove(pathname2);
return JFFS_IS_ERROR;
EXIT:
if (dir1) {
closedir(dir1);
}
return JFFS_IS_ERROR;
}
void ItTestFsJffs112(void)
{
TEST_ADD_CASE("It_Test_Fs_Jffs_112", TestCase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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_fs_jffs.h"
static FILE *g_filep;
#define NUM 64
#define COUNT 10
void *DoChild()
{
int fd = 0;
int ret, count;
char buf[NUM];
flockfile(g_filep);
if (fseek(g_filep, 0L, SEEK_SET) == -1) {
perror("fseek()");
}
ret = fread(buf, NUM, 1, g_filep);
count = atoi(buf);
++count;
sprintf_s(buf, NUM, "%d", count);
if (fseek(g_filep, 0L, SEEK_SET) == -1) {
perror("fseek()");
}
ret = fwrite(buf, strlen(buf), 1, g_filep);
funlockfile(g_filep);
return NULL;
}
static int TestCase(void)
{
INT32 ret = JFFS_IS_ERROR;
INT32 fd = 0;
INT32 count = 0;
pthread_t tid[COUNT];
CHAR pathname1[JFFS_STANDARD_NAME_LENGTH] = JFFS_PATH_NAME01;
CHAR pathname2[JFFS_STANDARD_NAME_LENGTH] = JFFS_PATH_NAME01;
CHAR buf[COUNT];
ret = mkdir(pathname1, 0777);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
strcat_s(pathname2, JFFS_STANDARD_NAME_LENGTH, "/test12345.txt");
g_filep = fopen(pathname2, "w+");
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
for (count = 0; count < COUNT; count++) {
ret = pthread_create(tid + count, NULL, DoChild, NULL);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
}
for (count = 0; count < COUNT; count++) {
ret = pthread_join(tid[count], NULL);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
}
ret = fclose(g_filep);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
fd = open(pathname2, O_RDONLY);
ICUNIT_GOTO_NOT_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT1);
ret = read(fd, buf, COUNT);
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT1);
ret = atoi(buf);
ICUNIT_GOTO_EQUAL(ret, COUNT, ret, EXIT1);
ret = close(fd);
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
ret = unlink(pathname2);
g_filep = nullptr;
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT);
ret = rmdir(JFFS_PATH_NAME01);
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT);
return JFFS_NO_ERROR;
EXIT1:
if (fd > 0) {
close(fd);
}
unlink(pathname2);
g_filep = nullptr;
EXIT:
rmdir(JFFS_PATH_NAME01);
return JFFS_IS_ERROR;
}
void ItTestFsJffs113(void)
{
TEST_ADD_CASE("It_Test_Fs_Jffs_113", TestCase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
}
include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))test
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/test/kernel/include \
-I $(LITEOSTOPDIR)/fs/proc/include \
-I $(LITEOSTOPDIR)/fs/include \
-I $(LITEOSTOPDIR)/test/kernel/sample/fs/proc
SRC_MODULES := .
ifeq ($(LOSCFG_USER_TEST_LLT), y)
LLT_MODULES := llt
endif
ifeq ($(LOSCFG_USER_TEST_PRESSURE), y)
PRESSURE_MODULES := pressure
endif
ifeq ($(LOSCFG_USER_TEST_SMOKE), y)
SMOKE_MODULES := smoke
endif
ifeq ($(LOSCFG_USER_TEST_FULL), y)
FULL_MODULES := full
endif
LOCAL_MODULES := $(SRC_MODULES) $(LLT_MODULES) $(PRESSURE_MODULES) $(SMOKE_MODULES) $(FULL_MODULES)
LOCAL_SRCS := $(foreach dir,$(LOCAL_MODULES),$(wildcard $(dir)/*.c))
LOCAL_CHS := $(foreach dir,$(LOCAL_MODULES),$(wildcard $(dir)/*.h))
LOCAL_FLAGS := $(LOCAL_INCLUDE) -Wno-error
include $(MODULE)
# 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.
SRC_MODULES := fs/proc
ifeq ($(LOSCFG_USER_TEST_LLT), y)
LLT_MODULES := fs/proc/llt
endif
ifeq ($(LOSCFG_USER_TEST_SMOKE), y)
SMOKE_MODULES := fs/proc/smoke
endif
ifeq ($(LOSCFG_USER_TEST_FULL), y)
FULL_MODULES := fs/proc/full
endif
ifeq ($(LOSCFG_USER_TEST_PRESSURE), y)
PRESSURE_MODULES := fs/proc/pressure
endif
LOCAL_MODULES := $(SRC_MODULES) $(LLT_MODULES) $(PRESSURE_MODULES) $(SMOKE_MODULES) $(FULL_MODULES)
LOCAL_SRCS += $(foreach dir,$(LOCAL_MODULES),$(wildcard $(dir)/*.c))
LOCAL_CHS += $(foreach dir,$(LOCAL_MODULES),$(wildcard $(dir)/*.h))
LOCAL_FLAGS += -I./fs/proc
/*
* 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_process.h"
static int g_signal = 0;
static void Handler(int sig)
{
g_signal = sig;
}
static int TestCase(void)
{
void (*retSig)(int);
int status;
int ret;
retSig = signal(SIGUSR1, Handler);
ICUNIT_ASSERT_NOT_EQUAL(retSig, SIG_ERR, retSig);
pid_t pid = fork();
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
if (pid == 0) {
ret = killpg(getpgrp(), SIGUSR1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
exit(10); // 10, exit args
}
while (g_signal == 0) {
sleep(1);
}
ICUNIT_ASSERT_EQUAL(g_signal, SIGUSR1, g_signal);
ret = wait(&status);
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
status = WEXITSTATUS(status);
ICUNIT_ASSERT_EQUAL(status, 10, status); // 10, assert that function Result is equal to this.
return 0;
EXIT:
return 1;
}
void ItTestProcess053(void)
{
TEST_ADD_CASE("IT_POSIX_PROCESS_053", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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_process.h"
static int TestCase(void)
{
int ret;
int pid = 3;
siginfo_t info = { 0 };
ret = waitid((idtype_t)3, getpgrp(), &info, WEXITED); // 3, set tid.
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
ret = waitid(P_PID, 0, &info, WEXITED);
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
ret = waitid(P_PID, 999, &info, WEXITED); // 999, set group.
ret = errno;
ICUNIT_GOTO_EQUAL(ret, ECHILD, ret, EXIT);
ret = waitid(P_PGID, 0, &info, WEXITED);
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
ret = waitid(P_ALL, getpgrp(), &info, -1);
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
ret = waitid(P_ALL, getpgrp(), &info, 0);
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
ret = waitid(P_ALL, getpgrp(), &info, 32); // 32, set exit num.
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
ret = waitid(P_ALL, getpgrp(), &info, WSTOPPED);
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EOPNOTSUPP, ret, EXIT);
ret = waitid(P_ALL, getpgrp(), &info, WCONTINUED);
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EOPNOTSUPP, ret, EXIT);
ret = waitid(P_ALL, getpgrp(), &info, WNOWAIT);
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EOPNOTSUPP, ret, EXIT);
ret = waitid(P_ALL, getpgrp(), &info, 21); // 21, set exit num.
ret = errno;
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
return 0;
EXIT:
return 1;
}
void ItTestProcess054(void)
{
TEST_ADD_CASE("IT_POSIX_PROCESS_054", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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_process.h"
static int Child1(void)
{
int ret;
siginfo_t info = { 0 };
pid_t pid = fork();
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
if (pid == 0) {
ret = kill(getpid(), SIGKILL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
}
ret = waitid(P_PID, pid, &info, WEXITED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(info.si_status, SIGKILL, info.si_status);
ICUNIT_ASSERT_EQUAL(info.si_code, 2, info.si_code); // 2, assert that function Result is equal to this.
ICUNIT_ASSERT_EQUAL(info.si_pid, pid, info.si_pid);
exit(8); // 8, exit args
EXIT:
return 0;
}
static int TestCase(void)
{
pid_t pid;
int status;
int ret;
pid = fork();
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
if (pid == 0) {
Child1();
printf("[Failed] - [Errline : %d RetCode : 0x%x\n", g_iCunitErrLineNo, g_iCunitErrCode);
exit(g_iCunitErrLineNo);
} else {
siginfo_t info = { 0 };
ret = waitid(P_ALL, getpgrp(), &info, WEXITED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(info.si_status, 8, info.si_status); // 8, assert that function Result is equal to this.
ICUNIT_ASSERT_EQUAL(info.si_code, 1, info.si_code);
ICUNIT_ASSERT_EQUAL(info.si_pid, pid, info.si_pid);
pid = fork();
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
if (pid == 0) {
exit(11); // 11, exit args
}
sleep(1);
ret = waitid(P_PGID, getpgrp(), &info, WNOHANG);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(info.si_status, 11, info.si_status); // 11, assert that function Result is equal to this.
ICUNIT_ASSERT_EQUAL(info.si_code, 1, info.si_code);
ICUNIT_ASSERT_EQUAL(info.si_pid, pid, info.si_pid);
}
return 0;
EXIT:
return 1;
}
void ItTestProcess055(void)
{
TEST_ADD_CASE("IT_POSIX_PROCESS_055", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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_process.h"
static int TestCase(void)
{
int ret = killpg(-1, 0);
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
ret = killpg(99999, 0); // 99999, set group
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
ICUNIT_GOTO_EQUAL(errno, ESRCH, errno, EXIT);
ret = killpg(2, 0); // 2, set group
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
ICUNIT_GOTO_EQUAL(errno, EPERM, errno, EXIT);
ret = killpg(0, 65); // 65, set signal
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
return 0;
EXIT:
return 1;
}
void ItTestProcess061(void)
{
TEST_ADD_CASE("IT_POSIX_PROCESS_061", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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_process.h"
#include "sys/shm.h"
static volatile int *g_shmptr = NULL;
static void Handler(int sig)
{
(*g_shmptr)++;
}
static int TestCase(void)
{
int status;
(void)signal(SIGUSR2, Handler);
int ret;
pid_t pid;
int shmid = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0600); // 0600 config of shmget
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
g_shmptr = (int *)shmat(shmid, nullptr, 0);
ICUNIT_GOTO_NOT_EQUAL(g_shmptr, (int *)-1, g_shmptr, EXIT);
*g_shmptr = 0;
pid = fork();
ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, assert pid equal to this.
if (pid == 0) {
pid_t pid1 = fork();
ICUNIT_GOTO_WITHIN_EQUAL(pid1, 0, 100000, pid1, EXIT); // 100000, assert pid1 equal to this.
if (pid1 == 0) {
ret = killpg(getpgrp(), SIGUSR2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
while (*g_shmptr < 3) { // 3, Number of cycles.
sleep(1);
}
exit(11); // 11, exit args
}
while (*g_shmptr < 3) { // 3, Number of cycles.
sleep(1);
}
ret = waitpid(pid1, &status, 0);
ICUNIT_GOTO_EQUAL(ret, pid1, ret, EXIT);
status = WEXITSTATUS(status);
ICUNIT_GOTO_EQUAL(status, 11, status, EXIT); // 11, assert status equal to this.
exit(10); // 10, exit args
}
while (*g_shmptr < 3) { // 3, wait function running.
sleep(1);
}
ICUNIT_ASSERT_EQUAL(*g_shmptr, 3, *g_shmptr); // 3, assert that function Result is equal to this.
ret = waitpid(pid, &status, 0);
ICUNIT_GOTO_EQUAL(ret, pid, ret, EXIT);
status = WEXITSTATUS(status);
ICUNIT_GOTO_EQUAL(status, 10, status, EXIT); // 10, assert that function Result is equal to this.
shmdt((void *)g_shmptr);
shmctl(shmid, IPC_RMID, NULL);
return 0;
EXIT:
shmdt((void *)g_shmptr);
shmctl(shmid, IPC_RMID, NULL);
return 1;
}
void ItTestProcess062(void)
{
TEST_ADD_CASE("IT_POSIX_PROCESS_062", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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_sys.h"
static jmp_buf g_buf;
static UINT32 First(VOID)
{
int val = 2;
int ret = setjmp(g_buf);
if (ret) {
ICUNIT_ASSERT_EQUAL(ret, val, ret);
goto OUT1;
}
longjmp(g_buf, val);
OUT1:
return 0;
}
static UINT32 Sencond(VOID)
{
int ret = setjmp(g_buf);
if (ret) {
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
goto OUT2;
}
longjmp(g_buf, 0);
OUT2:
return 0;
}
static UINT32 TestCase(VOID)
{
int ret = First();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = Sencond();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
VOID ItTestSys001(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_024", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
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);
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);
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);
user4 = getpwnam("lyw");
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
user4 = getpwnam("");
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
return 0;
}
VOID ItTestSys018(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd pwd;
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
struct passwd *user5 = nullptr;
char buf1[1024] = { 0 };
char buf2[2] = { 0 };
int ret;
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_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);
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);
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);
ret = getpwnam_r("root", &pwd, buf2, sizeof(buf2), &user4);
ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ret = getpwnam_r(nullptr, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(ret, 0, -1);
ret = getpwnam_r("", &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwnam_r("sssssss", &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
return 0;
}
VOID ItTestSys019(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
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);
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);
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);
user4 = getpwuid(200);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
user4 = getpwuid(-100);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
user4 = getpwuid(100000);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
return 0;
}
VOID ItTestSys020(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd pwd;
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
struct passwd *user5 = nullptr;
char buf1[1024] = { 0 };
char buf2[2] = { 0 };
int ret;
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_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);
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);
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(0, &pwd, buf2, sizeof(buf2), &user4);
ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
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(100000, &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);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
return 0;
}
VOID ItTestSys021(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
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);
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);
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);
setpwent();
user2 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user2, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, user1->pw_name, -1);
return 0;
}
VOID ItTestSys022(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_sys.h"
#include "grp.h"
static UINT32 TestCase(VOID)
{
struct group *grp1 = nullptr;
struct group *grp2 = nullptr;
struct group *grp3 = nullptr;
struct group *grp4 = nullptr;
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);
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);
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);
setgrent();
grp4 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp4, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_name, grp4->gr_name, -1);
return 0;
}
VOID ItTestSys023(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_sys.h"
static jmp_buf g_buf;
static UINT32 First(VOID)
{
int ret = _setjmp(g_buf);
if (ret) {
ICUNIT_ASSERT_EQUAL(ret, 2, ret);
goto OUT1;
}
_longjmp(g_buf, 2);
OUT1:
return 0;
}
static UINT32 Sencond(VOID)
{
int ret = _setjmp(g_buf);
if (ret) {
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
goto OUT2;
}
_longjmp(g_buf, 0);
OUT2:
return 0;
}
static UINT32 TestCase(VOID)
{
int ret = First();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = Sencond();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
VOID ItTestSys024(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_024", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_sys.h"
#include <grp.h>
#define GROUPFILE "/etc/group"
static int 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;
int ret = getgrgid_r(0, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(getNam2, nullptr, getNam2);
ICUNIT_ASSERT_STRING_EQUAL(getNam2->gr_name, "root", getNam2->gr_name);
ICUNIT_ASSERT_STRING_EQUAL(getNam2->gr_passwd, "x", getNam2->gr_passwd);
ICUNIT_ASSERT_EQUAL(getNam2->gr_gid, 0, getNam2->gr_gid);
groupRet = getgrgid(0);
ICUNIT_ASSERT_NOT_EQUAL(groupRet, nullptr, groupRet);
ICUNIT_ASSERT_STRING_EQUAL(groupRet->gr_name, "root", groupRet->gr_name);
ICUNIT_ASSERT_STRING_EQUAL(groupRet->gr_passwd, "x", groupRet->gr_passwd);
ICUNIT_ASSERT_EQUAL(groupRet->gr_gid, 0, groupRet->gr_gid);
groupRet = getgrnam("root");
ICUNIT_ASSERT_NOT_EQUAL(groupRet, nullptr, groupRet);
ICUNIT_ASSERT_STRING_EQUAL(groupRet->gr_name, "root", groupRet->gr_name);
ICUNIT_ASSERT_STRING_EQUAL(groupRet->gr_passwd, "x", groupRet->gr_passwd);
ICUNIT_ASSERT_EQUAL(groupRet->gr_gid, 0, groupRet->gr_gid);
ret = getgrnam_r("root", &getData1, buf, len, &getData2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(getData2, nullptr, getData2);
ICUNIT_ASSERT_STRING_EQUAL(getData2->gr_name, "root", getData2->gr_name);
ICUNIT_ASSERT_STRING_EQUAL(getData2->gr_passwd, "x", getData2->gr_passwd);
ICUNIT_ASSERT_EQUAL(getData2->gr_gid, 0, getData2->gr_gid);
return 0;
}
static int TestCase1(void)
{
int 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);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
groupRet = getgrgid(-1);
ICUNIT_ASSERT_EQUAL(groupRet, 0, groupRet);
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
groupRet = getgrnam("null");
ICUNIT_ASSERT_EQUAL(groupRet, nullptr, groupRet);
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
ret = getgrnam_r("null", &getData1, buf, len, &getData2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
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)
{
int ret = TestCase0();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = TestCase1();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
VOID ItTestSys025(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_025", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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_sys.h"
static int TestCase(void)
{
char *name = getlogin();
ICUNIT_ASSERT_NOT_EQUAL(name, "USER1", NULL);
int ret = getlogin_r(name, sizeof(name));
ICUNIT_ASSERT_EQUAL(ret, 6, ret);
ret = setenv("LOGNAME", "USER1", 1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
name = getlogin();
ICUNIT_ASSERT_STRING_EQUAL(name, "USER1", name);
ret = getlogin_r(name, strlen(name) + 1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = getlogin_r(name, 1);
ICUNIT_ASSERT_EQUAL(ret, 34, ret);
ret = unsetenv("LOGNAME");
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
name = getlogin();
ICUNIT_ASSERT_EQUAL(name, nullptr, name);
return 0;
}
VOID ItTestSys026(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_026", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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_sys.h"
#include "fcntl.h"
#include <sys/ipc.h>
static UINT32 TestCase(VOID)
{
int fd;
int ret1;
int ret2;
int id1 = 1;
int id2 = 2;
char *str1 = "/storage/1.txt";
char *str2 = "/storage/2.txt";
fd = open(str1, O_CREAT);
if (fd < 0) {
return -1;
}
fd = open(str2, O_CREAT);
if (fd < 0) {
return -1;
}
ret1 = ftok(str1, id1);
ICUNIT_ASSERT_NOT_EQUAL(ret1, -1, ret1);
ret2 = ftok(str1, id2);
ICUNIT_ASSERT_NOT_EQUAL(ret1, -1, ret2);
ICUNIT_ASSERT_NOT_EQUAL(ret1, ret2, -1);
ret2 = ftok(str1, id1);
ICUNIT_ASSERT_EQUAL(ret1, ret2, -1);
ret2 = ftok(str2, id1);
ICUNIT_ASSERT_NOT_EQUAL(ret2, -1, ret2);
ICUNIT_ASSERT_NOT_EQUAL(ret1, ret2, -1);
return 0;
}
VOID ItTestSys027(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/* 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_sys.h"
static UINT32 TestCase(VOID)
{
int ret;
pid_t pid = fork();
if (pid == 0) {
ret = nice(0);
ICUNIT_ASSERT_EQUAL(ret, 15, ret);
} else {
ret = nice(-15);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
}
return 0;
}
VOID IT_TEST_SYS_028(VOID)
{
TEST_ADD_CASE(IT_TEST_SYS_028, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/times.h>
#include <errno.h>
#include "lt_clock_test.h"
#include <osTest.h>
/* When clock time is changed, timers for a relative interval are unaffected,
* but timers for an absolute point in time are affected.
*/
static int ClockTest(void)
{
clockid_t clk = CLOCK_REALTIME;
struct timespec res, tp, oldtp;
int ret;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get current real time */
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("sleep 2 seconds\n");
sleep(2); // 2, seconds.
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
/* set real time */
ret = clock_settime(clk, &tp);
#if TEST_ON_LINUX
/* on linux host we need root to set clock time */
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EPERM, errno);
#else
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
#endif
LogPrintln("get real time clock again\n");
/* get current real time again */
ret = clock_gettime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest001(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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 "lt_clock_test.h"
static int ClockMonotonicTest(void)
{
clockid_t clk = CLOCK_MONOTONIC;
struct timespec res, ts;
int ret;
ret = clock_gettime(clk, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest002(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockMonotonicTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/times.h>
#include "lt_clock_test.h"
#include <osTest.h>
static int ClockCoarseTest(void)
{
clockid_t clk = CLOCK_REALTIME_COARSE;
struct timespec res, realts, monots;
int ret;
ret = clock_gettime(clk, &realts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
LogPrintln("get real coarse time again\n");
ret = clock_gettime(clk, &realts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
clk = CLOCK_MONOTONIC_COARSE;
ret = clock_gettime(clk, &monots);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest003(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockCoarseTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* 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 "lt_clock_test.h"
static int CpuClockTest(void)
{
int pid = 0;
int ret;
clockid_t clockid;
struct timespec ts;
/* CLOCK_PROCESS_CPUTIME_ID if pid == 0 */
ret = clock_getcpuclockid(pid, &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = clock_gettime(clockid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest004(void)
{
TEST_ADD_CASE(__FUNCTION__, CpuClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/times.h>
#include <errno.h>
#include "lt_clock_test.h"
#include <osTest.h>
/* When clock time is changed, timers for a relative interval are unaffected,
* but timers for an absolute point in time are affected.
*/
static int ClockTest(void)
{
clockid_t clk = CLOCK_REALTIME_COARSE;
struct timespec res, tp, oldtp;
int ret;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get current real coarse time */
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
/* set real coarse time */
ret = clock_settime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EOPNOTSUPP, errno);
LogPrintln("get coarse real time clock again\n");
/* get current real coarse time again */
ret = clock_gettime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest006(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/times.h>
#include <errno.h>
#include "lt_clock_test.h"
#include <osTest.h>
/* When clock time is changed, timers for a relative interval are unaffected,
* but timers for an absolute point in time are affected.
*/
static int ClockTest(void)
{
clockid_t clk = CLOCK_MONOTONIC_COARSE;
struct timespec res, tp, oldtp;
int ret;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get current monotonic coarse time */
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
/* set monotonic coarse time */
ret = clock_settime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EOPNOTSUPP, errno);
LogPrintln("get coarse monotonic time clock again\n");
/* get current monotonic coarse time again */
ret = clock_gettime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest007(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/times.h>
#include <errno.h>
#include "lt_clock_test.h"
#include <osTest.h>
/* When clock time is changed, timers for a relative interval are unaffected,
* but timers for an absolute point in time are affected.
*/
static int ClockTest(void)
{
clockid_t clk = CLOCK_MONOTONIC;
struct timespec res, tp, oldtp;
int ret;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get current monotonic time */
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
/* set real time */
ret = clock_settime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
LogPrintln("get monotonic time clock again\n");
/* get current monotonic time again */
ret = clock_gettime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest008(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/times.h>
#include <errno.h>
#include "lt_clock_test.h"
#include <osTest.h>
/* When clock time is changed, timers for a relative interval are unaffected,
* but timers for an absolute point in time are affected.
*/
static int ClockTest(void)
{
clockid_t clk = CLOCK_MONOTONIC_RAW;
struct timespec res, tp, oldtp;
int ret;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get current monotonic raw time */
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
/* set monotonic raw time */
ret = clock_settime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EOPNOTSUPP, errno);
LogPrintln("get monotonic raw time clock again\n");
/* get current monotonic raw time again */
ret = clock_gettime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest009(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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 "lt_clock_test.h"
static void *ThreadFuncTest(void *arg)
{
printf("Subthread starting infinite loop\n");
while (1) {
}
}
static int ThreadClock(const char *msg, clockid_t cid)
{
struct timespec ts;
int ret;
printf("%s", msg);
ret = clock_gettime(cid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("%4jd.%03ld\n", ts.tv_sec, ts.tv_nsec / 1000000); // 1000000, 1ms.
return 0;
}
static int ClockTest(void)
{
pthread_t thread;
clockid_t clockid;
int ret;
struct timespec ts;
/* check param invalid */
ret = clock_gettime(-2050, &ts); // 2050, clock id.
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
ret = pthread_create(&thread, NULL, ThreadFuncTest, 0);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("Main thread sleeping\n");
sleep(1);
printf("Main thread consuming some CPU time...\n");
for (int j = 0; j < 4000000; j++) { // 4000000, The loop frequency.
getppid();
}
/* get current pthread clockid */
ret = pthread_getcpuclockid(pthread_self(), &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = ThreadClock("Main thread CPU time: ", clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get create pthread clockid */
ret = pthread_getcpuclockid(thread, &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = ThreadClock("Subthread CPU time: 1 ", clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest011(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* 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 "lt_clock_test.h"
static int ClockTest(void)
{
clockid_t clockid;
struct timespec ts;
int ret;
/* check param invalid */
ret = clock_getcpuclockid(0, &clockid);
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
ret = clock_getcpuclockid(65, &clockid); // 65, pthread id.
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
/* get user process2 clockid */
ret = clock_getcpuclockid(2, &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get clockid time */
ret = clock_gettime(clockid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get kernel process1 clockid */
ret = clock_getcpuclockid(1, &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get clockid time */
ret = clock_gettime(clockid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get current process clockid */
ret = clock_getcpuclockid(getpid(), &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* get clockid time */
ret = clock_gettime(clockid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest012(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
git add -A
git commit -m ' 优化进程模块部分注解
git commit -m ' 同步下官方源码,近半个月官方改动很小.
百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码
博客输出站点(国内):http://weharmonyos.com
博客输出站点(国外):https://weharmony.github.io
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册