Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
c108e9f6
I
iSulad
项目概览
openeuler
/
iSulad
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
iSulad
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c108e9f6
编写于
2月 25, 2020
作者:
L
leizhongkai
提交者:
lifeng68
2月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
iSulad: add testcase for isulad-shim
Signed-off-by:
N
leizhongkai
<
leizhongkai@huawei.com
>
上级
3d017330
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
160 addition
and
0 deletion
+160
-0
src/cmd/isulad-shim/common.h
src/cmd/isulad-shim/common.h
+8
-0
src/cmd/isulad-shim/process.h
src/cmd/isulad-shim/process.h
+7
-0
test/cmd/CMakeLists.txt
test/cmd/CMakeLists.txt
+1
-0
test/cmd/isulad-shim/CMakeLists.txt
test/cmd/isulad-shim/CMakeLists.txt
+22
-0
test/cmd/isulad-shim/isulad-shim_llt.cc
test/cmd/isulad-shim/isulad-shim_llt.cc
+122
-0
未找到文件。
src/cmd/isulad-shim/common.h
浏览文件 @
c108e9f6
...
...
@@ -18,6 +18,10 @@
#include <stdbool.h>
#ifdef __cplusplus
extern
"C"
{
#endif
// error code
#define SHIM_ERR_BASE (-10000)
#define SHIM_SYS_ERR(err) (SHIM_ERR_BASE-err)
...
...
@@ -60,5 +64,9 @@ void close_fd(int *pfd);
int
open_no_inherit
(
const
char
*
path
,
int
flag
,
mode_t
mode
);
#ifdef __cplusplus
}
#endif
#endif
src/cmd/isulad-shim/process.h
浏览文件 @
c108e9f6
...
...
@@ -21,6 +21,10 @@
#include <stdbool.h>
#include "shim_client_process_state.h"
#ifdef __cplusplus
extern
"C"
{
#endif
enum
{
stdid_in
=
0
,
stdid_out
,
...
...
@@ -88,6 +92,9 @@ int create_process(process_t *p);
int
process_signal_handle_routine
(
process_t
*
p
);
void
process_delete
(
process_t
*
p
);
#ifdef __cplusplus
}
#endif
#endif
test/cmd/CMakeLists.txt
浏览文件 @
c108e9f6
project
(
iSulad_LLT
)
add_subdirectory
(
isula
)
add_subdirectory
(
isulad-shim
)
test/cmd/isulad-shim/CMakeLists.txt
0 → 100644
浏览文件 @
c108e9f6
project
(
iSulad_LLT
)
SET
(
EXE isulad-shim_llt
)
add_executable
(
${
EXE
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../src/cmd/isulad-shim/process.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../src/cmd/isulad-shim/common.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../src/json/schema/src/read_file.c
${
CMAKE_BINARY_DIR
}
/json/json_common.c
${
CMAKE_BINARY_DIR
}
/json/host_config.c
${
CMAKE_BINARY_DIR
}
/json/shim_client_process_state.c
isulad-shim_llt.cc
)
target_include_directories
(
${
EXE
}
PUBLIC
${
GTEST_INCLUDE_DIR
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../src/cmd/isulad-shim
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../src/json
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../src/json/schema/src/
${
CMAKE_BINARY_DIR
}
/json
${
CMAKE_BINARY_DIR
}
/conf
)
target_link_libraries
(
${
EXE
}
${
GTEST_BOTH_LIBRARIES
}
${
GMOCK_LIBRARY
}
${
GMOCK_MAIN_LIBRARY
}
${
CMAKE_THREAD_LIBS_INIT
}
-lyajl
)
test/cmd/isulad-shim/isulad-shim_llt.cc
0 → 100644
浏览文件 @
c108e9f6
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* Description: isulad-shim llt
* Author: leizhongkai
* Create: 2020-02-25
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "process.h"
#include "common.h"
int
g_log_fd
=
-
1
;
using
::
testing
::
Args
;
using
::
testing
::
ByRef
;
using
::
testing
::
SetArgPointee
;
using
::
testing
::
DoAll
;
using
::
testing
::
NiceMock
;
using
::
testing
::
Return
;
using
::
testing
::
NotNull
;
using
::
testing
::
AtLeast
;
using
::
testing
::
Invoke
;
using
::
testing
::
_
;
using
namespace
std
;
class
IsuladShimUnitTest
:
public
testing
::
Test
{
public:
void
SetUp
()
override
{
}
void
TearDown
()
override
{
}
};
TEST_F
(
IsuladShimUnitTest
,
test_new_process
)
{
string
id
=
"aaaabbbbccccdddd"
;
string
bundle
=
"/home/isulad/bundle"
;
string
runtime
=
"kata-runtime"
;
process_t
*
p
=
new_process
((
char
*
)
id
.
c_str
(),
(
char
*
)
bundle
.
c_str
(),
(
char
*
)
runtime
.
c_str
());
ASSERT_TRUE
(
p
==
NULL
);
}
TEST_F
(
IsuladShimUnitTest
,
test_open_no_inherit
)
{
string
exist_file
=
"/tmp/test_open_no_inherit_exist"
;
string
non_file
=
"/tmp/test_open_no_inherit_non"
;
int
fd_exist
=
-
1
;
fd_exist
=
open_no_inherit
(
exist_file
.
c_str
(),
O_CREAT
|
O_WRONLY
|
O_APPEND
|
O_SYNC
,
0640
);
EXPECT_GT
(
fd_exist
,
0
);
EXPECT_EQ
(
open_no_inherit
(
non_file
.
c_str
(),
O_WRONLY
,
-
1
),
-
1
);
close
(
fd_exist
);
unlink
(
exist_file
.
c_str
());
}
TEST_F
(
IsuladShimUnitTest
,
test_read_write_nointr
)
{
char
buf
[
32
]
=
{
0
};
string
test_file
=
"/tmp/test_read_nointr"
;
string
test_string
=
"hello"
;
int
fd_wr
=
-
1
;
int
fd_rd
=
-
1
;
int
nwrite
=
-
1
;
int
nread
=
-
1
;
EXPECT_EQ
(
read_nointr
(
-
1
,
NULL
,
32
),
-
1
);
EXPECT_EQ
(
read_nointr
(
0
,
NULL
,
32
),
-
1
);
EXPECT_EQ
(
read_nointr
(
1
,
NULL
,
32
),
-
1
);
fd_wr
=
open_no_inherit
(
test_file
.
c_str
(),
O_CREAT
|
O_RDWR
|
O_APPEND
|
O_SYNC
,
0640
);
EXPECT_GT
(
fd_wr
,
0
);
nwrite
=
write_nointr
(
fd_wr
,
test_string
.
c_str
(),
5
);
EXPECT_EQ
(
nwrite
,
5
);
fd_rd
=
open
(
test_file
.
c_str
(),
O_RDONLY
);
nread
=
read_nointr
(
fd_rd
,
buf
,
32
);
EXPECT_EQ
(
nread
,
5
);
close
(
fd_wr
);
close
(
fd_rd
);
unlink
(
test_file
.
c_str
());
}
TEST_F
(
IsuladShimUnitTest
,
test_file_exist
)
{
string
exist_file
=
"/tmp/test_exist_exist"
;
string
non_file
=
"/tmp/test_exist_non"
;
int
fd_exist
=
-
1
;
fd_exist
=
open_no_inherit
(
exist_file
.
c_str
(),
O_CREAT
|
O_WRONLY
|
O_APPEND
|
O_SYNC
,
0640
);
EXPECT_GT
(
fd_exist
,
0
);
EXPECT_TRUE
(
file_exists
(
exist_file
.
c_str
()));
EXPECT_FALSE
(
file_exists
(
non_file
.
c_str
()));
close
(
fd_exist
);
unlink
(
exist_file
.
c_str
());
}
TEST_F
(
IsuladShimUnitTest
,
test_combined_output
)
{
string
exist_cmd
=
"ls"
;
string
non_cmd
=
"aaa"
;
const
char
*
params
[
MAX_RUNTIME_ARGS
]
=
{
NULL
};
char
output
[
BUFSIZ
]
=
{
0
};
int
output_len
=
BUFSIZ
;
params
[
0
]
=
exist_cmd
.
c_str
();
EXPECT_EQ
(
cmd_combined_output
(
exist_cmd
.
c_str
(),
params
,
output
,
&
output_len
),
0
);
params
[
0
]
=
non_cmd
.
c_str
();
EXPECT_EQ
(
cmd_combined_output
(
non_cmd
.
c_str
(),
params
,
output
,
&
output_len
),
-
1
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录