From 0f579f785cff4c840fa2e0918a958f7e6f56a1f0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 9 May 2006 15:35:46 +0000 Subject: [PATCH] XML-RPC tests --- ChangeLog | 9 ++ Makefile.am | 5 +- configure.in | 5 +- docs/APIchunk0.html | 13 +- docs/APIchunk1.html | 22 ++- docs/APIchunk2.html | 45 +++--- docs/APIchunk3.html | 5 +- docs/APIconstructors.html | 1 + docs/APIfiles.html | 6 + docs/APIfunctions.html | 9 +- docs/APIsymbols.html | 6 + docs/examples/.cvsignore | 2 +- docs/examples/Makefile.am | 14 +- docs/examples/examples.xml | 50 +++---- docs/html/libvirt-libvirt.html | 20 ++- docs/html/libvirt-virterror.html | 2 + docs/libvirt-api.xml | 35 ++++- docs/libvirt-refs.xml | 119 +++++++++++---- src/Makefile.am | 8 +- src/xml.c | 10 ++ src/xml.h | 1 + src/xmlrpc.c | 79 ++++++---- src/xmlrpc.h | 4 + tests/Makefile.am | 31 ++++ tests/test_xmlrpc.sh | 6 + tests/testutils.c | 74 ++++++++++ tests/testutils.h | 33 +++++ tests/xmlrpcserver.py | 49 +++++++ tests/xmlrpctest.c | 245 +++++++++++++++++++++++++++++++ 29 files changed, 770 insertions(+), 138 deletions(-) create mode 100644 tests/Makefile.am create mode 100755 tests/test_xmlrpc.sh create mode 100644 tests/testutils.c create mode 100644 tests/testutils.h create mode 100755 tests/xmlrpcserver.py create mode 100644 tests/xmlrpctest.c diff --git a/ChangeLog b/ChangeLog index 5b6fde92b..930705e27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue May 9 16:37:22 CEST 2006 Karel Zak + + * tests/Makefile.am tests/xmlrpctest.c tests/testutils.h: added test + directory with basic test utils + * tests/test_xmlrpc.sh tests/xmlrpcserver.py tests/xmlrpctest.c: added + simple XML-RPC tests agains Python SimpleXMLRPCServer + * src/xmlrpc.c src/xmlrpc.h: minor refactoring, fixed gcc warnings + * src/xml.c src/xml.h: added virBufferFree() + Fri Apr 28 18:31:49 EDT 2006 Daniel Veillard * src/hash.c src/internal.h src/libvirt.c src/virterror.c diff --git a/Makefile.am b/Makefile.am index 1e0eeb32d..8c02b0a6f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = src include docs @PYTHON_SUBDIR@ +SUBDIRS = src include docs @PYTHON_SUBDIR@ tests EXTRA_DIST = libvirt.spec.in libvirt.spec COPYING.LIB \ libvirt.pc.in libvirt.pc TODO AUTHORS ChangeLog \ @@ -19,5 +19,4 @@ check-local: all tests tests: @(cd docs/examples ; $(MAKE) MAKEFLAGS+=--silent tests) @(if [ "@PYTHON_SUBDIR@" != "" ] ; then cd python ; \ - $(MAKE) MAKEFLAGS+=--silent tests ; fi) - + $(MAKE) MAKEFLAGS+=--silent tests ; fi) diff --git a/configure.in b/configure.in index 516ab23b9..3bc3b99d0 100644 --- a/configure.in +++ b/configure.in @@ -94,7 +94,7 @@ dnl dnl To be able to make dist on a non-xenified host dnl AC_ARG_WITH(depends, -[ --with-depends check for dependancies (on)]) + [ --with-depends check for dependancies (on)]) if test "$with_depends" != "no" then @@ -254,4 +254,5 @@ AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \ docs/examples/Makefile docs/devhelp/Makefile \ docs/examples/python/Makefile \ libvirt.pc libvirt.spec include/libvirt.h \ - python/Makefile python/tests/Makefile) + python/Makefile python/tests/Makefile \ + tests/Makefile) diff --git a/docs/APIchunk0.html b/docs/APIchunk0.html index 7e78a266c..e64996075 100644 --- a/docs/APIchunk0.html +++ b/docs/APIchunk0.html @@ -46,6 +46,7 @@ virConnectOpen
virConnectOpenReadOnly
virDomainCreateLinux
+virDomainDefineXML
virDomainGetMaxMemory
virDomainGetName
virDomainGetOSType
@@ -101,13 +102,15 @@
Try
virDomainLookupByID
virDomainLookupByName
virDomainLookupByUUID
-

Letter U:

UTF-8
virDomainGetXMLDesc
+

Letter U:

UTF-8
virDomainDefineXML
+virDomainGetXMLDesc
UUID
virDomainGetUUID
virDomainLookupByUUID
Use
virDomainSave
virDomainSuspend

Letter W:

What
_virError

Letter X:

XML
virDomainCreateLinux
+virDomainDefineXML
virDomainGetXMLDesc
Xen
virGetVersion

Letter a:

about
virDomainGetInfo
@@ -156,7 +159,8 @@ virSetErrorFunc
argument
virConnectOpen
virConnectOpenReadOnly
-
array
virConnectListDomains
+
array
virConnectListDefinedDomains
+virConnectListDomains
virDomainGetUUID
assumed
virGetVersion
available
_virError
@@ -177,12 +181,15 @@
better
virInitialize
block
_virDomainKernel
but
virConnGetLastError
+virDomainDefineXML
virDomainReboot
virDomainShutdown
virDomainSuspend
+virDomainUndefine
virGetLastError
bytes
virDomainGetUUID

Letter c:

call
virConnectGetVersion
+virDomainCreate
virDomainDestroy
virDomainSave
virInitialize
@@ -227,11 +234,13 @@ virConnectClose
virConnectGetType
virConnectGetVersion
+virConnectListDefinedDomains
virConnectListDomains
virConnectNumOfDomains
virConnectOpen
virConnectOpenReadOnly
virDomainCreateLinux
+virDomainDefineXML
virDomainGetInfo
virDomainLookupByID
virDomainLookupByName
diff --git a/docs/APIchunk1.html b/docs/APIchunk1.html index a640d44f2..9aae23092 100644 --- a/docs/APIchunk1.html +++ b/docs/APIchunk1.html @@ -12,16 +12,25 @@
deallocated
virDomainGetName
default
virConnSetErrorFunc
virSetErrorFunc
+
define
virDomainDefineXML
+
defined
virConnectListDefinedDomains
+virDomainCreate
+virDomainUndefine
description
virDomainCreateLinux
+virDomainDefineXML
virDomainGetXMLDesc
device
_virDomainKernel
disk
virDomainRestore
virDomainSave
doable
virDomainShutdown
-
does
virDomainDestroy
-
domains
virConnectListDomains
+
does
virDomainDefineXML
+virDomainDestroy
+virDomainUndefine
+
domains
virConnectListDefinedDomains
+virConnectListDomains
virConnectNumOfDomains
virConnectOpenReadOnly
+virDomainCreate
down
virDomainDestroy

Letter e:

encoded
virDomainGetXMLDesc
especially
virConnectClose
@@ -59,6 +68,7 @@ _virNodeInfo
virConnGetLastError
virConnectGetVersion
+virDomainDefineXML
virDomainGetID
virDomainGetName
virDomainGetUUID
@@ -83,7 +93,8 @@ virDomainFree
virDomainGetOSType
frequency
_virNodeInfo
-
from
virDomainResume
+
from
virDomainCreate
+virDomainResume
frozen
virDomainResume
virDomainSuspend
function
virConnSetErrorFunc
@@ -160,6 +171,7 @@ virGetLastError
virResetLastError
later
virDomainGetXMLDesc
+
launch
virDomainCreate
level
virConnectGetVersion
virCopyLastError
virDomainSuspend
@@ -180,7 +192,8 @@
lifetime
virDomainGetName
limited
virDomainGetInfo
line
_virDomainKernel
-
list
virConnectListDomains
+
list
virConnectListDefinedDomains
+virConnectListDomains
listed
virDomainSave
lookup
virDomainLookupByName
virDomainLookupByUUID
@@ -219,6 +232,7 @@ virGetVersion
model
_virNodeInfo
monitoring
virConnectClose
+
moves
virDomainCreate
multithreaded
virConnGetLastError
virGetLastError
virInitialize
diff --git a/docs/APIchunk2.html b/docs/APIchunk2.html index 2fdb42747..8f0dcb8f9 100644 --- a/docs/APIchunk2.html +++ b/docs/APIchunk2.html @@ -7,6 +7,7 @@

Letter n:

name
virConnectGetType
virDomainGetName
virDomainLookupByName
+
names
virConnectListDefinedDomains
nanoseconds
_virDomainInfo
need
virConnCopyLastError
virConnectClose
@@ -25,6 +26,7 @@
not
virConnGetLastError
virConnectClose
virConnectGetVersion
+virDomainDefineXML
virDomainDestroy
virDomainFree
virDomainGetName
@@ -32,11 +34,13 @@ virDomainReboot
virDomainSave
virDomainShutdown
+virDomainUndefine
virGetLastError
virGetVersion
number
_virDomainInfo
_virError
_virNodeInfo
+virConnectListDefinedDomains
virConnectListDomains
virConnectNumOfDomains
virDomainGetID
@@ -78,6 +82,7 @@ virConnectGetType
virConnectGetVersion
virCopyLastError
+virDomainDefineXML
virGetVersion
output
virDomainSave

Letter p:

parameter
virConnCopyLastError
@@ -95,32 +100,11 @@ virDomainSetMaxMemory
virDomainSetMemory
pointed
virResetError
-
pointer
virConnCopyLastError
-virConnGetLastError
-virConnResetLastError
-virConnSetErrorFunc
-virConnectClose
-virConnectGetType
-virConnectGetVersion
-virConnectListDomains
-virConnectNumOfDomains
-virConnectOpen
-virConnectOpenReadOnly
-virDefaultErrorFunc
-virDomainCreateLinux
-virDomainGetInfo
-virDomainGetName
-virDomainGetUUID
-virDomainLookupByID
-virDomainLookupByName
-virDomainLookupByUUID
-virDomainRestore
-virGetLastError
-virNodeGetInfo
-virResetError
-virSetErrorFunc
+
pointers
virConnectListDefinedDomains
pointing
_virDomainKernel
+
pools
virDomainCreate
potential
virInitialize
+
preferably
virDomainDefineXML
printing
virSetErrorFunc
priviledged
virConnectGetVersion
virDomainCreateLinux
@@ -133,6 +117,7 @@
process
virDomainResume
virDomainSuspend
provided
virConnSetErrorFunc
+virConnectListDefinedDomains
virErrorFunc
virSetErrorFunc
providing
LIBVIR_VERSION_NUMBER
@@ -187,9 +172,11 @@
running
_virDomainInfo
virConnectClose
virConnectGetVersion
+virDomainCreate
virDomainDestroy
virDomainFree
virDomainSave
+virDomainUndefine
runs
virDomainGetMaxMemory
virDomainSetMaxMemory
virDomainSetMemory
@@ -210,12 +197,14 @@
shutdown
virDomainDestroy
similar
virDomainCreateLinux
size
_virNodeInfo
+virConnectListDefinedDomains
virConnectListDomains
virDomainGetMaxMemory
virDomainSetMaxMemory
virDomainSetMemory
socket
_virNodeInfo
software
virConnectGetType
+
start
virDomainDefineXML
startup
virInitialize
state
_virDomainInfo
virDomainResume
@@ -225,10 +214,13 @@ virSetErrorFunc
still
virDomainReboot
virDomainShutdown
+
stop
virDomainUndefine
stopped
virDomainReboot
virDomainShutdown
-
store
virConnectListDomains
+
store
virConnectListDefinedDomains
+virConnectListDomains
virConnectOpen
+
stores
virConnectListDefinedDomains
string
_virError
_virNodeInfo
virConnectGetType
@@ -239,7 +231,9 @@ virDomainFree
virDomainGetInfo
virNodeGetInfo
+
succeed
virDomainCreate
success
virConnectClose
+virDomainCreate
virDomainDestroy
virDomainFree
virDomainGetInfo
@@ -252,6 +246,7 @@ virDomainSetMemory
virDomainShutdown
virDomainSuspend
+virDomainUndefine
virInitialize
virNodeGetInfo
successful
virDomainSave
diff --git a/docs/APIchunk3.html b/docs/APIchunk3.html index d282e0e72..31eccf366 100644 --- a/docs/APIchunk3.html +++ b/docs/APIchunk3.html @@ -40,7 +40,8 @@
two
virGetVersion
type
virDomainGetOSType
virGetVersion
-

Letter u:

uniform
_virNodeInfo
+

Letter u:

undefine
virDomainUndefine
+
uniform
_virNodeInfo
unknown
virGetVersion
unsigned
virDomainGetID
unused
virConnectOpen
@@ -129,4 +130,4 @@ d-m n-s t-z -

+

diff --git a/docs/APIconstructors.html b/docs/APIconstructors.html index a9e67d00f..8b2fadb44 100644 --- a/docs/APIconstructors.html +++ b/docs/APIconstructors.html @@ -5,6 +5,7 @@

Type virConnectPtr:

virConnectOpen
virConnectOpenReadOnly

Type virDomainPtr:

virDomainCreateLinux
+virDomainDefineXML
virDomainLookupByID
virDomainLookupByName
virDomainLookupByUUID
diff --git a/docs/APIfiles.html b/docs/APIfiles.html index d3cd9add5..316850c42 100644 --- a/docs/APIfiles.html +++ b/docs/APIfiles.html @@ -24,6 +24,7 @@ virConnectClose
virConnectGetType
virConnectGetVersion
+virConnectListDefinedDomains
virConnectListDomains
virConnectNumOfDomains
virConnectOpen
@@ -31,8 +32,10 @@ virConnectPtr
virDeviceMode
virDomain
+virDomainCreate
virDomainCreateFlags
virDomainCreateLinux
+virDomainDefineXML
virDomainDestroy
virDomainFree
virDomainGetID
@@ -60,12 +63,14 @@ virDomainShutdown
virDomainState
virDomainSuspend
+virDomainUndefine
virGetVersion
virInitialize
virNodeGetInfo
virNodeInfo
virNodeInfoPtr

Module virterror:

VIR_ERR_CALL_FAILED
+VIR_ERR_DOM_EXIST
VIR_ERR_DRIVER_FULL
VIR_ERR_ERROR
VIR_ERR_GET_FAILED
@@ -95,6 +100,7 @@ VIR_ERR_UNKNOWN_HOST
VIR_ERR_WARNING
VIR_ERR_XEN_CALL
+VIR_ERR_XML_ERROR
VIR_FROM_DOM
VIR_FROM_NONE
VIR_FROM_SEXPR
diff --git a/docs/APIfunctions.html b/docs/APIfunctions.html index f1ef9055f..d6e4d2822 100644 --- a/docs/APIfunctions.html +++ b/docs/APIfunctions.html @@ -1,6 +1,7 @@ -List of function manipulating types in libvirt

List of function manipulating types in libvirt

Type const unsigned char *:

virDomainLookupByUUID
+List of function manipulating types in libvirt

List of function manipulating types in libvirt

Type const char **:

virConnectListDefinedDomains
+

Type const unsigned char *:

virDomainLookupByUUID

Type int *:

virConnectListDomains

Type unsigned char *:

virDomainGetUUID

Type unsigned int:

virDomainCreateLinux
@@ -16,16 +17,19 @@ virConnectClose
virConnectGetType
virConnectGetVersion
+virConnectListDefinedDomains
virConnectListDomains
virConnectNumOfDomains
virDomainCreateLinux
+virDomainDefineXML
virDomainLookupByID
virDomainLookupByName
virDomainLookupByUUID
virDomainRestore
virNodeGetInfo

Type virDomainInfoPtr:

virDomainGetInfo
-

Type virDomainPtr:

virDomainDestroy
+

Type virDomainPtr:

virDomainCreate
+virDomainDestroy
virDomainFree
virDomainGetID
virDomainGetInfo
@@ -41,6 +45,7 @@ virDomainSetMemory
virDomainShutdown
virDomainSuspend
+virDomainUndefine

Type virErrorFunc:

virConnSetErrorFunc
virSetErrorFunc

Type virErrorPtr:

virConnCopyLastError
diff --git a/docs/APIsymbols.html b/docs/APIsymbols.html index d04efc3dc..70523c73b 100644 --- a/docs/APIsymbols.html +++ b/docs/APIsymbols.html @@ -18,6 +18,7 @@ VIR_DOMAIN_SHUTDOWN
VIR_DOMAIN_SHUTOFF
VIR_ERR_CALL_FAILED
+VIR_ERR_DOM_EXIST
VIR_ERR_DRIVER_FULL
VIR_ERR_ERROR
VIR_ERR_GET_FAILED
@@ -47,6 +48,7 @@ VIR_ERR_UNKNOWN_HOST
VIR_ERR_WARNING
VIR_ERR_XEN_CALL
+VIR_ERR_XML_ERROR
VIR_FROM_DOM
VIR_FROM_NONE
VIR_FROM_SEXPR
@@ -66,6 +68,7 @@ virConnectClose
virConnectGetType
virConnectGetVersion
+virConnectListDefinedDomains
virConnectListDomains
virConnectNumOfDomains
virConnectOpen
@@ -75,8 +78,10 @@ virDefaultErrorFunc
virDeviceMode
virDomain
+virDomainCreate
virDomainCreateFlags
virDomainCreateLinux
+virDomainDefineXML
virDomainDestroy
virDomainFree
virDomainGetID
@@ -104,6 +109,7 @@ virDomainShutdown
virDomainState
virDomainSuspend
+virDomainUndefine
virError
virErrorDomain
virErrorFunc
diff --git a/docs/examples/.cvsignore b/docs/examples/.cvsignore index 5f28847a8..eca76badc 100644 --- a/docs/examples/.cvsignore +++ b/docs/examples/.cvsignore @@ -1,5 +1,5 @@ .memdump Makefile.in Makefile -info1 suspend +info1 diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 18e1b134d..b6d768936 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -18,24 +18,24 @@ install-data-local: EXTRA_DIST=examples.xsl index.py examples.xml -noinst_PROGRAMS=info1 suspend - -info1_SOURCES=info1.c -info1_LDFLAGS= -info1_DEPENDENCIES= $(DEPS) -info1_LDADD= $(LDADDS) +noinst_PROGRAMS=suspend info1 suspend_SOURCES=suspend.c suspend_LDFLAGS= suspend_DEPENDENCIES= $(DEPS) suspend_LDADD= $(LDADDS) +info1_SOURCES=info1.c +info1_LDFLAGS= +info1_DEPENDENCIES= $(DEPS) +info1_LDADD= $(LDADDS) + valgrind: $(MAKE) CHECKER='valgrind' tests tests: $(noinst_PROGRAMS) @(echo '## examples regression tests') - @($(CHECKER) ./info1) @($(CHECKER) ./suspend) + @($(CHECKER) ./info1) diff --git a/docs/examples/examples.xml b/docs/examples/examples.xml index 5e5456784..af7d4b9fb 100644 --- a/docs/examples/examples.xml +++ b/docs/examples/examples.xml @@ -1,23 +1,4 @@ - - Extract informations about Xen domain 0 - Demonstrate the basic use of the library to connect to the hypervisor and extract domain informations. - info1 - info1 - Daniel Veillard - see Copyright for the status of this software. -

Informations
- - - - - - - - - - - Suspend a domain and then resume its execution Demonstrate the basic use of the library to suspend and resume a domain. If no id is given on the command line this script will suspend and resume the first domain found which is not Domain 0. @@ -40,33 +21,52 @@ + + Extract informations about Xen domain 0 + Demonstrate the basic use of the library to connect to the hypervisor and extract domain informations. + info1 + info1 + Daniel Veillard + see Copyright for the status of this software. +
Informations
+ + + + + + + + + + +
- + - + - + - + - + - + diff --git a/docs/html/libvirt-libvirt.html b/docs/html/libvirt-libvirt.html index ec716bce9..3250753d7 100644 --- a/docs/html/libvirt-libvirt.html +++ b/docs/html/libvirt-libvirt.html @@ -19,11 +19,14 @@ The content of this structure is not made public by the API.
int	virConnectClose			(virConnectPtr conn)
const char *	virConnectGetType	(virConnectPtr conn)
int	virConnectGetVersion		(virConnectPtr conn, 
unsigned long * hvVer)
+
int	virConnectListDefinedDomains	(virConnectPtr conn, 
const char ** names,
int maxnames)
int	virConnectListDomains		(virConnectPtr conn, 
int * ids,
int maxids)
int	virConnectNumOfDomains		(virConnectPtr conn)
virConnectPtr	virConnectOpen		(const char * name)
virConnectPtr	virConnectOpenReadOnly	(const char * name)
+
int	virDomainCreate			(virDomainPtr domain)
virDomainPtr	virDomainCreateLinux	(virConnectPtr conn, 
const char * xmlDesc,
unsigned int flags)
+
virDomainPtr	virDomainDefineXML	(virConnectPtr conn, 
const char * xml)
int	virDomainDestroy		(virDomainPtr domain)
int	virDomainFree			(virDomainPtr domain)
unsigned int	virDomainGetID		(virDomainPtr domain)
@@ -44,6 +47,7 @@ The content of this structure is not made public by the API.
int	virDomainSetMemory		(virDomainPtr domain, 
unsigned long memory)
int	virDomainShutdown		(virDomainPtr domain)
int	virDomainSuspend		(virDomainPtr domain)
+
int	virDomainUndefine		(virDomainPtr domain)
int	virGetVersion			(unsigned long * libVer, 
const char * type,
unsigned long * typeVer)
int	virInitialize			(void)
int	virNodeGetInfo			(virConnectPtr conn, 
virNodeInfoPtr info)
@@ -113,7 +117,9 @@ The content of this structure is not made public by the API.

Get the name of the Hypervisor software used.

conn:pointer to the hypervisor connection
Returns:NULL in case of error, a static zero terminated string otherwise.

Function: virConnectGetVersion

int	virConnectGetVersion		(virConnectPtr conn, 
unsigned long * hvVer)

Get the version level of the Hypervisor running. This may work only with hypervisor call, i.e. with priviledged access to the hypervisor, not with a Read-Only connection.

-
conn:pointer to the hypervisor connection
hvVer:return value for the version of the running hypervisor (OUT)
Returns:-1 in case of error, 0 otherwise. if the version can't be extracted by lack of capacities returns 0 and @hvVer is 0, otherwise @hvVer value is major * 1,000,000 + minor * 1,000 + release

Function: virConnectListDomains

int	virConnectListDomains		(virConnectPtr conn, 
int * ids,
int maxids)
+
conn:pointer to the hypervisor connection
hvVer:return value for the version of the running hypervisor (OUT)
Returns:-1 in case of error, 0 otherwise. if the version can't be extracted by lack of capacities returns 0 and @hvVer is 0, otherwise @hvVer value is major * 1,000,000 + minor * 1,000 + release

Function: virConnectListDefinedDomains

int	virConnectListDefinedDomains	(virConnectPtr conn, 
const char ** names,
int maxnames)
+

list the defined domains, stores the pointers to the names in @names

+
conn:pointer to the hypervisor connection
names:pointer to an array to store the names
maxnames:size of the array
Returns:the number of names provided in the array or -1 in case of error

Function: virConnectListDomains

int	virConnectListDomains		(virConnectPtr conn, 
int * ids,
int maxids)

Collect the list of active domains, and store their ID in @maxids

conn:pointer to the hypervisor connection
ids:array to collect the list of IDs of active domains
maxids:size of @ids
Returns:the number of domain found or -1 in case of error

Function: virConnectNumOfDomains

int	virConnectNumOfDomains		(virConnectPtr conn)

Provides the number of active domains.

@@ -121,9 +127,13 @@ The content of this structure is not made public by the API.

This function should be called first to get a connection to the Hypervisor and xen store

name:optional argument currently unused, pass NULL
Returns:a pointer to the hypervisor connection or NULL in case of error

Function: virConnectOpenReadOnly

virConnectPtr	virConnectOpenReadOnly	(const char * name)

This function should be called first to get a restricted connection to the libbrary functionalities. The set of APIs usable are then restricted on the available methods to control the domains.

-
name:optional argument currently unused, pass NULL
Returns:a pointer to the hypervisor connection or NULL in case of error

Function: virDomainCreateLinux

virDomainPtr	virDomainCreateLinux	(virConnectPtr conn, 
const char * xmlDesc,
unsigned int flags)
+
name:optional argument currently unused, pass NULL
Returns:a pointer to the hypervisor connection or NULL in case of error

Function: virDomainCreate

int	virDomainCreate			(virDomainPtr domain)
+

launch a defined domain. If the call succeed the domain moves from the defined to the running domains pools.

+
domain:pointer to a defined domain
Returns:0 in case of success, -1 in case of error

Function: virDomainCreateLinux

virDomainPtr	virDomainCreateLinux	(virConnectPtr conn, 
const char * xmlDesc,
unsigned int flags)

Launch a new Linux guest domain, based on an XML description similar to the one returned by virDomainGetXMLDesc() This function may requires priviledged access to the hypervisor.

-
conn:pointer to the hypervisor connection
xmlDesc:an XML description of the domain
flags:an optional set of virDomainFlags
Returns:a new domain object or NULL in case of failure

Function: virDomainDestroy

int	virDomainDestroy		(virDomainPtr domain)
+
conn:pointer to the hypervisor connection
xmlDesc:an XML description of the domain
flags:an optional set of virDomainFlags
Returns:a new domain object or NULL in case of failure

Function: virDomainDefineXML

virDomainPtr	virDomainDefineXML	(virConnectPtr conn, 
const char * xml)
+

define a domain, but does not start it

+
conn:pointer to the hypervisor connection
xml:the XML description for the domain, preferably in UTF-8
Returns:NULL in case of error, a pointer to the domain otherwise

Function: virDomainDestroy

int	virDomainDestroy		(virDomainPtr domain)

Destroy the domain object. The running instance is shutdown if not down already and all resources used by it are given back to the hypervisor. The data structure is freed and should not be used thereafter if the call does not return an error. This function may requires priviledged access

domain:a domain object
Returns:0 in case of success and -1 in case of failure.

Function: virDomainFree

int	virDomainFree			(virDomainPtr domain)

Free the domain object. The running instance is kept alive. The data structure is freed and should not be used thereafter.

@@ -163,7 +173,9 @@ The content of this structure is not made public by the API.

Shutdown a domain, the domain object is still usable there after but the domain OS is being stopped. Note that the guest OS may ignore the request. TODO: should we add an option for reboot, knowing it may not be doable in the general case ?

domain:a domain object
Returns:0 in case of success and -1 in case of failure.

Function: virDomainSuspend

int	virDomainSuspend		(virDomainPtr domain)

Suspends an active domain, the process is frozen without further access to CPU resources and I/O but the memory used by the domain at the hypervisor level will stay allocated. Use virDomainResume() to reactivate the domain. This function may requires priviledged access.

-
domain:a domain object
Returns:0 in case of success and -1 in case of failure.

Function: virGetVersion

int	virGetVersion			(unsigned long * libVer, 
const char * type,
unsigned long * typeVer)
+
domain:a domain object
Returns:0 in case of success and -1 in case of failure.

Function: virDomainUndefine

int	virDomainUndefine		(virDomainPtr domain)
+

undefine a domain but does not stop it if it is running

+
domain:pointer to a defined domain
Returns:0 in case of success, -1 in case of error

Function: virGetVersion

int	virGetVersion			(unsigned long * libVer, 
const char * type,
unsigned long * typeVer)

Provides two information back, @libVer is the version of the library while @typeVer will be the version of the hypervisor type @type against which the library was compiled. If @type is NULL, "Xen" is assumed, if @type is unknown or not availble, an error code will be returned and @typeVer will be 0.

libVer:return value for the library version (OUT)
type:hypervisor type
typeVer:return value for the version of the hypervisor (OUT)
Returns:-1 in case of failure, 0 otherwise, and values for @libVer and @typeVer have the format major * 1,000,000 + minor * 1,000 + release.

Function: virInitialize

int	virInitialize			(void)

Initialize the library. It's better to call this routine at startup in multithreaded applications to avoid potential race when initializing the library.

diff --git a/docs/html/libvirt-virterror.html b/docs/html/libvirt-virterror.html index ac4c063b7..37c5e5a21 100644 --- a/docs/html/libvirt-virterror.html +++ b/docs/html/libvirt-virterror.html @@ -73,6 +73,8 @@ void virErrorFunc (void * userData,
VIR_ERR_NO_XENSTORE = 24 : could not open Xen Store control VIR_ERR_DRIVER_FULL = 25 : too many drivers registered VIR_ERR_CALL_FAILED = 26 : not supported by the drivers + VIR_ERR_XML_ERROR = 27 : an XML description is not well formed or broken + VIR_ERR_DOM_EXIST = 28 : the domain already exist }

Function: virConnCopyLastError

int	virConnCopyLastError		(virConnectPtr conn, 
virErrorPtr to)

Copy the content of the last error caught on that connection One will need to free the result with virResetError()

diff --git a/docs/libvirt-api.xml b/docs/libvirt-api.xml index 348820374..450834739 100644 --- a/docs/libvirt-api.xml +++ b/docs/libvirt-api.xml @@ -40,12 +40,16 @@ + + + + @@ -83,6 +87,7 @@ + @@ -100,12 +105,13 @@ - + + @@ -151,7 +157,8 @@ - + + @@ -181,6 +188,7 @@ + @@ -288,6 +296,13 @@ + + list the defined domains, stores the pointers to the names in @names + + + + + Collect the list of active domains, and store their ID in @maxids @@ -320,6 +335,11 @@ + + launch a defined domain. If the call succeed the domain moves from the defined to the running domains pools. + + + Launch a new Linux guest domain, based on an XML description similar to the one returned by virDomainGetXMLDesc() This function may requires priviledged access to the hypervisor. @@ -327,6 +347,12 @@ + + define a domain, but does not start it + + + + Destroy the domain object. The running instance is shutdown if not down already and all resources used by it are given back to the hypervisor. The data structure is freed and should not be used thereafter if the call does not return an error. This function may requires priviledged access @@ -438,6 +464,11 @@ + + undefine a domain but does not stop it if it is running + + + Signature of a function to use when there is an error raised by the library. diff --git a/docs/libvirt-refs.xml b/docs/libvirt-refs.xml index 7c52d1808..a377694a5 100644 --- a/docs/libvirt-refs.xml +++ b/docs/libvirt-refs.xml @@ -19,6 +19,7 @@ + @@ -48,6 +49,7 @@ + @@ -67,6 +69,7 @@ + @@ -76,8 +79,10 @@ + + @@ -105,6 +110,7 @@ + @@ -143,6 +149,7 @@ + @@ -172,6 +179,7 @@ + @@ -195,6 +203,7 @@ + @@ -204,8 +213,10 @@ + + @@ -233,6 +244,7 @@ + @@ -263,6 +275,7 @@ + @@ -273,6 +286,9 @@ + + + @@ -302,9 +318,11 @@ + + @@ -315,6 +333,7 @@ + @@ -331,6 +350,7 @@ + @@ -378,6 +398,7 @@ + @@ -385,8 +406,10 @@ + + @@ -414,6 +437,7 @@ + @@ -422,6 +446,7 @@ + @@ -451,6 +476,7 @@ + @@ -585,6 +611,7 @@ + @@ -692,6 +719,7 @@ + @@ -711,6 +739,7 @@ + @@ -801,6 +830,7 @@ + @@ -844,9 +874,11 @@ + + @@ -856,6 +888,7 @@ + @@ -932,11 +965,13 @@ + + @@ -990,8 +1025,17 @@ + + + + + + + + + @@ -1005,12 +1049,16 @@ + + + + @@ -1080,6 +1128,7 @@ + @@ -1116,6 +1165,7 @@ + @@ -1272,6 +1322,9 @@ + + + @@ -1305,6 +1358,7 @@ + @@ -1375,6 +1429,9 @@ + + + @@ -1393,6 +1450,9 @@ + + + @@ -1424,6 +1484,7 @@ + @@ -1431,6 +1492,7 @@ + @@ -1438,6 +1500,7 @@ + @@ -1497,6 +1560,7 @@ + @@ -1537,38 +1601,21 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + @@ -1590,6 +1637,7 @@ + @@ -1702,9 +1750,11 @@ + + @@ -1747,6 +1797,7 @@ + @@ -1758,6 +1809,9 @@ + + + @@ -1779,14 +1833,21 @@ + + + + + + + @@ -1801,8 +1862,12 @@ + + + + @@ -1815,6 +1880,7 @@ + @@ -1902,6 +1968,9 @@ + + + diff --git a/src/Makefile.am b/src/Makefile.am index f9453a2fb..a4471e8b0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,8 +9,10 @@ EXTRA_DIST = libvirt_sym.version lib_LTLIBRARIES = libvirt.la libvirt_la_LIBADD = @LIBXML_LIBS@ + libvirt_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvirt_sym.version \ -version-info @LIBVIRT_VERSION_INFO@ + libvirt_la_SOURCES = \ libvirt.c internal.h \ hash.c hash.h \ @@ -22,10 +24,10 @@ libvirt_la_SOURCES = \ virterror.c \ driver.h -bin_PROGRAMS=virsh +bin_PROGRAMS = virsh -virsh_SOURCES=virsh.c +virsh_SOURCES = virsh.c virsh_LDFLAGS = virsh_DEPENDENCIES = $(DEPS) -virsh_LDADD= $(LDADDS) $(VIRSH_LIBS) +virsh_LDADD = $(LDADDS) $(VIRSH_LIBS) diff --git a/src/xml.c b/src/xml.c index ba417aa7d..b273154be 100644 --- a/src/xml.c +++ b/src/xml.c @@ -114,6 +114,16 @@ virBufferAdd(virBufferPtr buf, const char *str, int len) return (0); } +void +virBufferFree(virBufferPtr buf) +{ + if (buf) { + if (buf->content) + free(buf->content); + free(buf); + } +} + /** * virBufferVSprintf: * @buf: the buffer to dump diff --git a/src/xml.h b/src/xml.h index 8d63b3402..7121b55d4 100644 --- a/src/xml.h +++ b/src/xml.h @@ -24,6 +24,7 @@ struct _virBuffer { unsigned int size; /* The buffer size */ }; +void virBufferFree(virBufferPtr buf); int virBufferAdd(virBufferPtr buf, const char *str, int len); int virBufferVSprintf(virBufferPtr buf, const char *format, ...); char *virDomainParseXMLDesc(const char *xmldesc, char **name); diff --git a/src/xmlrpc.c b/src/xmlrpc.c index 531c2fc76..eceb2872c 100644 --- a/src/xmlrpc.c +++ b/src/xmlrpc.c @@ -64,7 +64,7 @@ static xmlNodePtr xmlNextElement(xmlNodePtr node) return node; } -static xmlRpcValuePtr xmlRpcValueUnmarshalDateTime(xmlNodePtr node) +static xmlRpcValuePtr xmlRpcValueUnmarshalDateTime(xmlNodePtr node ATTRIBUTE_UNUSED) { /* we don't need this */ TODO; @@ -78,7 +78,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalString(xmlNodePtr node) return ret; } -static xmlRpcValuePtr xmlRpcValueUnmarshalBase64(xmlNodePtr node) +static xmlRpcValuePtr xmlRpcValueUnmarshalBase64(xmlNodePtr node ATTRIBUTE_UNUSED) { /* we don't need this */ TODO; @@ -187,7 +187,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalDict(xmlNodePtr node) xmlRpcValuePtr xmlRpcValueUnmarshal(xmlNodePtr node) { xmlNodePtr n; - xmlRpcValuePtr ret; + xmlRpcValuePtr ret = NULL; if (xmlStrEqual(node->name, BAD_CAST "value")) { n = xmlFirstElement(node); @@ -371,7 +371,7 @@ xmlRpcValuePtr xmlRpcUnmarshalResponse(xmlNodePtr node, bool *is_fault) static char *xmlRpcCallRaw(const char *url, const char *request) { void *cxt; - char *contentType = "text/xml"; + char *contentType = (char *) "text/xml"; int len, ret, serrno; char *response = NULL; @@ -442,7 +442,7 @@ static char **xmlRpcStringArray(xmlRpcValuePtr value) ret[i] = ptr; ptr += strlen(s) + 1; } else - ret[i] = ""; + ret[i] = (char *) ""; } ret[i] = NULL; @@ -450,29 +450,15 @@ static char **xmlRpcStringArray(xmlRpcValuePtr value) return ret; } -int xmlRpcCall(xmlRpcContextPtr context, const char *method, - const char *retfmt, const char *fmt, ...) +xmlRpcValuePtr * +xmlRpcArgvNew(const char *fmt, va_list ap, int *argc) { - va_list ap; - const char *ptr; - int argc; xmlRpcValuePtr *argv; - virBufferPtr buf; + const char *ptr; int i; - char *ret; - xmlDocPtr xml; - xmlNodePtr node; - bool fault; - xmlRpcValuePtr value; - void *retval; - - argc = strlen(fmt); - argv = malloc(sizeof(*argv) * argc); - - va_start(ap, fmt); - - if (retfmt && *retfmt) - retval = va_arg(ap, void *); + + *argc = strlen(fmt); + argv = malloc(sizeof(*argv) * *argc); i = 0; for (ptr = fmt; *ptr; ptr++) { @@ -494,23 +480,54 @@ int xmlRpcCall(xmlRpcContextPtr context, const char *method, argv[i]->value.string = strdup(va_arg(ap, const char *)); break; default: - return -1; + xmlRpcArgvFree(i, argv); + return NULL; } i++; } - va_end(ap); - - buf = xmlRpcMarshalRequest(method, argc, argv); + return argv; +} +void +xmlRpcArgvFree(int argc, xmlRpcValuePtr *argv) +{ + int i; for (i = 0; i < argc; i++) xmlRpcValueFree(argv[i]); free(argv); +} + +int xmlRpcCall(xmlRpcContextPtr context, const char *method, + const char *retfmt, const char *fmt, ...) +{ + va_list ap; + int argc; + xmlRpcValuePtr *argv; + virBufferPtr buf; + char *ret; + xmlDocPtr xml; + xmlNodePtr node; + bool fault; + xmlRpcValuePtr value; + void *retval = NULL; + + va_start(ap, fmt); + + if (retfmt && *retfmt) + retval = va_arg(ap, void *); + + argv = xmlRpcArgvNew(fmt, ap, &argc); + + va_end(ap); + + buf = xmlRpcMarshalRequest(method, argc, argv); + + xmlRpcArgvFree(argc, argv); ret = xmlRpcCallRaw(context->uri, buf->content); - free(buf->content); - free(buf); + virBufferFree(buf); xml = xmlReadDoc((const xmlChar *)ret, "response.xml", NULL, XML_PARSE_NOENT | XML_PARSE_NONET | diff --git a/src/xmlrpc.h b/src/xmlrpc.h index 286675380..3a8b750f6 100644 --- a/src/xmlrpc.h +++ b/src/xmlrpc.h @@ -17,6 +17,7 @@ #include #include #include +#include #include "xml.h" @@ -85,6 +86,9 @@ struct _xmlRpcValue { struct _xmlRpcContext; +xmlRpcValuePtr *xmlRpcArgvNew(const char *fmt, va_list ap, int *argc); +void xmlRpcArgvFree(int argc, xmlRpcValuePtr *argv); + virBufferPtr xmlRpcMarshalRequest(const char *request, int argc, xmlRpcValuePtr *argv); diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 000000000..c576a2288 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,31 @@ +## Process this file with automake to produce Makefile.in + +LIBVIRT = $(top_builddir)/src/.libs/libvirt.a + +INCLUDES = \ + -I$(top_builddir)/include \ + -I$(top_builddir)/src \ + -I@top_srcdir@/include \ + @LIBXML_CFLAGS@ + +LDADDS = \ + @STATIC_BINARIES@ \ + @LIBXML_LIBS@ \ + $(LIBVIRT) + +EXTRA_DIST = xmlrpcserver.py + +noinst_PROGRAMS = xmlrpctest + +# Note: xmlrpc.[c|h] is not in libvirt yet +xmlrpctest_SOURCES = \ + xmlrpctest.c \ + testutils.c testutils.h \ + $(top_builddir)/src/xmlrpc.c \ + $(top_builddir)/src/xmlrpc.h + +xmlrpctest_LDFLAGS = +xmlrpctest_LDADD = $(LDADDS) + +$(LIBVIRT): + -@(cd $(top_builddir)/src && $(MAKE) MAKEFLAGS+=--silent) diff --git a/tests/test_xmlrpc.sh b/tests/test_xmlrpc.sh new file mode 100755 index 000000000..ccdfdbc43 --- /dev/null +++ b/tests/test_xmlrpc.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +./xmlrpcserver.py >/dev/null 2>&1 & +sleep 1 +./xmlrpctest +pkill -f xmlrpcserver.py >/dev/null 2>&1 & diff --git a/tests/testutils.c b/tests/testutils.c new file mode 100644 index 000000000..d79b9e5fb --- /dev/null +++ b/tests/testutils.c @@ -0,0 +1,74 @@ +/* + * utils.c: basic test utils + * + * Copyright (C) 2005 Red Hat, Inc. + * + * See COPYING.LIB for the License of this software + * + * Karel Zak + * + * $Id$ + */ + +#include +#include +#include + +#include "testutils.h" + +#define GETTIMEOFDAY(T) gettimeofday(T, NULL) +#define DIFF_MSEC(T, U) \ + ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ + ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) + +double +virtTestCountAverage(double *items, int nitems) +{ + long double sum = 0; + int i; + + for (i=1; i < nitems; i++) + sum += items[i]; + + return (double) (sum / nitems); +} + +/* + * Runs test anf count average time (if the nloops is grater than 1) + * + * returns: -1 = error, 0 = success + */ +int +virtTestRun(const char *title, int nloops, int (*body)(void *data), void *data) +{ + int i, ret = 0; + double *ts = NULL; + + if (nloops > 1 && (ts = calloc(nloops, + sizeof(double)))==NULL) + return -1; + + for (i=0; i < nloops; i++) { + struct timeval before, after; + + if (ts) + GETTIMEOFDAY(&before); + if ((ret = body(data)) != 0) + break; + if (ts) { + GETTIMEOFDAY(&after); + ts[i] = DIFF_MSEC(&after, &before); + } + } + if (ret == 0 && ts) + fprintf(stderr, "%-50s ... OK [%.5f ms]\n", title, + virtTestCountAverage(ts, nloops)); + else if (ret == 0) + fprintf(stderr, "%-50s ... OK\n", title); + else + fprintf(stderr, "%-50s ... FAILED\n", title); + + if (ts) + free(ts); + return ret; +} diff --git a/tests/testutils.h b/tests/testutils.h new file mode 100644 index 000000000..8976e8222 --- /dev/null +++ b/tests/testutils.h @@ -0,0 +1,33 @@ +/* + * utils.c: test utils + * + * Copyright (C) 2005 Red Hat, Inc. + * + * See COPYING.LIB for the License of this software + * + * Karel Zak + * + * $Id$ + */ + +#ifndef __VIT_TEST_UTILS_H__ +#define __VIT_TEST_UTILS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +double virtTestCountAverage (double *items, + int nitems); + +int virtTestRun (const char *title, + int nloops, + int (*body)(void *data), + void *data); + +#ifdef __cplusplus +} +#endif +#endif /* __VIT_TEST_UTILS_H__ */ + diff --git a/tests/xmlrpcserver.py b/tests/xmlrpcserver.py new file mode 100755 index 000000000..debff9337 --- /dev/null +++ b/tests/xmlrpcserver.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +# +# xmlrpcserver.py: simple server for XML-RPC tests +# +# Copyright (C) 2005 Red Hat, Inc. +# +# See COPYING.LIB for the License of this software +# +# Karel Zak +# +# $Id$ +# +# +# simple client: +# +# >>> import xmlrpclib +# >>> s=xmlrpclib.Server('http://localhost:8000') +# >>> s.plus(10,10) +# 20 +# + +import sys +from SimpleXMLRPCServer import SimpleXMLRPCServer + +SERVER_PORT = 8000 + + +class VirtRPCServer(SimpleXMLRPCServer): + def _dispatch(self, method, params): + try: + func = getattr(self, 'test_' + method) + except AttributeError: + raise Exception('method "%s" is not supported' % method) + else: + return func(*params) + + def test_plus(self, x, y): + return x + y + + +server = VirtRPCServer(("localhost", SERVER_PORT)) +server.serve_forever() + + + +# vim: set tabstop=4: +# vim: set shiftwidth=4: +# vim: set expandtab: diff --git a/tests/xmlrpctest.c b/tests/xmlrpctest.c new file mode 100644 index 000000000..02f0fa497 --- /dev/null +++ b/tests/xmlrpctest.c @@ -0,0 +1,245 @@ +/* + * xmlrpctest.c: simple client for XML-RPC tests + * + * Copyright (C) 2005 Red Hat, Inc. + * + * See COPYING.LIB for the License of this software + * + * Karel Zak + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libvirt.h" +#include "xml.h" +#include "xmlrpc.h" + +#include "testutils.h" + + +#define NLOOPS 100 /* default number of loops per test */ + +static char *progname; + + +static int +testMethodPlusINT(void *data) +{ + int retval = 0; + xmlRpcContextPtr cxt = (xmlRpcContextPtr) data; + + if (xmlRpcCall(cxt, "plus", "i", "ii", + (const char *) &retval, 10, 10) < 0) + return -1; + + return retval==(10+10) ? 0 : -1; +} + +static int +testMethodPlusDOUBLE(void *data) +{ + double retval = 0; + xmlRpcContextPtr cxt = (xmlRpcContextPtr) data; + + if (xmlRpcCall(cxt, "plus", "f", "ff", + (const char *) &retval, 10.1234, 10.1234) < 0) + return -1; + + return retval==(10.1234+10.1234) ? 0 : -1; +} + +static virBufferPtr +marshalRequest(const char *fmt, ...) +{ + int argc; + xmlRpcValuePtr *argv; + virBufferPtr buf; + va_list ap; + + va_start(ap, fmt); + argv = xmlRpcArgvNew(fmt, ap, &argc); + va_end(ap); + + buf = xmlRpcMarshalRequest("test", argc, argv); + + xmlRpcArgvFree(argc, argv); + return buf; +} + +static int +checkRequestValue(const char *xmlstr, const char *xpath, int type, void *expected) +{ + xmlDocPtr xml = NULL; + xmlXPathContextPtr ctxt = NULL; + xmlXPathObjectPtr obj = NULL; + int ret = -1; + + xml = xmlReadDoc((const xmlChar *) xmlstr, "xmlrpctest.xml", NULL, + XML_PARSE_NOENT | XML_PARSE_NONET | + XML_PARSE_NOERROR | XML_PARSE_NOWARNING); + if (!xml) + goto error; + + if (!(ctxt = xmlXPathNewContext(xml))) + goto error; + + if (!(obj = xmlXPathEval(BAD_CAST xpath, ctxt))) + goto error; + + switch(type) { + case XML_RPC_INTEGER: + if ((obj->type != XPATH_NUMBER) || + ((int) obj->floatval != *((int *)expected))) + goto error; + break; + case XML_RPC_DOUBLE: + if ((obj->type != XPATH_NUMBER) || + ((double) obj->floatval != *((double *)expected))) + goto error; + break; + case XML_RPC_STRING: + if ((obj->type != XPATH_STRING) || + (strcmp((const char *)obj->stringval, (const char *)expected))) + goto error; + break; + default: + goto error; + } + ret = 0; + +error: + if (obj) + xmlXPathFreeObject(obj); + if (ctxt) + xmlXPathFreeContext(ctxt); + if (xml) + xmlFreeDoc(xml); + return ret; +} + +static int +testMarshalRequestINT(void *data) +{ + int num = INT_MAX; + int ret = 0; + int check = data ? *((int *)data) : 0; + virBufferPtr buf = marshalRequest("i", num); + + if (check) + ret = checkRequestValue(buf->content, + "number(/methodCall/params/param[1]/value/int)", + XML_RPC_INTEGER, (void *) &num); + + virBufferFree(buf); + return ret; +} + +static int +testMarshalRequestSTRING(void *data ATTRIBUTE_UNUSED) +{ + const char *str = "This library will be really sexy."; + int ret = 0; + int check = data ? *((int *)data) : 0; + virBufferPtr buf = marshalRequest("s", str); + + if (check) + ret = checkRequestValue(buf->content, + "string(/methodCall/params/param[1]/value/string)", + XML_RPC_STRING, (void *) str); + + virBufferFree(buf); + return ret; +} + +static int +testMarshalRequestDOUBLE(void *data) +{ + double num = 123456789.123; + int ret = 0; + int check = data ? *((int *)data) : 0; + virBufferPtr buf = marshalRequest("f", num); + + if (check) + ret = checkRequestValue(buf->content, + "number(/methodCall/params/param[1]/value/double)", + XML_RPC_DOUBLE, (void *) &num); + + virBufferFree(buf); + return ret; +} + +int +main(int argc, char **argv) +{ + xmlRpcContextPtr cxt = NULL; + int check = 1; + int ret = 0; + const char *url = "http://localhost:8000"; + + progname = argv[0]; + + if (argc > 2) + { + fprintf(stderr, "Usage: %s [url]\n", progname); + exit(EXIT_FAILURE); + } + if (argc == 2) + url = argv[1]; + + if (!(cxt = xmlRpcContextNew(url))) + { + fprintf(stderr, "%s: failed create new RPC context\n", progname); + exit(EXIT_FAILURE); + } + + /* client-server tests */ + if (virtTestRun("XML-RPC methodCall INT+INT", + NLOOPS, testMethodPlusINT, (void *) cxt) != 0) + ret = -1; + + if (virtTestRun("XML-RPC methodCall DOUBLE+DOUBLE", + NLOOPS, testMethodPlusDOUBLE, (void *) cxt) != 0) + ret = -1; + + /* regression / performance tests */ + if (virtTestRun("XML-RPC request marshalling: INT (check)", + 1, testMarshalRequestINT, (void *) &check) != 0) + ret = -1; + if (virtTestRun("XML-RPC request marshalling: INT", + NLOOPS, testMarshalRequestINT, NULL) != 0) + ret = -1; + + if (virtTestRun("XML-RPC request marshalling: DOUBLE (check)", + 1, testMarshalRequestDOUBLE, (void *) &check) != 0) + ret = -1; + if (virtTestRun("XML-RPC request marshalling: DOUBLE", + NLOOPS, testMarshalRequestDOUBLE, NULL) != 0) + ret = -1; + + if (virtTestRun("XML-RPC request marshalling: STRING (check)", + 1, testMarshalRequestSTRING, (void *) &check) != 0) + ret = -1; + if (virtTestRun("XML-RPC request marshalling: STRING", + NLOOPS, testMarshalRequestSTRING, NULL) != 0) + ret = -1; + + xmlRpcContextFree(cxt); + + exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); +} + + +/* + * vim: set tabstop=4: + * vim: set shiftwidth=4: + * vim: set expandtab: + */ -- 2.39.5