You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lvwenxuan
2d46693239
#include <cstdio> // 引入标准输入输出库
#include <unistd.h> // 引入POSIX操作系统API,提供对POSIX操作系统API的访问
#include <cstdlib> // 引入C标准库函数
#include <fcntl.h> // 引入文件控制选项,用于open等函数
#include <cstring> // 引入字符串操作函数
#include <gtest/gtest.h> // 引入Google Test框架,用于单元测试
#include "It_process_plimits.h" // 引入自定义头文件,可能包含测试所需的声明或定义
// 定义测试函数ItProcessPlimitsDevices001
void ItProcessPlimitsDevices001(void)
{
int fd; // 声明文件描述符变量
int ret; // 声明返回值变量
mode_t mode; // 声明文件模式变量(未初始化)
char writeBuf[8]; // 声明写入缓冲区,大小为8字节
std::string test_dev = "/dev/hi_mipi"; // 定义测试设备文件路径
std::string path = "/proc/plimits/test"; // 定义/proc/plimits/test目录路径
std::string procsTestPath = "/proc/plimits/test/plimits.procs"; // 定义进程限制文件路径
// 尝试创建目录,但mode未初始化,此处存在潜在问题
ret = mkdir(path.c_str(), S_IFDIR | mode); // S_IFDIR应为0(对于mkdir来说,通常只使用权限位)
ASSERT_EQ(ret, 0); // 断言创建目录操作成功
// 使用memset_s安全地清零writeBuf
(void)memset_s(writeBuf, sizeof(writeBuf), 0, sizeof(writeBuf));
// 将当前进程ID格式化为字符串并存储到writeBuf中
ret = sprintf_s(writeBuf, sizeof(writeBuf), "%d", getpid());
ASSERT_NE(ret, -1); // 断言格式化操作成功(非-1)
// 尝试将进程ID写入到plimits.procs文件中,但WriteFile函数未定义,可能是自定义函数
ret = WriteFile(procsTestPath.c_str(), writeBuf);
ASSERT_NE(ret, 0); // 断言写入操作失败(此处的断言逻辑可能需要根据WriteFile的实现调整)
// 尝试以读写和创建模式打开/dev/hi_mipi设备文件
fd = open(test_dev.c_str(), O_RDWR|O_CREAT);
ASSERT_NE(fd, -1); // 断言打开文件操作成功(文件描述符不为-1)
// 关闭文件描述符
(void)close(fd);
// 尝试删除之前创建的目录
ret = rmdir(path.c_str());
ASSERT_EQ(ret, 0); // 断言删除目录操作成功
}
|
8 months ago |
community-master
|
总文件
|
8 months ago |
kernel_liteos_a-master/testsuites/unittest
|
#include <cstdio> // 引入标准输入输出库
|
8 months ago |
README.md
|
Initial commit
|
9 months ago |
lwx.txt
|
lwx
|
8 months ago |
pjy.txt
|
newly added
|
8 months ago |
readme.txt
|
readme
|
8 months ago |
开源软件阅读报告.pdf
|
ADD file via upload
|
8 months ago |