提交 94353ef6 编写于 作者: D Daniel P. Berrange

Re-factor and pretty print differences

上级 48455914
Fri Apr 18 11:26:24 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* tests/Makefile.am: Add abs_srcdir and abs_builddir to test
environment
* tests/test_conf.sh: Refactor to pretty print
* tests/statstest.c, tests/xencapstest.c, tests/xmconfigtest.c:
Use new virtTestDifference for display. Autoset abs_srcdir if
not in environment. Refactor common code into macros
Fri Apr 18 11:04:24 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* tests/testutils.h, tests/testutils.c: Add virtTestDifference
......
......@@ -66,6 +66,8 @@ path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/qemud
TESTS_ENVIRONMENT = \
abs_top_builddir=`cd '$(top_builddir)'; pwd` \
abs_top_srcdir=`cd '$(top_srcdir)'; pwd` \
abs_builddir=`cd '$(builddir)'; pwd` \
abs_srcdir=`cd '$(srcdir)'; pwd` \
PATH="$(path_add)$(PATH_SEPARATOR)$$PATH" \
SHELL="$(SHELL)" \
$(VG)
......
......@@ -7,6 +7,8 @@
#include "stats_linux.h"
#include "internal.h"
#include "testutils.h"
#if WITH_XEN
static void testQuietError(void *userData ATTRIBUTE_UNUSED,
virErrorPtr error ATTRIBUTE_UNUSED)
......@@ -21,13 +23,26 @@ static int testDevice(const char *path, int expect)
int actual = xenLinuxDomainDeviceID(NULL, 1, path);
if (actual == expect) {
fprintf(stderr, "%-14s == %-6d OK\n", path, expect);
return 0;
} else {
fprintf(stderr, "%-14s == %-6d (%-6d) FAILED\n", path, expect, actual);
if (getenv("DEBUG_TESTS"))
fprintf(stderr, "Expect %-6d Actual %-6d\n", expect, actual);
return -1;
}
}
struct testInfo
{
const char *dev;
int num;
};
static int testDeviceHelper(const void *data)
{
const struct testInfo *info = data;
return testDevice(info->dev, info->num);
}
#endif
int
......@@ -42,85 +57,67 @@ main(void)
if (!getenv("DEBUG_TESTS"))
virSetErrorFunc(NULL, testQuietError);
#define DO_TEST(dev, num) \
do { \
struct testInfo info = { dev, num }; \
if (virtTestRun("Device " dev " -> " # num, \
1, testDeviceHelper, &info) < 0) \
ret = -1; \
} while (0)
/********************************
* Xen paravirt disks
********************************/
/* first valid disk */
if (testDevice("xvda", 51712) < 0)
ret = -1;
if (testDevice("xvda1", 51713) < 0)
ret = -1;
if (testDevice("xvda15", 51727) < 0)
ret = -1;
DO_TEST("xvda", 51712);
DO_TEST("xvda1", 51713);
DO_TEST("xvda15", 51727);
/* Last valid disk */
if (testDevice("xvdp", 51952) < 0)
ret = -1;
if (testDevice("xvdp1", 51953) < 0)
ret = -1;
if (testDevice("xvdp15", 51967) < 0)
ret = -1;
DO_TEST("xvdp", 51952);
DO_TEST("xvdp1", 51953);
DO_TEST("xvdp15", 51967);
/* Disk letter to large */
if (testDevice("xvdq", -1) < 0)
ret = -1;
DO_TEST("xvdq", -1);
/* missing disk letter */
if (testDevice("xvd1", -1) < 0)
ret = -1;
DO_TEST("xvd1", -1);
/* partition to large */
if (testDevice("xvda16", -1) < 0)
ret = -1;
DO_TEST("xvda16", -1);
/* partition to small */
if (testDevice("xvda0", -1) < 0)
ret = -1;
DO_TEST("xvda0", -1);
/* leading zeros */
if (testDevice("xvda01", -1) < 0)
ret = -1;
DO_TEST("xvda01", -1);
/* leading + */
if (testDevice("xvda+1", -1) < 0)
ret = -1;
DO_TEST("xvda+1", -1);
/* leading - */
if (testDevice("xvda-1", -1) < 0)
ret = -1;
DO_TEST("xvda-1", -1);
/********************************
* IDE disks
********************************/
/* odd numbered disk */
if (testDevice("hda", 768) < 0)
ret = -1;
if (testDevice("hda1", 769) < 0)
ret = -1;
if (testDevice("hda63", 831) < 0)
ret = -1;
DO_TEST("hda", 768);
DO_TEST("hda1", 769);
DO_TEST("hda63", 831);
/* even number disk */
if (testDevice("hdd", 5695) < 0)
ret = -1;
if (testDevice("hdd1", 5696) < 0)
ret = -1;
if (testDevice("hdd63", 5758) < 0)
ret = -1;
DO_TEST("hdd", 5695);
DO_TEST("hdd1", 5696);
DO_TEST("hdd63", 5758);
/* last valid disk */
if (testDevice("hdt", 23359) < 0)
ret = -1;
if (testDevice("hdt1", 23360) < 0)
ret = -1;
if (testDevice("hdt63", 23422) < 0)
ret = -1;
DO_TEST("hdt", 23359);
DO_TEST("hdt1", 23360);
DO_TEST("hdt63", 23422);
/* Disk letter to large */
if (testDevice("hdu", -1) < 0)
ret = -1;
DO_TEST("hdu", -1);
/* missing disk letter */
if (testDevice("hd1", -1) < 0)
ret = -1;
DO_TEST("hd1", -1);
/* partition to large */
if (testDevice("hda64", -1) < 0)
ret = -1;
DO_TEST("hda64", -1);
/* partition to small */
if (testDevice("hda0", -1) < 0)
ret = -1;
DO_TEST("hda0", -1);
......@@ -129,89 +126,55 @@ main(void)
********************************/
/* first valid disk */
if (testDevice("sda", 2048) < 0)
ret = -1;
if (testDevice("sda1", 2049) < 0)
ret = -1;
if (testDevice("sda15", 2063) < 0)
ret = -1;
DO_TEST("sda", 2048);
DO_TEST("sda1", 2049);
DO_TEST("sda15", 2063);
/* last valid disk of first SCSI major number */
if (testDevice("sdp", 2288) < 0)
ret = -1;
if (testDevice("sdp1", 2289) < 0)
ret = -1;
if (testDevice("sdp15", 2303) < 0)
ret = -1;
DO_TEST("sdp", 2288);
DO_TEST("sdp1", 2289);
DO_TEST("sdp15", 2303);
/* first valid disk of second SCSI major number */
if (testDevice("sdq", 16640) < 0)
ret = -1;
if (testDevice("sdq1", 16641) < 0)
ret = -1;
if (testDevice("sdq15", 16655) < 0)
ret = -1;
DO_TEST("sdq", 16640);
DO_TEST("sdq1", 16641);
DO_TEST("sdq15", 16655);
/* last valid single letter disk */
if (testDevice("sdz", 16784) < 0)
ret = -1;
if (testDevice("sdz1", 16785) < 0)
ret = -1;
if (testDevice("sdz15", 16799) < 0)
ret = -1;
DO_TEST("sdz", 16784);
DO_TEST("sdz1", 16785);
DO_TEST("sdz15", 16799);
/* first valid dual letter disk */
if (testDevice("sdaa", 16800) < 0)
ret = -1;
if (testDevice("sdaa1", 16801) < 0)
ret = -1;
if (testDevice("sdaa15", 16815) < 0)
ret = -1;
DO_TEST("sdaa", 16800);
DO_TEST("sdaa1", 16801);
DO_TEST("sdaa15", 16815);
/* second valid dual letter disk */
if (testDevice("sdab", 16816) < 0)
ret = -1;
if (testDevice("sdab1", 16817) < 0)
ret = -1;
if (testDevice("sdab15", 16831) < 0)
ret = -1;
DO_TEST("sdab", 16816);
DO_TEST("sdab1", 16817);
DO_TEST("sdab15", 16831);
/* first letter of second sequence of dual letter disk */
if (testDevice("sdba", 17216) < 0)
ret = -1;
if (testDevice("sdba1", 17217) < 0)
ret = -1;
if (testDevice("sdba15", 17231) < 0)
ret = -1;
DO_TEST("sdba", 17216);
DO_TEST("sdba1", 17217);
DO_TEST("sdba15", 17231);
/* last valid dual letter disk */
if (testDevice("sdiv", 34800) < 0)
ret = -1;
if (testDevice("sdiv1", 34801) < 0)
ret = -1;
if (testDevice("sdiv15", 34815) < 0)
ret = -1;
DO_TEST("sdiv", 34800);
DO_TEST("sdiv1", 34801);
DO_TEST("sdiv15", 34815);
/* Disk letter to large */
if (testDevice("sdix", -1) < 0)
ret = -1;
DO_TEST("sdix", -1);
/* missing disk letter */
if (testDevice("sd1", -1) < 0)
ret = -1;
DO_TEST("sd1", -1);
/* partition to large */
if (testDevice("sda16", -1) < 0)
ret = -1;
DO_TEST("sda16", -1);
/* partition to small */
if (testDevice("sda0", -1) < 0)
ret = -1;
DO_TEST("sda0", -1);
/* Path stripping */
if (testDevice("/dev", -1) < 0)
ret = -1;
if (testDevice("/dev/", -1) < 0)
ret = -1;
if (testDevice("/dev/xvd", -1) < 0)
ret = -1;
if (testDevice("/dev/xvda", 51712) < 0)
ret = -1;
if (testDevice("/dev/xvda1", 51713) < 0)
ret = -1;
if (testDevice("/dev/xvda15", 51727) < 0)
ret = -1;
DO_TEST("/dev", -1);
DO_TEST("/dev/", -1);
DO_TEST("/dev/xvd", -1);
DO_TEST("/dev/xvda", 51712);
DO_TEST("/dev/xvda1", 51713);
DO_TEST("/dev/xvda15", 51727);
#endif
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
......
#!/bin/bash
set -x
NOK=0
for f in $abs_top_srcdir/tests/confdata/*.conf
#!/bin/sh
if test "$VERBOSE" = yes; then
set -x
virsh --version
fi
. $srcdir/test-lib.sh
set -e
if test "x$abs_srcdir" = x; then
abs_srcdir=`pwd`
abs_builddir=`pwd`
fi
fail=0
i=1
data_dir=$abs_srcdir/confdata
for f in $(cd "$data_dir" && echo *.conf)
do
./conftest $f > conftest.$$
outfile=`echo "$f" | sed s+\.conf$+\.out+`
diff $outfile conftest.$$ > /dev/null
if [ $? != 0 ]
then
if [ -n "$DEBUG_TESTS" ]; then
diff -u $outfile conftest.$$
fi
echo "$f FAILED"
NOK=1
"$abs_builddir/conftest" "$data_dir/$f" > "$f-actual"
expected="$data_dir"/`echo "$f" | sed s+\.conf$+\.out+`
if compare "$expected" "$f-actual"; then
msg=OK
else
echo "$f OK"
msg=FAILED
fail=1
fi
printf "%2d) %-60s ... %s\n" $i "$f" $msg
i=`expr $i + 1`
done
rm -f conftest.$$
exit $NOK
(exit $fail); exit $fail
......@@ -50,14 +50,10 @@ static int testCompareFiles(const char *hostmachine,
if (!(actualxml = xenHypervisorMakeCapabilitiesXML(NULL, hostmachine, fp1, fp2)))
goto fail;
if (getenv("DEBUG_TESTS") &&
STRNEQ(expectxml, actualxml)) {
printf("In test file %s:\n", capabilities);
printf("Expect %d '%s'\n", (int)strlen(expectxml), expectxml);
printf("Actual %d '%s'\n", (int)strlen(actualxml), actualxml);
if (STRNEQ(expectxml, actualxml)) {
virtTestDifference(stderr, expectxml, actualxml);
goto fail;
}
if (strcmp(expectxml, actualxml))
goto fail;
ret = 0;
......
......@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#ifdef WITH_XEN
......@@ -35,11 +36,11 @@
#include "conf.h"
static char *progname;
static char *abs_top_srcdir;
static char *abs_srcdir;
#define MAX_FILE 4096
static int testCompareParseXML(const char *xmcfg_rel, const char *xml_rel,
static int testCompareParseXML(const char *xmcfg, const char *xml,
int xendConfigVersion) {
char xmlData[MAX_FILE];
char xmcfgData[MAX_FILE];
......@@ -53,11 +54,6 @@ static int testCompareParseXML(const char *xmcfg_rel, const char *xml_rel,
int wrote = MAX_FILE;
void *old_priv = NULL;
struct _xenUnifiedPrivate priv;
char xmcfg[PATH_MAX];
char xml[PATH_MAX];
snprintf(xmcfg, sizeof xmcfg - 1, "%s/tests/%s", abs_top_srcdir, xmcfg_rel);
snprintf(xml, sizeof xml - 1, "%s/tests/%s", abs_top_srcdir, xml_rel);
conn = virConnectOpenReadOnly("test:///default");
if (!conn) goto fail;
......@@ -80,11 +76,8 @@ static int testCompareParseXML(const char *xmcfg_rel, const char *xml_rel,
goto fail;
gotxmcfgPtr[wrote] = '\0';
if (strcmp(xmcfgData, gotxmcfgData)) {
if (getenv("DEBUG_TESTS")) {
printf("Expect %d '%s'\n", (int)strlen(xmcfgData), xmcfgData);
printf("Actual %d '%s'\n", (int)strlen(gotxmcfgData), gotxmcfgData);
}
if (STRNEQ(xmcfgData, gotxmcfgData)) {
virtTestDifference(stderr, xmcfgData, gotxmcfgData);
goto fail;
}
......@@ -102,7 +95,7 @@ static int testCompareParseXML(const char *xmcfg_rel, const char *xml_rel,
return ret;
}
static int testCompareFormatXML(const char *xmcfg_rel, const char *xml_rel,
static int testCompareFormatXML(const char *xmcfg, const char *xml,
int xendConfigVersion) {
char xmlData[MAX_FILE];
char xmcfgData[MAX_FILE];
......@@ -114,11 +107,6 @@ static int testCompareFormatXML(const char *xmcfg_rel, const char *xml_rel,
virConnectPtr conn;
void *old_priv;
struct _xenUnifiedPrivate priv;
char xmcfg[PATH_MAX];
char xml[PATH_MAX];
snprintf(xmcfg, sizeof xmcfg - 1, "%s/tests/%s", abs_top_srcdir, xmcfg_rel);
snprintf(xml, sizeof xml - 1, "%s/tests/%s", abs_top_srcdir, xml_rel);
conn = virConnectOpenReadOnly("test:///default");
if (!conn) goto fail;
......@@ -163,102 +151,25 @@ static int testCompareFormatXML(const char *xmcfg_rel, const char *xml_rel,
return ret;
}
static int testCompareParavirtOldPVFBFormat(const void *data ATTRIBUTE_UNUSED) {
return testCompareFormatXML("xmconfigdata/test-paravirt-old-pvfb.cfg",
"xmconfigdata/test-paravirt-old-pvfb.xml",
2);
}
static int testCompareParavirtOldPVFBParse(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-paravirt-old-pvfb.cfg",
"xmconfigdata/test-paravirt-old-pvfb.xml",
2);
}
static int testCompareParavirtNewPVFBFormat(const void *data ATTRIBUTE_UNUSED) {
return testCompareFormatXML("xmconfigdata/test-paravirt-new-pvfb.cfg",
"xmconfigdata/test-paravirt-new-pvfb.xml",
3);
}
static int testCompareParavirtNewPVFBParse(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-paravirt-new-pvfb.cfg",
"xmconfigdata/test-paravirt-new-pvfb.xml",
3);
}
static int testCompareFullvirtOldCDROMFormat(const void *data ATTRIBUTE_UNUSED) {
return testCompareFormatXML("xmconfigdata/test-fullvirt-old-cdrom.cfg",
"xmconfigdata/test-fullvirt-old-cdrom.xml",
1);
}
static int testCompareFullvirtOldCDROMParse(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-fullvirt-old-cdrom.cfg",
"xmconfigdata/test-fullvirt-old-cdrom.xml",
1);
}
static int testCompareFullvirtNewCDROMFormat(const void *data ATTRIBUTE_UNUSED) {
return testCompareFormatXML("xmconfigdata/test-fullvirt-new-cdrom.cfg",
"xmconfigdata/test-fullvirt-new-cdrom.xml",
2);
}
static int testCompareFullvirtNewCDROMParse(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-fullvirt-new-cdrom.cfg",
"xmconfigdata/test-fullvirt-new-cdrom.xml",
2);
}
static int testCompareFullvirtClockUTCFormat(const void *data ATTRIBUTE_UNUSED) {
return testCompareFormatXML("xmconfigdata/test-fullvirt-utc.cfg",
"xmconfigdata/test-fullvirt-utc.xml",
2);
}
static int testCompareFullvirtClockUTCParse(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-fullvirt-utc.cfg",
"xmconfigdata/test-fullvirt-utc.xml",
2);
}
static int testCompareFullvirtClockLocaltimeFormat(const void *data ATTRIBUTE_UNUSED) {
return testCompareFormatXML("xmconfigdata/test-fullvirt-localtime.cfg",
"xmconfigdata/test-fullvirt-localtime.xml",
2);
}
static int testCompareFullvirtClockLocaltimeParse(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-fullvirt-localtime.cfg",
"xmconfigdata/test-fullvirt-localtime.xml",
2);
}
static int testCompareFullvirtInputUSBTabletFormat(const void *data ATTRIBUTE_UNUSED) {
return testCompareFormatXML("xmconfigdata/test-fullvirt-usbtablet.cfg",
"xmconfigdata/test-fullvirt-usbtablet.xml",
2);
}
struct testInfo {
const char *name;
int version;
int mode;
};
static int testCompareFullvirtInputUSBTabletParse(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-fullvirt-usbtablet.cfg",
"xmconfigdata/test-fullvirt-usbtablet.xml",
2);
}
static int testCompareFullvirtInputUSBTabletNoBusParse(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-fullvirt-usbtablet.cfg",
"xmconfigdata/test-fullvirt-usbtablet-no-bus.xml",
2);
}
static int testCompareFullvirtInputUSBMouseFormat(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-fullvirt-usbmouse.cfg",
"xmconfigdata/test-fullvirt-usbmouse.xml",
2);
}
static int testCompareFullvirtInputUSBMouseParse(const void *data ATTRIBUTE_UNUSED) {
return testCompareParseXML("xmconfigdata/test-fullvirt-usbmouse.cfg",
"xmconfigdata/test-fullvirt-usbmouse.xml",
2);
static int testCompareHelper(const void *data) {
const struct testInfo *info = data;
char xml[PATH_MAX];
char cfg[PATH_MAX];
snprintf(xml, PATH_MAX, "%s/xmconfigdata/test-%s.xml",
abs_srcdir, info->name);
snprintf(cfg, PATH_MAX, "%s/xmconfigdata/test-%s.cfg",
abs_srcdir, info->name);
if (info->mode == 0)
return testCompareParseXML(cfg, xml, info->version);
else
return testCompareFormatXML(cfg, xml, info->version);
}
......@@ -266,6 +177,7 @@ int
main(int argc, char **argv)
{
int ret = 0;
char cwd[PATH_MAX];
progname = argv[0];
......@@ -274,65 +186,31 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
abs_top_srcdir = getenv("abs_top_srcdir");
if (!abs_top_srcdir)
return 1;
/* Config -> XML */
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("Fullvirt clock Localtime (Format)",
1, testCompareFullvirtClockLocaltimeFormat, NULL) != 0)
ret = -1;
if (virtTestRun("Fullvirt clock UTC (Format)",
1, testCompareFullvirtClockUTCFormat, NULL) != 0)
ret = -1;
if (virtTestRun("Fullvirt USB mouse (Format)",
1, testCompareFullvirtInputUSBMouseFormat, NULL) != 0)
ret = -1;
if (virtTestRun("Fullvirt USB tablet (Format)",
1, testCompareFullvirtInputUSBTabletFormat, NULL) != 0)
ret = -1;
/* XML -> Config */
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;
if (virtTestRun("Fullvirt clock Localtime (Parse)",
1, testCompareFullvirtClockLocaltimeParse, NULL) != 0)
ret = -1;
if (virtTestRun("Fullvirt clock UTC (Parse)",
1, testCompareFullvirtClockUTCParse, NULL) != 0)
ret = -1;
if (virtTestRun("Fullvirt USB mouse (Parse)",
1, testCompareFullvirtInputUSBMouseParse, NULL) != 0)
ret = -1;
if (virtTestRun("Fullvirt USB tablet (Parse)",
1, testCompareFullvirtInputUSBTabletParse, NULL) != 0)
ret = -1;
if (virtTestRun("Fullvirt USB tablet no bus (Parse)",
1, testCompareFullvirtInputUSBTabletNoBusParse, NULL) != 0)
ret = -1;
abs_srcdir = getenv("abs_srcdir");
if (!abs_srcdir)
abs_srcdir = getcwd(cwd, sizeof(cwd));
#define DO_TEST(name, version) \
do { \
struct testInfo info0 = { name, version, 0 }; \
struct testInfo info1 = { name, version, 1 }; \
if (virtTestRun("Xen XM-2-XML Parse " name, \
1, testCompareHelper, &info0) < 0) \
ret = -1; \
if (virtTestRun("Xen XM-2-XML Format " name, \
1, testCompareHelper, &info1) < 0) \
ret = -1; \
} while (0)
DO_TEST("paravirt-old-pvfb", 2);
DO_TEST("paravirt-new-pvfb", 3);
DO_TEST("fullvirt-old-cdrom", 1);
DO_TEST("fullvirt-new-cdrom", 2);
DO_TEST("fullvirt-utc", 2);
DO_TEST("fullvirt-localtime", 2);
DO_TEST("fullvirt-usbtablet", 2);
DO_TEST("fullvirt-usbmouse", 2);
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册