mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 10:52:22 +00:00
Added test suite for the XML <-> XM config file conversion
This commit is contained in:
parent
1b0f541704
commit
bc073b5a4d
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
Fri Jan 19 15:28:13 EST 2007 Daniel Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* tests/xmconfigtest.c: Test suite to check conversion from
|
||||||
|
XML to XM config files, and the reverse
|
||||||
|
* tests/xmconfigdata/*.xml: Source XML files for the test
|
||||||
|
suite
|
||||||
|
* tests/xmconfigdata/*.cfg: Source XM config files for the
|
||||||
|
test suite
|
||||||
|
* configure.ac, tests/Makefile.am: Added xmconfigdata subdir
|
||||||
|
* tests/xmconfigdata/Makefile.am: Include config files when
|
||||||
|
doing a make dist.
|
||||||
|
|
||||||
Fri Jan 19 15:23:13 EST 2007 Daniel Berrange <berrange@redhat.com>
|
Fri Jan 19 15:23:13 EST 2007 Daniel Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* src/xm_internal.c: Finished off the conversion from XML
|
* src/xm_internal.c: Finished off the conversion from XML
|
||||||
|
@ -269,4 +269,5 @@ AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
|
|||||||
tests/Makefile proxy/Makefile \
|
tests/Makefile proxy/Makefile \
|
||||||
tests/xml2sexprdata/Makefile \
|
tests/xml2sexprdata/Makefile \
|
||||||
tests/sexpr2xmldata/Makefile \
|
tests/sexpr2xmldata/Makefile \
|
||||||
|
tests/xmconfigdata/Makefile \
|
||||||
tests/virshdata/Makefile tests/confdata/Makefile)
|
tests/virshdata/Makefile tests/confdata/Makefile)
|
||||||
|
@ -8,3 +8,4 @@ xml2sexprtest
|
|||||||
virshtest
|
virshtest
|
||||||
conftest
|
conftest
|
||||||
reconnect
|
reconnect
|
||||||
|
xmconfigtest
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
## Process this file with automake to produce Makefile.in
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata
|
SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata xmconfigdata
|
||||||
|
|
||||||
LIBVIRT = $(top_builddir)/src/.libs/libvirt.a
|
LIBVIRT = $(top_builddir)/src/.libs/libvirt.a
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ LDADDS = \
|
|||||||
EXTRA_DIST = xmlrpcserver.py test_conf.sh
|
EXTRA_DIST = xmlrpcserver.py test_conf.sh
|
||||||
|
|
||||||
noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \
|
noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \
|
||||||
reconnect
|
reconnect xmconfigtest
|
||||||
|
|
||||||
TESTS = xml2sexprtest sexpr2xmltest virshtest test_conf.sh reconnect
|
TESTS = xml2sexprtest sexpr2xmltest virshtest test_conf.sh reconnect xmconfigtest
|
||||||
|
|
||||||
valgrind:
|
valgrind:
|
||||||
$(MAKE) check TESTS_ENVIRONMENT="valgrind --quiet --leak-check=full"
|
$(MAKE) check TESTS_ENVIRONMENT="valgrind --quiet --leak-check=full"
|
||||||
@ -49,6 +49,12 @@ sexpr2xmltest_SOURCES = \
|
|||||||
sexpr2xmltest_LDFLAGS =
|
sexpr2xmltest_LDFLAGS =
|
||||||
sexpr2xmltest_LDADD = $(LDADDS)
|
sexpr2xmltest_LDADD = $(LDADDS)
|
||||||
|
|
||||||
|
xmconfigtest_SOURCES = \
|
||||||
|
xmconfigtest.c \
|
||||||
|
testutils.c testutils.h
|
||||||
|
xmconfigtest_LDFLAGS =
|
||||||
|
xmconfigtest_LDADD = $(LDADDS)
|
||||||
|
|
||||||
virshtest_SOURCES = \
|
virshtest_SOURCES = \
|
||||||
virshtest.c \
|
virshtest.c \
|
||||||
testutils.c testutils.h
|
testutils.c testutils.h
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* utils.c: basic test utils
|
* testutils.c: basic test utils
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 Red Hat, Inc.
|
* Copyright (C) 2005-2007 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* See COPYING.LIB for the License of this software
|
* See COPYING.LIB for the License of this software
|
||||||
*
|
*
|
||||||
@ -23,68 +23,68 @@
|
|||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
|
|
||||||
#define GETTIMEOFDAY(T) gettimeofday(T, NULL)
|
#define GETTIMEOFDAY(T) gettimeofday(T, NULL)
|
||||||
#define DIFF_MSEC(T, U) \
|
#define DIFF_MSEC(T, U) \
|
||||||
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
|
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
|
||||||
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
|
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
|
||||||
|
|
||||||
double
|
double
|
||||||
virtTestCountAverage(double *items, int nitems)
|
virtTestCountAverage(double *items, int nitems)
|
||||||
{
|
{
|
||||||
long double sum = 0;
|
long double sum = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=1; i < nitems; i++)
|
for (i=1; i < nitems; i++)
|
||||||
sum += items[i];
|
sum += items[i];
|
||||||
|
|
||||||
return (double) (sum / nitems);
|
return (double) (sum / nitems);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs test and count average time (if the nloops is grater than 1)
|
* Runs test and count average time (if the nloops is grater than 1)
|
||||||
*
|
*
|
||||||
* returns: -1 = error, 0 = success
|
* returns: -1 = error, 0 = success
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virtTestRun(const char *title, int nloops, int (*body)(void *data), void *data)
|
virtTestRun(const char *title, int nloops, int (*body)(void *data), void *data)
|
||||||
{
|
{
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
double *ts = NULL;
|
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)
|
if (nloops > 1 && (ts = calloc(nloops,
|
||||||
GETTIMEOFDAY(&before);
|
sizeof(double)))==NULL)
|
||||||
if ((ret = body(data)) != 0)
|
return -1;
|
||||||
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)
|
for (i=0; i < nloops; i++) {
|
||||||
free(ts);
|
struct timeval before, after;
|
||||||
return ret;
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
int virtTestLoadFile(const char *name,
|
int virtTestLoadFile(const char *name,
|
||||||
char **buf,
|
char **buf,
|
||||||
int buflen) {
|
int buflen) {
|
||||||
FILE *fp = fopen(name, "r");
|
FILE *fp = fopen(name, "r");
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -98,9 +98,11 @@ int virtTestLoadFile(const char *name,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fread(*buf, st.st_size, 1, fp) != 1) {
|
if (st.st_size) {
|
||||||
fclose(fp);
|
if (fread(*buf, st.st_size, 1, fp) != 1) {
|
||||||
return -1;
|
fclose(fp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(*buf)[st.st_size] = '\0';
|
(*buf)[st.st_size] = '\0';
|
||||||
|
|
||||||
@ -110,89 +112,99 @@ int virtTestLoadFile(const char *name,
|
|||||||
|
|
||||||
static
|
static
|
||||||
void virtTestCaptureProgramExecChild(const char *const argv[],
|
void virtTestCaptureProgramExecChild(const char *const argv[],
|
||||||
int pipefd) {
|
int pipefd) {
|
||||||
int i;
|
int i;
|
||||||
int open_max;
|
int open_max;
|
||||||
int stdinfd = -1;
|
int stdinfd = -1;
|
||||||
int stderrfd = -1;
|
int stderrfd = -1;
|
||||||
const char *const env[] = {
|
const char *const env[] = {
|
||||||
"LANG=C",
|
"LANG=C",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((stdinfd = open(_PATH_DEVNULL, O_RDONLY)) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
if ((stderrfd = open(_PATH_DEVNULL, O_WRONLY)) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
open_max = sysconf (_SC_OPEN_MAX);
|
if ((stdinfd = open(_PATH_DEVNULL, O_RDONLY)) < 0)
|
||||||
for (i = 0; i < open_max; i++) {
|
goto cleanup;
|
||||||
if (i != stdinfd &&
|
if ((stderrfd = open(_PATH_DEVNULL, O_WRONLY)) < 0)
|
||||||
i != stderrfd &&
|
goto cleanup;
|
||||||
i != pipefd)
|
|
||||||
close(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
|
open_max = sysconf (_SC_OPEN_MAX);
|
||||||
goto cleanup;
|
for (i = 0; i < open_max; i++) {
|
||||||
if (dup2(pipefd, STDOUT_FILENO) != STDOUT_FILENO)
|
if (i != stdinfd &&
|
||||||
goto cleanup;
|
i != stderrfd &&
|
||||||
if (dup2(stderrfd, STDERR_FILENO) != STDERR_FILENO)
|
i != pipefd)
|
||||||
goto cleanup;
|
close(i);
|
||||||
|
}
|
||||||
/* SUS is crazy here, hence the cast */
|
|
||||||
execve(argv[0], (char *const*)argv, (char *const*)env);
|
if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
|
||||||
|
goto cleanup;
|
||||||
|
if (dup2(pipefd, STDOUT_FILENO) != STDOUT_FILENO)
|
||||||
|
goto cleanup;
|
||||||
|
if (dup2(stderrfd, STDERR_FILENO) != STDERR_FILENO)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
/* SUS is crazy here, hence the cast */
|
||||||
|
execve(argv[0], (char *const*)argv, (char *const*)env);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (stdinfd != -1)
|
if (stdinfd != -1)
|
||||||
close(stdinfd);
|
close(stdinfd);
|
||||||
if (stderrfd != -1)
|
if (stderrfd != -1)
|
||||||
close(stderrfd);
|
close(stderrfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int virtTestCaptureProgramOutput(const char *const argv[],
|
int virtTestCaptureProgramOutput(const char *const argv[],
|
||||||
char **buf,
|
char **buf,
|
||||||
int buflen) {
|
int buflen) {
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
|
|
||||||
if (pipe(pipefd) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
int pid = fork();
|
if (pipe(pipefd) < 0)
|
||||||
switch (pid) {
|
return -1;
|
||||||
|
|
||||||
|
int pid = fork();
|
||||||
|
switch (pid) {
|
||||||
case 0:
|
case 0:
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
virtTestCaptureProgramExecChild(argv, pipefd[1]);
|
virtTestCaptureProgramExecChild(argv, pipefd[1]);
|
||||||
|
|
||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
|
|
||||||
case -1:
|
case -1:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
int got = 0;
|
int got = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int want = buflen-1;
|
int want = buflen-1;
|
||||||
|
|
||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
|
|
||||||
while (want) {
|
while (want) {
|
||||||
if ((ret = read(pipefd[0], (*buf)+got, want)) <= 0)
|
if ((ret = read(pipefd[0], (*buf)+got, want)) <= 0)
|
||||||
break;
|
break;
|
||||||
got += ret;
|
got += ret;
|
||||||
want -= ret;
|
want -= ret;
|
||||||
}
|
}
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
(*buf)[got] = '\0';
|
(*buf)[got] = '\0';
|
||||||
|
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* c-indent-level: 4
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* tab-width: 4
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
|
2
tests/xmconfigdata/.cvsignore
Normal file
2
tests/xmconfigdata/.cvsignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Makefile
|
||||||
|
Makefile.in
|
2
tests/xmconfigdata/Makefile.am
Normal file
2
tests/xmconfigdata/Makefile.am
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
EXTRA_DIST = $(wildcard *.xml) $(wildcard *.cfg)
|
22
tests/xmconfigdata/test-fullvirt-new-cdrom.cfg
Executable file
22
tests/xmconfigdata/test-fullvirt-new-cdrom.cfg
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
name = "XenGuest2"
|
||||||
|
uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
|
||||||
|
maxmem = 579
|
||||||
|
memory = 394
|
||||||
|
vcpus = 1
|
||||||
|
builder = "hvm"
|
||||||
|
kernel = "/usr/lib/xen/boot/hvmloader"
|
||||||
|
boot = "d"
|
||||||
|
pae = 1
|
||||||
|
acpi = 1
|
||||||
|
apic = 1
|
||||||
|
on_poweroff = "destroy"
|
||||||
|
on_reboot = "restart"
|
||||||
|
on_crash = "restart"
|
||||||
|
device_model = "/usr/lib/xen/bin/qemu-dm"
|
||||||
|
sdl = 0
|
||||||
|
vnc = 1
|
||||||
|
vncunused = 1
|
||||||
|
vnclisten = "127.0.0.1"
|
||||||
|
vncpasswd = "123poi"
|
||||||
|
disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ]
|
||||||
|
vif = [ "mac=00:16:3E:66:92:9C,type=ioemu" ]
|
38
tests/xmconfigdata/test-fullvirt-new-cdrom.xml
Normal file
38
tests/xmconfigdata/test-fullvirt-new-cdrom.xml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<domain type='xen'>
|
||||||
|
<name>XenGuest2</name>
|
||||||
|
<uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
|
||||||
|
<os>
|
||||||
|
<type>hvm</type>
|
||||||
|
<loader>/usr/lib/xen/boot/hvmloader</loader>
|
||||||
|
<boot>cdrom</boot>
|
||||||
|
</os>
|
||||||
|
<currentMemory>403456</currentMemory>
|
||||||
|
<memory>592896</memory>
|
||||||
|
<vcpu>1</vcpu>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>restart</on_crash>
|
||||||
|
<features>
|
||||||
|
<pae/>
|
||||||
|
<acpi/>
|
||||||
|
<apic/>
|
||||||
|
</features>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
|
||||||
|
<disk type='block' device='disk'>
|
||||||
|
<driver name='phy'/>
|
||||||
|
<source dev='/dev/HostVG/XenGuest2'/>
|
||||||
|
<target dev='hda'/>
|
||||||
|
</disk>
|
||||||
|
<disk type='file' device='cdrom'>
|
||||||
|
<driver name='file'/>
|
||||||
|
<source file='/root/boot.iso'/>
|
||||||
|
<target dev='hdc'/>
|
||||||
|
<readonly/>
|
||||||
|
</disk>
|
||||||
|
<interface type='bridge'>
|
||||||
|
<mac address='00:16:3E:66:92:9C'/>
|
||||||
|
</interface>
|
||||||
|
<graphics type='vnc' port='-1' listen='127.0.0.1' passwd='123poi'/>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
23
tests/xmconfigdata/test-fullvirt-old-cdrom.cfg
Executable file
23
tests/xmconfigdata/test-fullvirt-old-cdrom.cfg
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
name = "XenGuest2"
|
||||||
|
uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
|
||||||
|
maxmem = 579
|
||||||
|
memory = 394
|
||||||
|
vcpus = 1
|
||||||
|
builder = "hvm"
|
||||||
|
kernel = "/usr/lib/xen/boot/hvmloader"
|
||||||
|
boot = "d"
|
||||||
|
pae = 1
|
||||||
|
acpi = 1
|
||||||
|
apic = 1
|
||||||
|
cdrom = "/root/boot.iso"
|
||||||
|
on_poweroff = "destroy"
|
||||||
|
on_reboot = "restart"
|
||||||
|
on_crash = "restart"
|
||||||
|
device_model = "/usr/lib/xen/bin/qemu-dm"
|
||||||
|
sdl = 0
|
||||||
|
vnc = 1
|
||||||
|
vncunused = 1
|
||||||
|
vnclisten = "127.0.0.1"
|
||||||
|
vncpasswd = "123poi"
|
||||||
|
disk = [ "phy:/dev/HostVG/XenGuest2,ioemu:hda,w" ]
|
||||||
|
vif = [ "mac=00:16:3E:66:92:9C,type=ioemu" ]
|
38
tests/xmconfigdata/test-fullvirt-old-cdrom.xml
Normal file
38
tests/xmconfigdata/test-fullvirt-old-cdrom.xml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<domain type='xen'>
|
||||||
|
<name>XenGuest2</name>
|
||||||
|
<uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
|
||||||
|
<os>
|
||||||
|
<type>hvm</type>
|
||||||
|
<loader>/usr/lib/xen/boot/hvmloader</loader>
|
||||||
|
<boot>cdrom</boot>
|
||||||
|
</os>
|
||||||
|
<currentMemory>403456</currentMemory>
|
||||||
|
<memory>592896</memory>
|
||||||
|
<vcpu>1</vcpu>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>restart</on_crash>
|
||||||
|
<features>
|
||||||
|
<pae/>
|
||||||
|
<acpi/>
|
||||||
|
<apic/>
|
||||||
|
</features>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
|
||||||
|
<disk type='block' device='disk'>
|
||||||
|
<driver name='phy'/>
|
||||||
|
<source dev='/dev/HostVG/XenGuest2'/>
|
||||||
|
<target dev='hda'/>
|
||||||
|
</disk>
|
||||||
|
<disk type='file' device='cdrom'>
|
||||||
|
<driver name='file'/>
|
||||||
|
<source file='/root/boot.iso'/>
|
||||||
|
<target dev='hdc'/>
|
||||||
|
<readonly/>
|
||||||
|
</disk>
|
||||||
|
<interface type='bridge'>
|
||||||
|
<mac address='00:16:3E:66:92:9C'/>
|
||||||
|
</interface>
|
||||||
|
<graphics type='vnc' port='-1' listen='127.0.0.1' passwd='123poi'/>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
12
tests/xmconfigdata/test-paravirt-new-pvfb.cfg
Executable file
12
tests/xmconfigdata/test-paravirt-new-pvfb.cfg
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
name = "XenGuest1"
|
||||||
|
uuid = "c7a5fdb0cdaf9455926ad65c16db1809"
|
||||||
|
maxmem = 579
|
||||||
|
memory = 394
|
||||||
|
vcpus = 1
|
||||||
|
bootloader = "/usr/bin/pygrub"
|
||||||
|
on_poweroff = "destroy"
|
||||||
|
on_reboot = "restart"
|
||||||
|
on_crash = "restart"
|
||||||
|
vfb = [ "type=vnc,vncunused=1,vnclisten=127.0.0.1,vncpasswd=123poi" ]
|
||||||
|
disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ]
|
||||||
|
vif = [ "mac=00:16:3E:66:94:9C,ip=192.168.0.9" ]
|
24
tests/xmconfigdata/test-paravirt-new-pvfb.xml
Normal file
24
tests/xmconfigdata/test-paravirt-new-pvfb.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<domain type='xen'>
|
||||||
|
<name>XenGuest1</name>
|
||||||
|
<uuid>c7a5fdb0cdaf9455926ad65c16db1809</uuid>
|
||||||
|
<bootloader>/usr/bin/pygrub</bootloader>
|
||||||
|
<currentMemory>403456</currentMemory>
|
||||||
|
<memory>592896</memory>
|
||||||
|
<vcpu>1</vcpu>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>restart</on_crash>
|
||||||
|
<devices>
|
||||||
|
<disk type='block' device='disk'>
|
||||||
|
<driver name='phy'/>
|
||||||
|
<source dev='/dev/HostVG/XenGuest1'/>
|
||||||
|
<target dev='xvda'/>
|
||||||
|
</disk>
|
||||||
|
<interface type='bridge'>
|
||||||
|
<mac address='00:16:3E:66:94:9C'/>
|
||||||
|
<ip address='192.168.0.9'/>
|
||||||
|
</interface>
|
||||||
|
<graphics type='vnc' port='-1' listen='127.0.0.1' passwd='123poi'/>
|
||||||
|
<console/>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
16
tests/xmconfigdata/test-paravirt-old-pvfb.cfg
Executable file
16
tests/xmconfigdata/test-paravirt-old-pvfb.cfg
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
name = "XenGuest1"
|
||||||
|
uuid = "c7a5fdb0cdaf9455926ad65c16db1809"
|
||||||
|
maxmem = 579
|
||||||
|
memory = 394
|
||||||
|
vcpus = 1
|
||||||
|
bootloader = "/usr/bin/pygrub"
|
||||||
|
on_poweroff = "destroy"
|
||||||
|
on_reboot = "restart"
|
||||||
|
on_crash = "restart"
|
||||||
|
sdl = 0
|
||||||
|
vnc = 1
|
||||||
|
vncunused = 1
|
||||||
|
vnclisten = "127.0.0.1"
|
||||||
|
vncpasswd = "123poi"
|
||||||
|
disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ]
|
||||||
|
vif = [ "mac=00:16:3E:66:94:9C,ip=192.168.0.9" ]
|
24
tests/xmconfigdata/test-paravirt-old-pvfb.xml
Normal file
24
tests/xmconfigdata/test-paravirt-old-pvfb.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<domain type='xen'>
|
||||||
|
<name>XenGuest1</name>
|
||||||
|
<uuid>c7a5fdb0cdaf9455926ad65c16db1809</uuid>
|
||||||
|
<bootloader>/usr/bin/pygrub</bootloader>
|
||||||
|
<currentMemory>403456</currentMemory>
|
||||||
|
<memory>592896</memory>
|
||||||
|
<vcpu>1</vcpu>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>restart</on_crash>
|
||||||
|
<devices>
|
||||||
|
<disk type='block' device='disk'>
|
||||||
|
<driver name='phy'/>
|
||||||
|
<source dev='/dev/HostVG/XenGuest1'/>
|
||||||
|
<target dev='xvda'/>
|
||||||
|
</disk>
|
||||||
|
<interface type='bridge'>
|
||||||
|
<mac address='00:16:3E:66:94:9C'/>
|
||||||
|
<ip address='192.168.0.9'/>
|
||||||
|
</interface>
|
||||||
|
<graphics type='vnc' port='-1' listen='127.0.0.1' passwd='123poi'/>
|
||||||
|
<console/>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
226
tests/xmconfigtest.c
Normal file
226
tests/xmconfigtest.c
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
/*
|
||||||
|
* xmconfigtest.c: Test backend for xm_internal config file handling
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Red Hat
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "xm_internal.h"
|
||||||
|
#include "testutils.h"
|
||||||
|
#include "internal.h"
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
|
static char *progname;
|
||||||
|
|
||||||
|
#define MAX_FILE 4096
|
||||||
|
|
||||||
|
static int testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion) {
|
||||||
|
char xmlData[MAX_FILE];
|
||||||
|
char xmcfgData[MAX_FILE];
|
||||||
|
char gotxmcfgData[MAX_FILE];
|
||||||
|
char *xmlPtr = &(xmlData[0]);
|
||||||
|
char *xmcfgPtr = &(xmcfgData[0]);
|
||||||
|
char *gotxmcfgPtr = &(gotxmcfgData[0]);
|
||||||
|
virConfPtr conf = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
virConnectPtr conn;
|
||||||
|
int wrote = MAX_FILE;
|
||||||
|
|
||||||
|
conn = virConnectOpen("test:///default");
|
||||||
|
|
||||||
|
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
/* Yes, a nasty hack, but this is only a test suite */
|
||||||
|
conn->xendConfigVersion = xendConfigVersion;
|
||||||
|
|
||||||
|
if (!(conf = xenXMParseXMLToConfig(conn, xmlPtr)))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (virConfWriteMem(gotxmcfgPtr, &wrote, conf) < 0)
|
||||||
|
goto fail;
|
||||||
|
gotxmcfgPtr[wrote] = '\0';
|
||||||
|
|
||||||
|
if (getenv("DEBUG_TESTS")) {
|
||||||
|
printf("Expect %d '%s'\n", (int)strlen(xmcfgData), xmcfgData);
|
||||||
|
printf("Actual %d '%s'\n", (int)strlen(gotxmcfgData), gotxmcfgData);
|
||||||
|
}
|
||||||
|
if (strcmp(xmcfgData, gotxmcfgData))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
if (conf)
|
||||||
|
virConfFree(conf);
|
||||||
|
|
||||||
|
virConnectClose(conn);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion) {
|
||||||
|
char xmlData[MAX_FILE];
|
||||||
|
char xmcfgData[MAX_FILE];
|
||||||
|
char *xmlPtr = &(xmlData[0]);
|
||||||
|
char *xmcfgPtr = &(xmcfgData[0]);
|
||||||
|
char *gotxml = NULL;
|
||||||
|
virConfPtr conf = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
virConnectPtr conn;
|
||||||
|
|
||||||
|
conn = virConnectOpen("test:///default");
|
||||||
|
|
||||||
|
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
/* Yes, a nasty hack, but this is only a test suite */
|
||||||
|
conn->xendConfigVersion = xendConfigVersion;
|
||||||
|
|
||||||
|
if (!(conf = virConfReadMem(xmcfgPtr, strlen(xmcfgPtr))))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (!(gotxml = xenXMDomainFormatXML(conn, conf)))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (getenv("DEBUG_TESTS")) {
|
||||||
|
printf("Expect %d '%s'\n", (int)strlen(xmlData), xmlData);
|
||||||
|
printf("Actual %d '%s'\n", (int)strlen(gotxml), gotxml);
|
||||||
|
}
|
||||||
|
if (strcmp(xmlData, gotxml))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
if (conf)
|
||||||
|
virConfFree(conf);
|
||||||
|
if (gotxml)
|
||||||
|
free(gotxml);
|
||||||
|
|
||||||
|
virConnectClose(conn);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int testCompareParavirtOldPVFBFormat(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareFormatXML("xmconfigdata/test-paravirt-old-pvfb.cfg",
|
||||||
|
"xmconfigdata/test-paravirt-old-pvfb.xml",
|
||||||
|
2);
|
||||||
|
}
|
||||||
|
static int testCompareParavirtOldPVFBParse(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareParseXML("xmconfigdata/test-paravirt-old-pvfb.cfg",
|
||||||
|
"xmconfigdata/test-paravirt-old-pvfb.xml",
|
||||||
|
2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int testCompareParavirtNewPVFBFormat(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareFormatXML("xmconfigdata/test-paravirt-new-pvfb.cfg",
|
||||||
|
"xmconfigdata/test-paravirt-new-pvfb.xml",
|
||||||
|
3);
|
||||||
|
}
|
||||||
|
static int testCompareParavirtNewPVFBParse(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareParseXML("xmconfigdata/test-paravirt-new-pvfb.cfg",
|
||||||
|
"xmconfigdata/test-paravirt-new-pvfb.xml",
|
||||||
|
3);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int testCompareFullvirtOldCDROMFormat(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareFormatXML("xmconfigdata/test-fullvirt-old-cdrom.cfg",
|
||||||
|
"xmconfigdata/test-fullvirt-old-cdrom.xml",
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
static int testCompareFullvirtOldCDROMParse(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareParseXML("xmconfigdata/test-fullvirt-old-cdrom.cfg",
|
||||||
|
"xmconfigdata/test-fullvirt-old-cdrom.xml",
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int testCompareFullvirtNewCDROMFormat(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareFormatXML("xmconfigdata/test-fullvirt-new-cdrom.cfg",
|
||||||
|
"xmconfigdata/test-fullvirt-new-cdrom.xml",
|
||||||
|
2);
|
||||||
|
}
|
||||||
|
static int testCompareFullvirtNewCDROMParse(void *data ATTRIBUTE_UNUSED) {
|
||||||
|
return testCompareParseXML("xmconfigdata/test-fullvirt-new-cdrom.cfg",
|
||||||
|
"xmconfigdata/test-fullvirt-new-cdrom.xml",
|
||||||
|
2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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("Paravirt old PVFB (Format)",
|
||||||
|
1, testCompareParavirtOldPVFBFormat, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
if (virtTestRun("Paravirt new PVFB (Format)",
|
||||||
|
1, testCompareParavirtNewPVFBFormat, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
if (virtTestRun("Fullvirt old PVFB (Format)",
|
||||||
|
1, testCompareFullvirtOldCDROMFormat, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
if (virtTestRun("Fullvirt new PVFB (Format)",
|
||||||
|
1, testCompareFullvirtNewCDROMFormat, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
if (virtTestRun("Paravirt old PVFB (Parse)",
|
||||||
|
1, testCompareParavirtOldPVFBParse, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
if (virtTestRun("Paravirt new PVFB (Parse)",
|
||||||
|
1, testCompareParavirtNewPVFBParse, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
if (virtTestRun("Fullvirt old PVFB (Parse)",
|
||||||
|
1, testCompareFullvirtOldCDROMParse, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
if (virtTestRun("Fullvirt new PVFB (Parse)",
|
||||||
|
1, testCompareFullvirtNewCDROMParse, NULL) != 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local variables:
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* c-indent-level: 4
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* tab-width: 4
|
||||||
|
* End:
|
||||||
|
*/
|
Loading…
x
Reference in New Issue
Block a user