mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-27 06:50:23 +03:00
Added tests for the SEXPR<->XML conversion process
This commit is contained in:
parent
0658b086cd
commit
441246297e
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
Thu Aug 24 10:04:02 EDT 2006 Daniel Berrange <berrange@redhat.com>
|
||||
|
||||
* tests/xml2sexpr.c, tests/sexpr2xml.c: New tests suites for
|
||||
validating the SEXPR<->XML conversion
|
||||
* tests/*.sexpr, tests/*.xml: Data files for test suite
|
||||
* src/xend_internal.h, src/xend_internal.c: Expose the method
|
||||
for converting SEXPR -> XML to allow use by unit tests
|
||||
* src/xs_internal.c: Check if connection is NULL before
|
||||
deferencing it - test suite passes in NULL.
|
||||
|
||||
Mon Aug 21 13:00:03 EDT 2006 Daniel Berrange <berrange@redhat.com>
|
||||
|
||||
* src/virsh.c: check return code of virConnectListDomains in case
|
||||
|
@ -1655,6 +1655,20 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
xend_parse_domain_sexp(virConnectPtr conn, char *sexpr) {
|
||||
struct sexpr *root = string2sexpr(sexpr);
|
||||
char *data;
|
||||
|
||||
if (!root)
|
||||
return NULL;
|
||||
|
||||
data = xend_parse_sexp_desc(conn, root);
|
||||
|
||||
sexpr_free(root);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* sexpr_to_xend_domain_info:
|
||||
|
@ -613,6 +613,8 @@ char *xenDaemonDomainDumpXMLByID(virConnectPtr xend,
|
||||
*/
|
||||
int xend_log(virConnectPtr xend, char *buffer, size_t n_buffer);
|
||||
|
||||
char *xend_parse_domain_sexp(virConnectPtr conn, char *root);
|
||||
|
||||
/* refactored ones */
|
||||
void xenDaemonRegister(void);
|
||||
int xenDaemonOpen(virConnectPtr conn, const char *name, int flags);
|
||||
|
@ -148,7 +148,7 @@ virDomainDoStoreQuery(virConnectPtr conn, int domid, const char *path)
|
||||
char s[256];
|
||||
unsigned int len = 0;
|
||||
|
||||
if (conn->xshandle == NULL)
|
||||
if (!conn || conn->xshandle == NULL)
|
||||
return (NULL);
|
||||
|
||||
snprintf(s, 255, "/local/domain/%d/%s", domid, path);
|
||||
|
@ -3,3 +3,5 @@ Makefile.in
|
||||
.deps
|
||||
.libs
|
||||
xmlrpctest
|
||||
sexpr2xmltest
|
||||
xml2sexprtest
|
||||
|
@ -16,7 +16,9 @@ LDADDS = \
|
||||
|
||||
EXTRA_DIST = xmlrpcserver.py
|
||||
|
||||
noinst_PROGRAMS = xmlrpctest
|
||||
noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest
|
||||
|
||||
TESTS = xml2sexprtest sexpr2xmltest
|
||||
|
||||
# Note: xmlrpc.[c|h] is not in libvirt yet
|
||||
xmlrpctest_SOURCES = \
|
||||
@ -28,5 +30,17 @@ xmlrpctest_SOURCES = \
|
||||
xmlrpctest_LDFLAGS =
|
||||
xmlrpctest_LDADD = $(LDADDS)
|
||||
|
||||
xml2sexprtest_SOURCES = \
|
||||
xml2sexprtest.c \
|
||||
testutils.c testutils.h
|
||||
xml2sexprtest_LDFLAGS =
|
||||
xml2sexprtest_LDADD = $(LDADDS)
|
||||
|
||||
sexpr2xmltest_SOURCES = \
|
||||
sexpr2xmltest.c \
|
||||
testutils.c testutils.h
|
||||
sexpr2xmltest_LDFLAGS =
|
||||
sexpr2xmltest_LDADD = $(LDADDS)
|
||||
|
||||
$(LIBVIRT):
|
||||
-@(cd $(top_builddir)/src && $(MAKE) MAKEFLAGS+=--silent)
|
||||
|
1
tests/sexpr2xml-fv.sexpr
Normal file
1
tests/sexpr2xml-fv.sexpr
Normal file
@ -0,0 +1 @@
|
||||
(domain (domid 3)(name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)(cdrom '/root/boot.iso')(acpi 1)(vnc 1)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))
|
35
tests/sexpr2xml-fv.xml
Normal file
35
tests/sexpr2xml-fv.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<domain type='xen' id='3'>
|
||||
<name>fvtest</name>
|
||||
<uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
|
||||
<os>
|
||||
<type>hvm</type>
|
||||
<loader>/usr/lib/xen/boot/hvmloader</loader>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<memory>409600</memory>
|
||||
<vcpu>1</vcpu>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<features>
|
||||
<acpi/>
|
||||
</features>
|
||||
<devices>
|
||||
<emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<source file='/root/foo.img'/>
|
||||
<target dev='hda'/>
|
||||
</disk>
|
||||
<interface type='bridge'>
|
||||
<source bridge='xenbr0'/>
|
||||
<mac address='00:16:3e:1b:b1:47'/>
|
||||
<script path='vif-bridge'/>
|
||||
</interface>
|
||||
<disk type='file' device='cdrom'>
|
||||
<source file='/root/boot.iso'/>
|
||||
<target dev='hdc'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
<graphics type='vnc' port='5903'/>
|
||||
</devices>
|
||||
</domain>
|
2
tests/sexpr2xml-pv.sexpr
Normal file
2
tests/sexpr2xml-pv.sexpr
Normal file
@ -0,0 +1,2 @@
|
||||
(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
|
||||
|
21
tests/sexpr2xml-pv.xml
Normal file
21
tests/sexpr2xml-pv.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<domain type='xen' id='6'>
|
||||
<name>pvtest</name>
|
||||
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
|
||||
<os>
|
||||
<type>linux</type>
|
||||
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
|
||||
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
|
||||
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
|
||||
</os>
|
||||
<memory>430080</memory>
|
||||
<vcpu>2</vcpu>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>destroy</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<disk type='file' device='disk'>
|
||||
<source file='/root/some.img'/>
|
||||
<target dev='xvda'/>
|
||||
</disk>
|
||||
</devices>
|
||||
</domain>
|
71
tests/sexpr2xmltest.c
Normal file
71
tests/sexpr2xmltest.c
Normal file
@ -0,0 +1,71 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xml.h"
|
||||
#include "xend_internal.h"
|
||||
#include "testutils.h"
|
||||
#include "internal.h"
|
||||
|
||||
static char *progname;
|
||||
|
||||
#define MAX_FILE 4096
|
||||
|
||||
static int testCompareFiles(const char *xml, const char *sexpr) {
|
||||
char xmlData[MAX_FILE];
|
||||
char sexprData[MAX_FILE];
|
||||
char *gotxml = NULL;
|
||||
char *xmlPtr = &(xmlData[0]);
|
||||
char *sexprPtr = &(sexprData[0]);
|
||||
|
||||
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
|
||||
return -1;
|
||||
|
||||
if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
|
||||
return -1;
|
||||
|
||||
if (!(gotxml = xend_parse_domain_sexp(NULL, sexprData)))
|
||||
return -1;
|
||||
|
||||
if (getenv("DEBUG_TESTS")) {
|
||||
printf("In %d '%s'\n", strlen(xmlData), xmlData);
|
||||
printf("Out %d '%s'\n", strlen(gotxml), gotxml);
|
||||
}
|
||||
if (strcmp(xmlData, gotxml))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int testComparePV(void *data ATTRIBUTE_UNUSED) {
|
||||
return testCompareFiles("sexpr2xml-pv.xml",
|
||||
"sexpr2xml-pv.sexpr");
|
||||
}
|
||||
|
||||
static int testCompareFV(void *data ATTRIBUTE_UNUSED) {
|
||||
return testCompareFiles("sexpr2xml-fv.xml",
|
||||
"sexpr2xml-fv.sexpr");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
if (argc > 1) {
|
||||
fprintf(stderr, "Usage: %s\n", progname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (virtTestRun("SEXPR-2-XML PV config",
|
||||
1, testComparePV, NULL) != 0)
|
||||
ret = -1;
|
||||
|
||||
if (virtTestRun("SEXPR-2-XML FV config",
|
||||
1, testCompareFV, NULL) != 0)
|
||||
ret = -1;
|
||||
|
||||
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
@ -13,6 +13,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "testutils.h"
|
||||
|
||||
@ -72,3 +75,33 @@ virtTestRun(const char *title, int nloops, int (*body)(void *data), void *data)
|
||||
free(ts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int virtTestLoadFile(const char *name,
|
||||
char **buf,
|
||||
int buflen) {
|
||||
FILE *fp = fopen(name, "r");
|
||||
struct stat st;
|
||||
|
||||
if (!fp)
|
||||
return -1;
|
||||
|
||||
if (fstat(fileno(fp), &st) < 0) {
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (st.st_size > (buflen-1)) {
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fread(*buf, st.st_size, 1, fp) != 1) {
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
(*buf)[st.st_size] = '\0';
|
||||
|
||||
fclose(fp);
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,9 @@ int virtTestRun (const char *title,
|
||||
int nloops,
|
||||
int (*body)(void *data),
|
||||
void *data);
|
||||
int virtTestLoadFile(const char *name,
|
||||
char **buf,
|
||||
int buflen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
1
tests/xml2sexpr-fv.sexpr
Normal file
1
tests/xml2sexpr-fv.sexpr
Normal file
@ -0,0 +1 @@
|
||||
(vm (name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)(cdrom '/root/boot.iso')(acpi 1)(vnc 1)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))
|
36
tests/xml2sexpr-fv.xml
Normal file
36
tests/xml2sexpr-fv.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<domain type='xen'>
|
||||
<name>fvtest</name>
|
||||
<uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
|
||||
<os>
|
||||
<type>hvm</type>
|
||||
<loader>/usr/lib/xen/boot/hvmloader</loader>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<memory>409600</memory>
|
||||
<vcpu>1</vcpu>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<features>
|
||||
<acpi/>
|
||||
</features>
|
||||
<devices>
|
||||
<emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
|
||||
<interface type='bridge'>
|
||||
<source bridge='xenbr0'/>
|
||||
<mac address='00:16:3e:1b:b1:47'/>
|
||||
<script path='vif-bridge'/>
|
||||
</interface>
|
||||
<disk type='file' device='cdrom'>
|
||||
<source file='/root/boot.iso'/>
|
||||
<target dev='hdc'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
<disk type='file'>
|
||||
<source file='/root/foo.img'/>
|
||||
<target dev='ioemu:hda'/>
|
||||
</disk>
|
||||
<graphics type='vnc' port='5917'/>
|
||||
</devices>
|
||||
</domain>
|
||||
|
1
tests/xml2sexpr-pv.sexpr
Normal file
1
tests/xml2sexpr-pv.sexpr
Normal file
@ -0,0 +1 @@
|
||||
(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
|
23
tests/xml2sexpr-pv.xml
Normal file
23
tests/xml2sexpr-pv.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<domain type='xen' id='15'>
|
||||
<name>pvtest</name>
|
||||
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
|
||||
<os>
|
||||
<type>linux</type>
|
||||
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
|
||||
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
|
||||
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
|
||||
</os>
|
||||
<memory>430080</memory>
|
||||
<vcpu>2</vcpu>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>destroy</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<disk type='file' device='disk'>
|
||||
<source file='/root/some.img'/>
|
||||
<target dev='xvda'/>
|
||||
</disk>
|
||||
<console tty='/dev/pts/4'/>
|
||||
</devices>
|
||||
</domain>
|
||||
|
76
tests/xml2sexprtest.c
Normal file
76
tests/xml2sexprtest.c
Normal file
@ -0,0 +1,76 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xml.h"
|
||||
#include "testutils.h"
|
||||
#include "internal.h"
|
||||
|
||||
static char *progname;
|
||||
|
||||
#define MAX_FILE 4096
|
||||
|
||||
static int testCompareFiles(const char *xml, const char *sexpr, const char *name) {
|
||||
char xmlData[MAX_FILE];
|
||||
char sexprData[MAX_FILE];
|
||||
char *gotname = NULL;
|
||||
char *gotsexpr = NULL;
|
||||
char *xmlPtr = &(xmlData[0]);
|
||||
char *sexprPtr = &(sexprData[0]);
|
||||
|
||||
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
|
||||
return -1;
|
||||
|
||||
if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
|
||||
return -1;
|
||||
|
||||
if (!(gotsexpr = virDomainParseXMLDesc(xmlData, &gotname)))
|
||||
return -1;
|
||||
|
||||
if (getenv("DEBUG_TESTS")) {
|
||||
printf("In %d '%s'\n", strlen(sexprData), sexprData);
|
||||
printf("Out %d '%s'\n", strlen(gotsexpr), gotsexpr);
|
||||
}
|
||||
if (strcmp(sexprData, gotsexpr))
|
||||
return -1;
|
||||
|
||||
if (strcmp(name, gotname))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int testComparePV(void *data ATTRIBUTE_UNUSED) {
|
||||
return testCompareFiles("xml2sexpr-pv.xml",
|
||||
"xml2sexpr-pv.sexpr",
|
||||
"pvtest");
|
||||
}
|
||||
|
||||
static int testCompareFV(void *data ATTRIBUTE_UNUSED) {
|
||||
return testCompareFiles("xml2sexpr-fv.xml",
|
||||
"xml2sexpr-fv.sexpr",
|
||||
"fvtest");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
if (argc > 1) {
|
||||
fprintf(stderr, "Usage: %s\n", progname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (virtTestRun("XML-2-SEXPR PV config",
|
||||
1, testComparePV, NULL) != 0)
|
||||
ret = -1;
|
||||
|
||||
if (virtTestRun("XML-2-SEXPR FV config",
|
||||
1, testCompareFV, NULL) != 0)
|
||||
ret = -1;
|
||||
|
||||
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user