Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
1f12580a
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,发现更多精彩内容 >>
提交
1f12580a
编写于
7月 28, 2016
作者:
J
Jovanka Gulicoska
提交者:
Cole Robinson
8月 02, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: implement node device lifecycle event APIs
Also includes unittests for node device lifecycle events API
上级
9806ae04
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
120 addition
and
0 deletion
+120
-0
src/test/test_driver.c
src/test/test_driver.c
+48
-0
tests/objecteventtest.c
tests/objecteventtest.c
+72
-0
未找到文件。
src/test/test_driver.c
浏览文件 @
1f12580a
...
@@ -51,6 +51,7 @@
...
@@ -51,6 +51,7 @@
#include "storage_conf.h"
#include "storage_conf.h"
#include "storage_event.h"
#include "storage_event.h"
#include "node_device_conf.h"
#include "node_device_conf.h"
#include "node_device_event.h"
#include "virxml.h"
#include "virxml.h"
#include "virthread.h"
#include "virthread.h"
#include "virlog.h"
#include "virlog.h"
...
@@ -5427,6 +5428,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
...
@@ -5427,6 +5428,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
int
parent_host
=
-
1
;
int
parent_host
=
-
1
;
virNodeDevicePtr
dev
=
NULL
;
virNodeDevicePtr
dev
=
NULL
;
virNodeDevCapsDefPtr
caps
;
virNodeDevCapsDefPtr
caps
;
virObjectEventPtr
event
=
NULL
;
virCheckFlags
(
0
,
NULL
);
virCheckFlags
(
0
,
NULL
);
...
@@ -5470,11 +5472,16 @@ testNodeDeviceCreateXML(virConnectPtr conn,
...
@@ -5470,11 +5472,16 @@ testNodeDeviceCreateXML(virConnectPtr conn,
goto
cleanup
;
goto
cleanup
;
virNodeDeviceObjUnlock
(
obj
);
virNodeDeviceObjUnlock
(
obj
);
event
=
virNodeDeviceEventLifecycleNew
(
def
->
name
,
VIR_NODE_DEVICE_EVENT_CREATED
,
0
);
dev
=
virGetNodeDevice
(
conn
,
def
->
name
);
dev
=
virGetNodeDevice
(
conn
,
def
->
name
);
def
=
NULL
;
def
=
NULL
;
cleanup:
cleanup:
testDriverUnlock
(
driver
);
testDriverUnlock
(
driver
);
virNodeDeviceDefFree
(
def
);
virNodeDeviceDefFree
(
def
);
testObjectEventQueue
(
driver
,
event
);
VIR_FREE
(
wwnn
);
VIR_FREE
(
wwnn
);
VIR_FREE
(
wwpn
);
VIR_FREE
(
wwpn
);
return
dev
;
return
dev
;
...
@@ -5488,6 +5495,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
...
@@ -5488,6 +5495,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
virNodeDeviceObjPtr
obj
=
NULL
;
virNodeDeviceObjPtr
obj
=
NULL
;
char
*
parent_name
=
NULL
,
*
wwnn
=
NULL
,
*
wwpn
=
NULL
;
char
*
parent_name
=
NULL
,
*
wwnn
=
NULL
,
*
wwpn
=
NULL
;
int
parent_host
=
-
1
;
int
parent_host
=
-
1
;
virObjectEventPtr
event
=
NULL
;
testDriverLock
(
driver
);
testDriverLock
(
driver
);
obj
=
virNodeDeviceFindByName
(
&
driver
->
devs
,
dev
->
name
);
obj
=
virNodeDeviceFindByName
(
&
driver
->
devs
,
dev
->
name
);
...
@@ -5521,12 +5529,17 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
...
@@ -5521,12 +5529,17 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
goto
out
;
goto
out
;
}
}
event
=
virNodeDeviceEventLifecycleNew
(
dev
->
name
,
VIR_NODE_DEVICE_EVENT_DELETED
,
0
);
virNodeDeviceObjLock
(
obj
);
virNodeDeviceObjLock
(
obj
);
virNodeDeviceObjRemove
(
&
driver
->
devs
,
obj
);
virNodeDeviceObjRemove
(
&
driver
->
devs
,
obj
);
out:
out:
if
(
obj
)
if
(
obj
)
virNodeDeviceObjUnlock
(
obj
);
virNodeDeviceObjUnlock
(
obj
);
testObjectEventQueue
(
driver
,
event
);
VIR_FREE
(
parent_name
);
VIR_FREE
(
parent_name
);
VIR_FREE
(
wwnn
);
VIR_FREE
(
wwnn
);
VIR_FREE
(
wwpn
);
VIR_FREE
(
wwpn
);
...
@@ -5667,6 +5680,39 @@ testConnectStoragePoolEventDeregisterAny(virConnectPtr conn,
...
@@ -5667,6 +5680,39 @@ testConnectStoragePoolEventDeregisterAny(virConnectPtr conn,
return
ret
;
return
ret
;
}
}
static
int
testConnectNodeDeviceEventRegisterAny
(
virConnectPtr
conn
,
virNodeDevicePtr
dev
,
int
eventID
,
virConnectNodeDeviceEventGenericCallback
callback
,
void
*
opaque
,
virFreeCallback
freecb
)
{
testDriverPtr
driver
=
conn
->
privateData
;
int
ret
;
if
(
virNodeDeviceEventStateRegisterID
(
conn
,
driver
->
eventState
,
dev
,
eventID
,
callback
,
opaque
,
freecb
,
&
ret
)
<
0
)
ret
=
-
1
;
return
ret
;
}
static
int
testConnectNodeDeviceEventDeregisterAny
(
virConnectPtr
conn
,
int
callbackID
)
{
testDriverPtr
driver
=
conn
->
privateData
;
int
ret
=
0
;
if
(
virObjectEventStateDeregisterID
(
conn
,
driver
->
eventState
,
callbackID
)
<
0
)
ret
=
-
1
;
return
ret
;
}
static
int
testConnectListAllDomains
(
virConnectPtr
conn
,
static
int
testConnectListAllDomains
(
virConnectPtr
conn
,
virDomainPtr
**
domains
,
virDomainPtr
**
domains
,
unsigned
int
flags
)
unsigned
int
flags
)
...
@@ -6809,6 +6855,8 @@ static virStorageDriver testStorageDriver = {
...
@@ -6809,6 +6855,8 @@ static virStorageDriver testStorageDriver = {
};
};
static
virNodeDeviceDriver
testNodeDeviceDriver
=
{
static
virNodeDeviceDriver
testNodeDeviceDriver
=
{
.
connectNodeDeviceEventRegisterAny
=
testConnectNodeDeviceEventRegisterAny
,
/* 2.2.0 */
.
connectNodeDeviceEventDeregisterAny
=
testConnectNodeDeviceEventDeregisterAny
,
/* 2.2.0 */
.
nodeNumOfDevices
=
testNodeNumOfDevices
,
/* 0.7.2 */
.
nodeNumOfDevices
=
testNodeNumOfDevices
,
/* 0.7.2 */
.
nodeListDevices
=
testNodeListDevices
,
/* 0.7.2 */
.
nodeListDevices
=
testNodeListDevices
,
/* 0.7.2 */
.
nodeDeviceLookupByName
=
testNodeDeviceLookupByName
,
/* 0.7.2 */
.
nodeDeviceLookupByName
=
testNodeDeviceLookupByName
,
/* 0.7.2 */
...
...
tests/objecteventtest.c
浏览文件 @
1f12580a
...
@@ -61,12 +61,25 @@ static const char storagePoolDef[] =
...
@@ -61,12 +61,25 @@ static const char storagePoolDef[] =
" </target>
\n
"
" </target>
\n
"
"</pool>
\n
"
;
"</pool>
\n
"
;
static
const
char
nodeDeviceDef
[]
=
"<device>
\n
"
" <parent>test-scsi-host-vport</parent>
\n
"
" <capability type='scsi_host'>
\n
"
" <capability type='fc_host'>
\n
"
" <wwpn>1111222233334444</wwpn>
\n
"
" <wwnn>5555666677778888</wwnn>
\n
"
" </capability>
\n
"
" </capability>
\n
"
"</device>
\n
"
;
typedef
struct
{
typedef
struct
{
int
startEvents
;
int
startEvents
;
int
stopEvents
;
int
stopEvents
;
int
defineEvents
;
int
defineEvents
;
int
undefineEvents
;
int
undefineEvents
;
int
unexpectedEvents
;
int
unexpectedEvents
;
int
createdEvents
;
int
deletedEvents
;
}
lifecycleEventCounter
;
}
lifecycleEventCounter
;
static
void
static
void
...
@@ -77,12 +90,15 @@ lifecycleEventCounter_reset(lifecycleEventCounter *counter)
...
@@ -77,12 +90,15 @@ lifecycleEventCounter_reset(lifecycleEventCounter *counter)
counter
->
defineEvents
=
0
;
counter
->
defineEvents
=
0
;
counter
->
undefineEvents
=
0
;
counter
->
undefineEvents
=
0
;
counter
->
unexpectedEvents
=
0
;
counter
->
unexpectedEvents
=
0
;
counter
->
createdEvents
=
0
;
counter
->
deletedEvents
=
0
;
}
}
typedef
struct
{
typedef
struct
{
virConnectPtr
conn
;
virConnectPtr
conn
;
virNetworkPtr
net
;
virNetworkPtr
net
;
virStoragePoolPtr
pool
;
virStoragePoolPtr
pool
;
virNodeDevicePtr
dev
;
}
objecteventTest
;
}
objecteventTest
;
...
@@ -163,6 +179,21 @@ storagePoolRefreshCb(virConnectPtr conn ATTRIBUTE_UNUSED,
...
@@ -163,6 +179,21 @@ storagePoolRefreshCb(virConnectPtr conn ATTRIBUTE_UNUSED,
(
*
counter
)
++
;
(
*
counter
)
++
;
}
}
static
void
nodeDeviceLifecycleCb
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
virNodeDevicePtr
dev
ATTRIBUTE_UNUSED
,
int
event
,
int
detail
ATTRIBUTE_UNUSED
,
void
*
opaque
)
{
lifecycleEventCounter
*
counter
=
opaque
;
if
(
event
==
VIR_NODE_DEVICE_EVENT_CREATED
)
counter
->
createdEvents
++
;
else
if
(
event
==
VIR_NODE_DEVICE_EVENT_DELETED
)
counter
->
deletedEvents
++
;
}
static
int
static
int
testDomainCreateXMLOld
(
const
void
*
data
)
testDomainCreateXMLOld
(
const
void
*
data
)
{
{
...
@@ -691,6 +722,42 @@ testStoragePoolStartStopEvent(const void *data)
...
@@ -691,6 +722,42 @@ testStoragePoolStartStopEvent(const void *data)
return
ret
;
return
ret
;
}
}
static
int
testNodeDeviceCreateXML
(
const
void
*
data
)
{
const
objecteventTest
*
test
=
data
;
lifecycleEventCounter
counter
;
virNodeDevicePtr
dev
;
int
id
;
int
ret
=
0
;
lifecycleEventCounter_reset
(
&
counter
);
id
=
virConnectNodeDeviceEventRegisterAny
(
test
->
conn
,
NULL
,
VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE
,
VIR_NODE_DEVICE_EVENT_CALLBACK
(
&
nodeDeviceLifecycleCb
),
&
counter
,
NULL
);
dev
=
virNodeDeviceCreateXML
(
test
->
conn
,
nodeDeviceDef
,
0
);
virNodeDeviceDestroy
(
dev
);
if
(
!
dev
||
virEventRunDefaultImpl
()
<
0
)
{
ret
=
-
1
;
goto
cleanup
;
}
if
(
counter
.
createdEvents
!=
1
||
counter
.
deletedEvents
!=
1
||
counter
.
unexpectedEvents
>
0
)
{
ret
=
-
1
;
goto
cleanup
;
}
cleanup:
virConnectNodeDeviceEventDeregisterAny
(
test
->
conn
,
id
);
if
(
dev
)
virNodeDeviceFree
(
dev
);
return
ret
;
}
static
void
static
void
timeout
(
int
id
ATTRIBUTE_UNUSED
,
void
*
opaque
ATTRIBUTE_UNUSED
)
timeout
(
int
id
ATTRIBUTE_UNUSED
,
void
*
opaque
ATTRIBUTE_UNUSED
)
{
{
...
@@ -765,6 +832,11 @@ mymain(void)
...
@@ -765,6 +832,11 @@ mymain(void)
testStoragePoolStartStopEvent
,
&
test
)
<
0
)
testStoragePoolStartStopEvent
,
&
test
)
<
0
)
ret
=
EXIT_FAILURE
;
ret
=
EXIT_FAILURE
;
/* Node device event tests */
if
(
virTestRun
(
"Node device createXML add event "
,
testNodeDeviceCreateXML
,
&
test
)
<
0
)
ret
=
EXIT_FAILURE
;
/* Cleanup */
/* Cleanup */
if
(
test
.
pool
)
{
if
(
test
.
pool
)
{
virStoragePoolUndefine
(
test
.
pool
);
virStoragePoolUndefine
(
test
.
pool
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录