Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
295c1b0a
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看板
提交
295c1b0a
编写于
2月 26, 2014
作者:
J
Ján Tomko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a test for virUSBDeviceList functions
Most of them are already tested in a limited way by testing virUSBDeviceFind.
上级
855e9faa
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
102 addition
and
0 deletion
+102
-0
tests/virusbtest.c
tests/virusbtest.c
+102
-0
未找到文件。
tests/virusbtest.c
浏览文件 @
295c1b0a
...
@@ -134,6 +134,105 @@ cleanup:
...
@@ -134,6 +134,105 @@ cleanup:
}
}
static
int
testCheckNdevs
(
const
char
*
occasion
,
size_t
got
,
size_t
expected
)
{
if
(
got
!=
expected
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s: got %zu devices, expected %zu"
,
occasion
,
got
,
expected
);
return
-
1
;
}
return
0
;
}
static
int
testUSBList
(
const
void
*
opaque
ATTRIBUTE_UNUSED
)
{
virUSBDeviceListPtr
list
=
NULL
;
virUSBDeviceListPtr
devlist
=
NULL
;
virUSBDevicePtr
dev
=
NULL
;
int
ret
=
-
1
;
size_t
i
,
ndevs
;
if
(
!
(
list
=
virUSBDeviceListNew
()))
goto
cleanup
;
#define EXPECTED_NDEVS_ONE 3
if
(
virUSBDeviceFindByVendor
(
0x1d6b
,
0x0002
,
NULL
,
true
,
&
devlist
)
<
0
)
goto
cleanup
;
ndevs
=
virUSBDeviceListCount
(
devlist
);
if
(
testCheckNdevs
(
"After first find"
,
ndevs
,
EXPECTED_NDEVS_ONE
)
<
0
)
goto
cleanup
;
for
(
i
=
0
;
i
<
ndevs
;
i
++
)
{
dev
=
virUSBDeviceListGet
(
devlist
,
0
);
dev
=
virUSBDeviceListSteal
(
devlist
,
dev
);
if
(
virUSBDeviceListAdd
(
list
,
dev
)
<
0
)
goto
cleanup
;
dev
=
NULL
;
}
virObjectUnref
(
devlist
);
devlist
=
NULL
;
ndevs
=
virUSBDeviceListCount
(
list
);
if
(
testCheckNdevs
(
"After first loop"
,
ndevs
,
EXPECTED_NDEVS_ONE
)
<
0
)
goto
cleanup
;
#define EXPECTED_NDEVS_TWO 3
if
(
virUSBDeviceFindByVendor
(
0x18d1
,
0x4e22
,
NULL
,
true
,
&
devlist
)
<
0
)
goto
cleanup
;
ndevs
=
virUSBDeviceListCount
(
devlist
);
if
(
testCheckNdevs
(
"After second find"
,
ndevs
,
EXPECTED_NDEVS_TWO
)
<
0
)
goto
cleanup
;
for
(
i
=
0
;
i
<
ndevs
;
i
++
)
{
dev
=
virUSBDeviceListGet
(
devlist
,
0
);
dev
=
virUSBDeviceListSteal
(
devlist
,
dev
);
if
(
virUSBDeviceListAdd
(
list
,
dev
)
<
0
)
goto
cleanup
;
dev
=
NULL
;
}
if
(
testCheckNdevs
(
"After second loop"
,
virUSBDeviceListCount
(
list
),
EXPECTED_NDEVS_ONE
+
EXPECTED_NDEVS_TWO
)
<
0
)
goto
cleanup
;
if
(
virUSBDeviceFind
(
0x18d1
,
0x4e22
,
1
,
20
,
NULL
,
true
,
&
dev
)
<
0
)
goto
cleanup
;
if
(
!
virUSBDeviceListFind
(
list
,
dev
))
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"Device '%s' not in list when it should be"
,
virUSBDeviceGetName
(
dev
));
goto
cleanup
;
}
virUSBDeviceListDel
(
list
,
dev
);
dev
=
NULL
;
if
(
testCheckNdevs
(
"After deleting one"
,
virUSBDeviceListCount
(
list
),
EXPECTED_NDEVS_ONE
+
EXPECTED_NDEVS_TWO
-
1
)
<
0
)
goto
cleanup
;
ret
=
0
;
cleanup:
virObjectUnref
(
list
);
virObjectUnref
(
devlist
);
virUSBDeviceFree
(
dev
);
return
ret
;
}
static
int
static
int
mymain
(
void
)
mymain
(
void
)
{
{
...
@@ -182,6 +281,9 @@ mymain(void)
...
@@ -182,6 +281,9 @@ mymain(void)
DO_TEST_FIND_BY_VENDOR_FAIL
(
"Bogus vendor and product"
,
0xf00d
,
0xbeef
);
DO_TEST_FIND_BY_VENDOR_FAIL
(
"Bogus vendor and product"
,
0xf00d
,
0xbeef
);
DO_TEST_FIND_BY_VENDOR_FAIL
(
"Valid vendor"
,
0x1d6b
,
0xbeef
);
DO_TEST_FIND_BY_VENDOR_FAIL
(
"Valid vendor"
,
0x1d6b
,
0xbeef
);
if
(
virtTestRun
(
"USB List test"
,
testUSBList
,
NULL
)
<
0
)
rv
=
-
1
;
if
(
rv
<
0
)
if
(
rv
<
0
)
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录