Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
9e495f0a
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
接近 2 年 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9e495f0a
编写于
4月 28, 2022
作者:
O
openharmony_ci
提交者:
Gitee
4月 28, 2022
浏览文件
操作
浏览文件
下载
差异文件
!560 修改L1ut打印不必要错误提示问题
Merge pull request !560 from Mupceet/ut_cc
上级
fd296e8e
6d0b2a44
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
28 deletion
+9
-28
test/unittest/common/cmd_func_test.cpp
test/unittest/common/cmd_func_test.cpp
+9
-28
未找到文件。
test/unittest/common/cmd_func_test.cpp
浏览文件 @
9e495f0a
...
...
@@ -24,6 +24,7 @@
#include "init_cmds.h"
#include "init_jobs_internal.h"
#include "init_service_manager.h"
#include "beget_ext.h"
#include "securec.h"
#include "gtest/gtest.h"
...
...
@@ -83,22 +84,17 @@ public:
const
mode_t
mode
=
0755
;
if
(
mkdir
(
TEST_DRI
.
c_str
(),
mode
)
!=
0
)
{
if
(
errno
!=
EEXIST
)
{
printf
(
"[----------] StartupInitUTest, mkdir for %s failed, error %d.
\n
"
,
\
TEST_DRI
.
c_str
(),
errno
);
return
;
}
}
FILE
*
testFile
=
fopen
(
TEST_FILE
.
c_str
(),
"w+"
);
if
(
testFile
==
nullptr
)
{
printf
(
"[----------] StartupInitUTest, open file %s failed, error %d.
\n
"
,
\
TEST_FILE
.
c_str
(),
errno
);
return
;
}
std
::
string
writeContent
=
"This is a test file for startup subsystem init module."
;
if
(
fwrite
(
writeContent
.
c_str
(),
writeContent
.
length
(),
1
,
testFile
)
!=
1
)
{
printf
(
"[----------] StartupInitUTest, open file %s failed, error %d.
\n
"
,
TEST_FILE
.
c_str
(),
errno
);
fclose
(
testFile
);
return
;
}
...
...
@@ -107,32 +103,28 @@ public:
#ifndef USE_EMMC_STORAGE // emmc storage does not support chmod/chown
if
(
chmod
(
TEST_FILE
.
c_str
(),
TEST_FILE_MODE
)
!=
0
)
{
printf
(
"[----------] StartupInitUTest, chmod for file %s failed, error %d.
\n
"
,
TEST_FILE
.
c_str
(),
errno
);
return
;
}
if
(
chown
(
TEST_FILE
.
c_str
(),
TEST_FILE_UID
,
TEST_FILE_GID
)
!=
0
)
{
printf
(
"[----------] StartupInitUTest, chown for file %s failed, error %d.
\n
"
,
TEST_FILE
.
c_str
(),
errno
);
return
;
}
#endif // USE_EMMC_STORAGE
printf
(
"[----------] StartupInitUTest, cmd func test setup.
\n
"
);
}
static
void
TearDownTestCase
()
{
if
(
remove
(
TEST_FILE
.
c_str
())
!=
0
)
{
printf
(
"[----------] StartupInitUTest, remove %s failed, error %d.
\n
"
,
TEST_FILE
.
c_str
(),
errno
)
;
return
;
}
if
(
remove
(
TEST_DRI
.
c_str
())
!=
0
)
{
printf
(
"[----------] StartupInitUTest, remove %s failed, error %d.
\n
"
,
TEST_DRI
.
c_str
(),
errno
)
;
return
;
}
printf
(
"[----------] StartupInitUTest, cmd func test teardown.
\n
"
);
}
void
SetUp
()
{}
void
SetUp
()
{
SetInitLogLevel
(
INIT_FATAL
);
}
void
TearDown
()
{}
};
...
...
@@ -144,19 +136,16 @@ void ParseCmdLine(const char *content, TestCmdLine *resCmd)
const
struct
CmdTable
*
cmd
=
GetCmdByName
(
content
);
if
(
cmd
==
nullptr
)
{
printf
(
"Cannot support command: %s
\n
"
,
content
);
(
void
)
memset_s
(
resCmd
,
sizeof
(
TestCmdLine
),
0
,
sizeof
(
TestCmdLine
));
return
;
}
if
(
strlen
(
content
)
<=
(
strlen
(
cmd
->
name
)
+
1
))
{
printf
(
"Error content for command: %s
\n
"
,
content
);
(
void
)
memset_s
(
resCmd
,
sizeof
(
TestCmdLine
),
0
,
sizeof
(
TestCmdLine
));
return
;
}
int
ret1
=
strcpy_s
(
resCmd
->
name
,
MAX_CMD_NAME_LEN
,
cmd
->
name
);
int
ret2
=
strcpy_s
(
resCmd
->
cmdContent
,
MAX_CMD_CONTENT_LEN
,
content
+
strlen
(
cmd
->
name
));
if
(
ret1
||
ret2
)
{
printf
(
"Error copy command: %s
\n
"
,
content
);
(
void
)
memset_s
(
resCmd
,
sizeof
(
TestCmdLine
),
0
,
sizeof
(
TestCmdLine
));
return
;
}
...
...
@@ -243,7 +232,6 @@ HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_004, TestSize.Level0)
size_t
curCmdLen
=
g_supportedCmds
[
i
].
length
();
char
*
curCmd
=
(
char
*
)
malloc
(
curCmdLen
+
MAX_CMD_CONTENT_LEN
+
10
);
if
(
curCmd
==
nullptr
)
{
printf
(
"[----------] StartupInitUTest, cmdFuncParseCmdTest004, malloc failed.
\n
"
);
break
;
}
errno_t
ret
=
memcpy_s
(
curCmd
,
curCmdLen
+
MAX_CMD_CONTENT_LEN
+
10
,
\
...
...
@@ -251,7 +239,6 @@ HWTEST_F(StartupInitUTest, cmdFuncParseCmdTest_004, TestSize.Level0)
errno_t
ret2
=
memcpy_s
(
curCmd
+
curCmdLen
,
MAX_CMD_CONTENT_LEN
+
10
,
\
toLongContent
,
strlen
(
toLongContent
));
if
(
ret
!=
EOK
||
ret2
!=
EOK
)
{
printf
(
"[----------] StartupInitUTest, cmdFuncParseCmdTest004, memcpy_s failed.
\n
"
);
free
(
curCmd
);
curCmd
=
nullptr
;
break
;
...
...
@@ -491,8 +478,7 @@ HWTEST_F(StartupInitUTest, cmdFuncDoCmdTest_006, TestSize.Level0)
// delete dir
if
(
remove
(
cmdContentStr
.
c_str
())
!=
0
)
{
printf
(
"[----------] StartupInitUTest, cmdFuncDoCmdTest006 remove %s failed, error %d.
\n
"
,
\
TEST_DRI
.
c_str
(),
errno
);
EXPECT_EQ
(
0
,
0
);
}
// chmod success
...
...
@@ -831,13 +817,11 @@ static void CreateIllegalCfg()
{
FILE
*
testCfgFile
=
fopen
(
TEST_CFG_ILLEGAL
.
c_str
(),
"w+"
);
if
(
testCfgFile
==
nullptr
)
{
printf
(
"[----------] StartupInitUTest, open file %s failed, error %d.
\n
"
,
TEST_CFG_ILLEGAL
.
c_str
(),
errno
);
return
;
}
std
::
string
writeContent
=
"mount zpfs /patch/etc:/etc /etc"
;
if
(
fwrite
(
writeContent
.
c_str
(),
writeContent
.
length
(),
1
,
testCfgFile
)
!=
1
)
{
printf
(
"[----------] StartupInitUTest, open file %s failed, error %d.
\n
"
,
TEST_CFG_ILLEGAL
.
c_str
(),
errno
);
fclose
(
testCfgFile
);
return
;
}
...
...
@@ -894,8 +878,7 @@ HWTEST_F(StartupInitUTest, cmdFuncDoLoadCfgTest_002, TestSize.Level0)
// remove tmp file
if
(
remove
(
TEST_CFG_ILLEGAL
.
c_str
())
!=
0
)
{
printf
(
"[----------] StartupInitUTest, remove %s failed, error %d.
\n
"
,
\
TEST_CFG_ILLEGAL
.
c_str
(),
errno
);
EXPECT_EQ
(
0
,
0
);
}
}
...
...
@@ -979,7 +962,6 @@ HWTEST_F(StartupInitUTest, cmdJobTest_002, TestSize.Level0)
cJSON
*
jobItem
=
cJSON_Parse
(
cfgJson
.
c_str
());
EXPECT_NE
(
nullptr
,
jobItem
);
if
(
jobItem
==
nullptr
)
{
printf
(
"[----------] StartupInitUTest, job test, parse %s failed.
\n
"
,
cfgJson
.
c_str
());
return
;
}
ParseAllJobs
(
jobItem
);
...
...
@@ -996,7 +978,6 @@ HWTEST_F(StartupInitUTest, cmdJobTest_002, TestSize.Level0)
if
(
remove
(
POST_INIT_DIR
.
c_str
())
!=
0
||
remove
(
INIT_DIR
.
c_str
())
!=
0
||
remove
(
PRE_INIT_DIR
.
c_str
())
!=
0
)
{
printf
(
"[----------] StartupInitUTest, job test, remove failed, error %d.
\n
"
,
errno
);
}
ReleaseAllJobs
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录