提交 ff8d5214 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!53 iSulad: add testcase for lcr ops

Merge pull request !53 from lifeng_isula/fix_llt
......@@ -365,14 +365,16 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par
request.lcrpath = params->rootpath;
request.logpath = params->logpath;
request.loglevel = params->loglevel;
request.args = (const char **)params->spec->args;
request.args_len = params->spec->args_len;
request.env = (const char **)params->spec->env;
request.env_len = params->spec->env_len;
if (params->spec != NULL) {
request.args = (const char **)params->spec->args;
request.args_len = params->spec->args_len;
request.env = (const char **)params->spec->env;
request.env_len = params->spec->env_len;
}
request.console_fifos = params->console_fifos;
request.timeout = params->timeout;
request.suffix = params->suffix;
if (params->spec->user != NULL) {
if (params->spec != NULL && params->spec->user != NULL) {
if (generate_user_string_by_uid_gid(params->spec->user, &user) != 0) {
ret = -1;
goto out;
......@@ -548,15 +550,21 @@ int rt_lcr_listpids(const char *name, const char *runtime, const rt_listpids_par
int ret = 0;
struct engine_operation *engine_ops = NULL;
if (out == NULL) {
ERROR("Invalid arguments");
ret = -1;
goto out;
}
engine_ops = engines_get_handler(runtime);
if (engine_ops == NULL || engine_ops->engine_get_container_pids_op == NULL) {
DEBUG("Failed to get engine top operations");
ERROR("Failed to get engine top operations");
ret = -1;
goto out;
}
if (!engine_ops->engine_get_container_pids_op(name, params->rootpath, &(out->pids), &(out->pids_len))) {
DEBUG("Top container %s failed", name);
ERROR("Top container %s failed", name);
const char *tmpmsg = NULL;
if (engine_ops->engine_get_errmsg_op != NULL) {
tmpmsg = engine_ops->engine_get_errmsg_op();
......
......@@ -104,6 +104,119 @@ bool RuntimeCleanContainer(const char *name, const char *lcrpath, const char *lo
return true;
}
bool RuntimeRmContainer(const char *name, const char *enginepath)
{
if (name == nullptr || enginepath == nullptr) {
return false;
}
return true;
}
int RuntimeStatusContainer(const char *name, const char *enginepath, struct engine_container_status_info *status)
{
if (name == nullptr || enginepath == nullptr || status == nullptr) {
return -1;
}
return 0;
}
int RuntimeStatsContainer(const char *name, const char *enginepath,
struct engine_container_resources_stats_info *rs_stats)
{
if (name == nullptr || enginepath == nullptr || rs_stats == nullptr) {
return -1;
}
return 0;
}
bool RuntimeExecContainer(const engine_exec_request_t *request, int *exit_code)
{
if (request == nullptr || exit_code == nullptr || request->lcrpath == nullptr) {
return false;
}
return true;
}
bool RuntimePauseContainer(const char *name, const char *enginepath)
{
if (name == nullptr || enginepath == nullptr) {
return false;
}
return true;
}
bool RuntimeResumeContainer(const char *name, const char *enginepath)
{
if (name == nullptr || enginepath == nullptr) {
return false;
}
return true;
}
bool RuntimeAttachContainer(const char *name, const char *enginepath, char *in_fifo, char *out_fifo,
char *err_fifo)
{
if (name == nullptr || enginepath == nullptr) {
return false;
}
return true;
}
bool RuntimeUpdateContainer(const char *name, const char *enginepath, const struct engine_cgroup_resources *cr)
{
if (name == nullptr || enginepath == nullptr) {
return false;
}
return true;
}
bool RuntimeResizeContainer(const char *name, const char *lcrpath, unsigned int height, unsigned int width)
{
if (name == nullptr || lcrpath == nullptr) {
return false;
}
return true;
}
bool RuntimeExecResizeContainer(const char *name, const char *lcrpath, const char *suffix, unsigned int height,
unsigned int width)
{
if (name == nullptr || lcrpath == nullptr) {
return false;
}
return true;
}
bool RuntimeListPidsContainer(const char *name, const char *rootpath, pid_t **pids, size_t *pids_len)
{
if (name == nullptr || rootpath == nullptr) {
return false;
}
return true;
}
struct engine_operation g_engine_ops;
struct engine_operation *invoke_engines_get_handler(const char *runtime)
......@@ -114,6 +227,18 @@ struct engine_operation *invoke_engines_get_handler(const char *runtime)
g_engine_ops.engine_create_op = &RuntimeCreateContainer;
g_engine_ops.engine_start_op = &RuntimeStartContainer;
g_engine_ops.engine_clean_op = &RuntimeCleanContainer;
g_engine_ops.engine_delete_op = &RuntimeRmContainer;
g_engine_ops.engine_get_container_status_op = &RuntimeStatusContainer;
g_engine_ops.engine_get_container_resources_stats_op = &RuntimeStatsContainer;
g_engine_ops.engine_exec_op = &RuntimeExecContainer;
g_engine_ops.engine_pause_op = &RuntimePauseContainer;
g_engine_ops.engine_resume_op = &RuntimeResumeContainer;
g_engine_ops.engine_console_op = &RuntimeAttachContainer;
g_engine_ops.engine_update_op = &RuntimeUpdateContainer;
g_engine_ops.engine_resize_op = &RuntimeResizeContainer;
g_engine_ops.engine_exec_resize_op = &RuntimeExecResizeContainer;
g_engine_ops.engine_get_container_pids_op = &RuntimeListPidsContainer;
return &g_engine_ops;
}
......@@ -213,4 +338,258 @@ TEST_F(LcrRtOpsUnitTest, test_rt_lcr_clean_resource)
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
\ No newline at end of file
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_rm)
{
rt_rm_params_t params = {};
ASSERT_EQ(rt_lcr_rm(nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_rm("123", "lcr", &params), -1);
ASSERT_EQ(rt_lcr_rm(nullptr, "lcr", &params), -1);
ASSERT_EQ(rt_lcr_rm("123", nullptr, &params), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_rm("123", "lcr", &params), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_status)
{
rt_status_params_t params = {};
struct engine_container_status_info status = {};
ASSERT_EQ(rt_lcr_status(nullptr, nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_status("123", "lcr", &params, nullptr), -1);
ASSERT_EQ(rt_lcr_status(nullptr, "lcr", &params, &status), -1);
ASSERT_EQ(rt_lcr_status("123", nullptr, &params, &status), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_status("123", "lcr", &params, nullptr), -1);
ASSERT_EQ(rt_lcr_status("123", "lcr", &params, &status), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_resources_stats)
{
rt_stats_params_t params = {};
struct engine_container_resources_stats_info status = {};
ASSERT_EQ(rt_lcr_resources_stats(nullptr, nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_resources_stats("123", "lcr", &params, nullptr), -1);
ASSERT_EQ(rt_lcr_resources_stats(nullptr, "lcr", &params, &status), -1);
ASSERT_EQ(rt_lcr_resources_stats("123", nullptr, &params, &status), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_resources_stats("123", "lcr", &params, nullptr), -1);
ASSERT_EQ(rt_lcr_resources_stats("123", "lcr", &params, &status), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_exec)
{
rt_exec_params_t params = {};
int pid = 0;
ASSERT_EQ(rt_lcr_exec(nullptr, nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_exec("123", "lcr", &params, nullptr), -1);
ASSERT_EQ(rt_lcr_exec(nullptr, "lcr", &params, &pid), -1);
ASSERT_EQ(rt_lcr_exec("123", nullptr, &params, &pid), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_exec("123", "lcr", &params, nullptr), -1);
ASSERT_EQ(rt_lcr_exec("123", "lcr", &params, &pid), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_pause)
{
rt_pause_params_t params = {};
ASSERT_EQ(rt_lcr_pause(nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_pause("123", "lcr", &params), -1);
ASSERT_EQ(rt_lcr_pause(nullptr, "lcr", &params), -1);
ASSERT_EQ(rt_lcr_pause("123", nullptr, &params), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_pause("123", "lcr", &params), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_resume)
{
rt_resume_params_t params = {};
ASSERT_EQ(rt_lcr_resume(nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_resume("123", "lcr", &params), -1);
ASSERT_EQ(rt_lcr_resume(nullptr, "lcr", &params), -1);
ASSERT_EQ(rt_lcr_resume("123", nullptr, &params), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_resume("123", "lcr", &params), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_attach)
{
rt_attach_params_t params = {};
ASSERT_EQ(rt_lcr_attach(nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_attach("123", "lcr", &params), -1);
ASSERT_EQ(rt_lcr_attach(nullptr, "lcr", &params), -1);
ASSERT_EQ(rt_lcr_attach("123", nullptr, &params), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_attach("123", "lcr", &params), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_update)
{
rt_update_params_t params = {};
ASSERT_EQ(rt_lcr_update(nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_update("123", "lcr", &params), -1);
ASSERT_EQ(rt_lcr_update(nullptr, "lcr", &params), -1);
ASSERT_EQ(rt_lcr_update("123", nullptr, &params), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_update("123", "lcr", &params), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_resize)
{
rt_resize_params_t params = {};
ASSERT_EQ(rt_lcr_resize(nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_resize("123", "lcr", &params), -1);
ASSERT_EQ(rt_lcr_resize(nullptr, "lcr", &params), -1);
ASSERT_EQ(rt_lcr_resize("123", nullptr, &params), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_resize("123", "lcr", &params), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_exec_resize)
{
rt_exec_resize_params_t params = {};
ASSERT_EQ(rt_lcr_exec_resize(nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_exec_resize("123", "lcr", &params), -1);
ASSERT_EQ(rt_lcr_exec_resize(nullptr, "lcr", &params), -1);
ASSERT_EQ(rt_lcr_exec_resize("123", nullptr, &params), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_exec_resize("123", "lcr", &params), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
TEST_F(LcrRtOpsUnitTest, test_rt_lcr_listpids)
{
rt_listpids_params_t params = {};
rt_listpids_out_t out = {};
ASSERT_EQ(rt_lcr_listpids(nullptr, nullptr, nullptr, nullptr), -1);
EXPECT_CALL(m_isulad_conf, GetRuntimeDir(_)).WillRepeatedly(Invoke(invoke_conf_get_routine_rootdir));
EXPECT_CALL(m_engine, EngineGetHandler(_)).WillRepeatedly(Invoke(invoke_engines_get_handler));
ASSERT_EQ(rt_lcr_listpids("123", "lcr", &params, nullptr), -1);
ASSERT_EQ(rt_lcr_listpids(nullptr, "lcr", &params, &out), -1);
ASSERT_EQ(rt_lcr_listpids("123", nullptr, &params, &out), -1);
params.rootpath = "/var/lib/isulad";
ASSERT_EQ(rt_lcr_listpids("123", "lcr", &params, nullptr), -1);
ASSERT_EQ(rt_lcr_listpids("123", "lcr", &params, &out), 0);
testing::Mock::VerifyAndClearExpectations(&m_engine);
testing::Mock::VerifyAndClearExpectations(&m_isulad_conf);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册