Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
dcb397b8
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dcb397b8
编写于
12月 01, 2016
作者:
P
Peter Krempa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tests: qemumonitor: Propagate better error messages
上级
9d14cf59
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
93 addition
and
15 deletion
+93
-15
tests/qemuagenttest.c
tests/qemuagenttest.c
+2
-1
tests/qemumonitortestutils.c
tests/qemumonitortestutils.c
+88
-13
tests/qemumonitortestutils.h
tests/qemumonitortestutils.h
+3
-1
未找到文件。
tests/qemuagenttest.c
浏览文件 @
dcb397b8
...
...
@@ -375,7 +375,8 @@ qemuAgentShutdownTestMonitorHandler(qemuMonitorTestPtr test,
}
if
(
STRNEQ
(
cmdname
,
"guest-shutdown"
))
{
ret
=
qemuMonitorTestAddUnexpectedErrorResponse
(
test
);
ret
=
qemuMonitorTestAddInvalidCommandResponse
(
test
,
"guest-shutdown"
,
cmdname
);
goto
cleanup
;
}
...
...
tests/qemumonitortestutils.c
浏览文件 @
dcb397b8
...
...
@@ -118,17 +118,89 @@ qemuMonitorTestAddResponse(qemuMonitorTestPtr test,
}
int
qemuMonitorTestAddUnexpectedErrorResponse
(
qemuMonitorTestPtr
test
)
static
int
qemuMonitorTestAddErrorResponse
(
qemuMonitorTestPtr
test
,
const
char
*
usermsg
)
{
if
(
test
->
agent
||
test
->
json
)
{
return
qemuMonitorTestAddResponse
(
test
,
"{
\"
error
\"
: "
" {
\"
desc
\"
:
\"
Unexpected command
\"
, "
"
\"
class
\"
:
\"
UnexpectedCommand
\"
} }"
);
virBuffer
buf
=
VIR_BUFFER_INITIALIZER
;
char
*
escapemsg
=
NULL
;
char
*
jsonmsg
=
NULL
;
const
char
*
monmsg
=
NULL
;
char
*
tmp
;
int
ret
=
-
1
;
if
(
!
usermsg
)
usermsg
=
"unexpected command"
;
if
(
test
->
json
||
test
->
agent
)
{
virBufferEscape
(
&
buf
,
'\\'
,
"
\"
"
,
"%s"
,
usermsg
);
if
(
virBufferCheckError
(
&
buf
)
<
0
)
goto
error
;
escapemsg
=
virBufferContentAndReset
(
&
buf
);
/* replace newline/carriage return with space */
tmp
=
escapemsg
;
while
(
*
tmp
)
{
if
(
*
tmp
==
'\r'
||
*
tmp
==
'\n'
)
*
tmp
=
' '
;
tmp
++
;
}
/* format the JSON error message */
if
(
virAsprintf
(
&
jsonmsg
,
"{
\"
error
\"
: "
" {
\"
desc
\"
:
\"
%s
\"
, "
"
\"
class
\"
:
\"
UnexpectedCommand
\"
} }"
,
escapemsg
)
<
0
)
goto
error
;
monmsg
=
jsonmsg
;
}
else
{
return
qemuMonitorTestAddResponse
(
test
,
"unexpected command"
)
;
monmsg
=
usermsg
;
}
ret
=
qemuMonitorTestAddResponse
(
test
,
monmsg
);
error:
VIR_FREE
(
escapemsg
);
VIR_FREE
(
jsonmsg
);
return
ret
;
}
static
int
qemuMonitorTestAddUnexpectedErrorResponse
(
qemuMonitorTestPtr
test
,
const
char
*
command
)
{
char
*
msg
;
int
ret
;
if
(
virAsprintf
(
&
msg
,
"unexpected command: '%s'"
,
command
)
<
0
)
return
-
1
;
ret
=
qemuMonitorTestAddErrorResponse
(
test
,
msg
);
VIR_FREE
(
msg
);
return
ret
;
}
int
qemuMonitorTestAddInvalidCommandResponse
(
qemuMonitorTestPtr
test
,
const
char
*
expectedcommand
,
const
char
*
actualcommand
)
{
char
*
msg
;
int
ret
;
if
(
virAsprintf
(
&
msg
,
"expected command '%s' got '%s'"
,
expectedcommand
,
actualcommand
)
<
0
)
return
-
1
;
ret
=
qemuMonitorTestAddErrorResponse
(
test
,
msg
);
VIR_FREE
(
msg
);
return
ret
;
}
...
...
@@ -181,7 +253,7 @@ qemuMonitorTestProcessCommand(qemuMonitorTestPtr test,
VIR_DEBUG
(
"Processing string from monitor handler: '%s"
,
cmdstr
);
if
(
test
->
nitems
==
0
)
{
return
qemuMonitorTestAddUnexpectedErrorResponse
(
test
);
return
qemuMonitorTestAddUnexpectedErrorResponse
(
test
,
cmdstr
);
}
else
{
qemuMonitorTestItemPtr
item
=
test
->
items
[
0
];
ret
=
(
item
->
cb
)(
test
,
item
,
cmdstr
);
...
...
@@ -499,7 +571,8 @@ qemuMonitorTestProcessCommandDefault(qemuMonitorTestPtr test,
}
if
(
data
->
command_name
&&
STRNEQ
(
data
->
command_name
,
cmdname
))
ret
=
qemuMonitorTestAddUnexpectedErrorResponse
(
test
);
ret
=
qemuMonitorTestAddInvalidCommandResponse
(
test
,
data
->
command_name
,
cmdname
);
else
ret
=
qemuMonitorTestAddResponse
(
test
,
data
->
response
);
...
...
@@ -553,7 +626,7 @@ qemuMonitorTestProcessGuestAgentSync(qemuMonitorTestPtr test,
}
if
(
STRNEQ
(
cmdname
,
"guest-sync"
))
{
ret
=
qemuMonitorTestAdd
UnexpectedErrorResponse
(
test
);
ret
=
qemuMonitorTestAdd
InvalidCommandResponse
(
test
,
"guest-sync"
,
cmdname
);
goto
cleanup
;
}
...
...
@@ -619,7 +692,8 @@ qemuMonitorTestProcessCommandWithArgs(qemuMonitorTestPtr test,
if
(
data
->
command_name
&&
STRNEQ
(
data
->
command_name
,
cmdname
))
{
ret
=
qemuMonitorTestAddUnexpectedErrorResponse
(
test
);
ret
=
qemuMonitorTestAddInvalidCommandResponse
(
test
,
data
->
command_name
,
cmdname
);
goto
cleanup
;
}
...
...
@@ -745,7 +819,8 @@ qemuMonitorTestProcessCommandWithArgStr(qemuMonitorTestPtr test,
}
if
(
STRNEQ
(
data
->
command_name
,
cmdname
))
{
ret
=
qemuMonitorTestAddUnexpectedErrorResponse
(
test
);
ret
=
qemuMonitorTestAddInvalidCommandResponse
(
test
,
data
->
command_name
,
cmdname
);
goto
cleanup
;
}
...
...
tests/qemumonitortestutils.h
浏览文件 @
dcb397b8
...
...
@@ -42,7 +42,9 @@ int qemuMonitorTestAddHandler(qemuMonitorTestPtr test,
int
qemuMonitorTestAddResponse
(
qemuMonitorTestPtr
test
,
const
char
*
response
);
int
qemuMonitorTestAddUnexpectedErrorResponse
(
qemuMonitorTestPtr
test
);
int
qemuMonitorTestAddInvalidCommandResponse
(
qemuMonitorTestPtr
test
,
const
char
*
expectedcommand
,
const
char
*
actualcommand
);
void
*
qemuMonitorTestItemGetPrivateData
(
qemuMonitorTestItemPtr
item
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录