From 348209ca264bdd9c4b464bb4d974c5bda9ae34c3 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 27 Mar 2007 14:45:17 +0000 Subject: [PATCH] Fixed Xen capabilities parsing & added test suite --- ChangeLog | 9 + configure.in | 1 + src/xen_internal.c | 238 +++++++++++++-------- src/xen_internal.h | 5 + tests/Makefile.am | 11 +- tests/xencapsdata/.cvsignore | 2 + tests/xencapsdata/Makefile.am | 2 + tests/xencapsdata/xen-i686-pae-hvm.caps | 1 + tests/xencapsdata/xen-i686-pae-hvm.cpuinfo | 38 ++++ tests/xencapsdata/xen-i686-pae-hvm.xml | 37 ++++ tests/xencapsdata/xen-i686-pae.caps | 1 + tests/xencapsdata/xen-i686-pae.cpuinfo | 20 ++ tests/xencapsdata/xen-i686-pae.xml | 21 ++ tests/xencapsdata/xen-i686.caps | 1 + tests/xencapsdata/xen-i686.cpuinfo | 19 ++ tests/xencapsdata/xen-i686.xml | 20 ++ tests/xencapsdata/xen-ia64-be-hvm.caps | 1 + tests/xencapsdata/xen-ia64-be-hvm.cpuinfo | 29 +++ tests/xencapsdata/xen-ia64-be-hvm.xml | 35 +++ tests/xencapsdata/xen-ia64-be.caps | 1 + tests/xencapsdata/xen-ia64-be.cpuinfo | 29 +++ tests/xencapsdata/xen-ia64-be.xml | 20 ++ tests/xencapsdata/xen-ia64-hvm.caps | 1 + tests/xencapsdata/xen-ia64-hvm.cpuinfo | 29 +++ tests/xencapsdata/xen-ia64-hvm.xml | 33 +++ tests/xencapsdata/xen-ia64.caps | 1 + tests/xencapsdata/xen-ia64.cpuinfo | 29 +++ tests/xencapsdata/xen-ia64.xml | 19 ++ tests/xencapsdata/xen-ppc64.caps | 1 + tests/xencapsdata/xen-ppc64.cpuinfo | 0 tests/xencapsdata/xen-ppc64.xml | 19 ++ tests/xencapsdata/xen-x86_64-hvm.caps | 1 + tests/xencapsdata/xen-x86_64-hvm.cpuinfo | 47 ++++ tests/xencapsdata/xen-x86_64-hvm.xml | 50 +++++ tests/xencapsdata/xen-x86_64.caps | 1 + tests/xencapsdata/xen-x86_64.cpuinfo | 47 ++++ tests/xencapsdata/xen-x86_64.xml | 20 ++ tests/xencapstest.c | 199 +++++++++++++++++ 38 files changed, 943 insertions(+), 95 deletions(-) create mode 100644 tests/xencapsdata/.cvsignore create mode 100644 tests/xencapsdata/Makefile.am create mode 100644 tests/xencapsdata/xen-i686-pae-hvm.caps create mode 100644 tests/xencapsdata/xen-i686-pae-hvm.cpuinfo create mode 100644 tests/xencapsdata/xen-i686-pae-hvm.xml create mode 100644 tests/xencapsdata/xen-i686-pae.caps create mode 100644 tests/xencapsdata/xen-i686-pae.cpuinfo create mode 100644 tests/xencapsdata/xen-i686-pae.xml create mode 100644 tests/xencapsdata/xen-i686.caps create mode 100644 tests/xencapsdata/xen-i686.cpuinfo create mode 100644 tests/xencapsdata/xen-i686.xml create mode 100644 tests/xencapsdata/xen-ia64-be-hvm.caps create mode 100644 tests/xencapsdata/xen-ia64-be-hvm.cpuinfo create mode 100644 tests/xencapsdata/xen-ia64-be-hvm.xml create mode 100644 tests/xencapsdata/xen-ia64-be.caps create mode 100644 tests/xencapsdata/xen-ia64-be.cpuinfo create mode 100644 tests/xencapsdata/xen-ia64-be.xml create mode 100644 tests/xencapsdata/xen-ia64-hvm.caps create mode 100644 tests/xencapsdata/xen-ia64-hvm.cpuinfo create mode 100644 tests/xencapsdata/xen-ia64-hvm.xml create mode 100644 tests/xencapsdata/xen-ia64.caps create mode 100644 tests/xencapsdata/xen-ia64.cpuinfo create mode 100644 tests/xencapsdata/xen-ia64.xml create mode 100644 tests/xencapsdata/xen-ppc64.caps create mode 100644 tests/xencapsdata/xen-ppc64.cpuinfo create mode 100644 tests/xencapsdata/xen-ppc64.xml create mode 100644 tests/xencapsdata/xen-x86_64-hvm.caps create mode 100644 tests/xencapsdata/xen-x86_64-hvm.cpuinfo create mode 100644 tests/xencapsdata/xen-x86_64-hvm.xml create mode 100644 tests/xencapsdata/xen-x86_64.caps create mode 100644 tests/xencapsdata/xen-x86_64.cpuinfo create mode 100644 tests/xencapsdata/xen-x86_64.xml create mode 100644 tests/xencapstest.c diff --git a/ChangeLog b/ChangeLog index f354109078..8491d7f926 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Mar 27 10:39:00 EDT 2007 Daniel P. Berrange + + * src/xen_internal.c: Fix handling of PAE flags in capabilities XML + generation & merge duplicate (arch,os-type) entries. + * tests/xencapstest.c: Added a test suite for various Xen capabilities + data sets + * tests/xencapsdata/*: Added data files for Xen capabilities tests + * configure.ac, tests/Makefile.am: Added tests/xencapsdata/ directory + Tue Mar 27 11:26:00 BST 2007 Richard W.M. Jones * qemud/qemud.c: If using FORTIFY_SOURCE, remove warning diff --git a/configure.in b/configure.in index d67d0a667a..8e3e291397 100644 --- a/configure.in +++ b/configure.in @@ -431,4 +431,5 @@ AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \ tests/xml2sexprdata/Makefile \ tests/sexpr2xmldata/Makefile \ tests/xmconfigdata/Makefile \ + tests/xencapsdata/Makefile \ tests/virshdata/Makefile tests/confdata/Makefile) diff --git a/src/xen_internal.c b/src/xen_internal.c index 5c4a0e7fb4..b275d41080 100644 --- a/src/xen_internal.c +++ b/src/xen_internal.c @@ -85,7 +85,7 @@ static const char *flags_hvm_re = "^flags[[:blank:]]+:.* (vmx|svm)[[:space:]]"; static regex_t flags_hvm_rec; static const char *flags_pae_re = "^flags[[:blank:]]+:.* pae[[:space:]]"; static regex_t flags_pae_rec; -static const char *xen_cap_re = "(xen|hvm)-[[:digit:]]+\\.[[:digit:]]+-(x86_32|x86_64|ia64)(p|be)?"; +static const char *xen_cap_re = "(xen|hvm)-[[:digit:]]+\\.[[:digit:]]+-(x86_32|x86_64|ia64|powerpc64)(p|be)?"; static regex_t xen_cap_rec; /* @@ -1472,27 +1472,29 @@ xenHypervisorGetVersion(virConnectPtr conn, unsigned long *hvVer) /** * xenHypervisorGetCapabilities: * @conn: pointer to the connection block + * @cpuinfo: file handle containing /proc/cpuinfo data, or NULL + * @capabilities: file handle containing /sys/hypervisor/properties/capabilities data, or NULL * * Return the capabilities of this hypervisor. */ char * -xenHypervisorGetCapabilities (virConnectPtr conn) +xenHypervisorMakeCapabilitiesXML(virConnectPtr conn ATTRIBUTE_UNUSED, + const char *hostmachine, + FILE *cpuinfo, FILE *capabilities) { - struct utsname utsname; char line[1024], *str, *token; regmatch_t subs[4]; char *saveptr = NULL; - FILE *fp; int i, r; char hvm_type[4] = ""; /* "vmx" or "svm" (or "" if not in CPU). */ int host_pae = 0; struct guest_arch { - const char *token; const char *model; int bits; int hvm; int pae; + int nonpae; int ia64_be; } guest_archs[32]; int nr_guest_archs = 0; @@ -1502,34 +1504,22 @@ xenHypervisorGetCapabilities (virConnectPtr conn) memset(guest_archs, 0, sizeof(guest_archs)); - /* Really, this never fails - look at the man-page. */ - uname (&utsname); - /* /proc/cpuinfo: flags: Intel calls HVM "vmx", AMD calls it "svm". * It's not clear if this will work on IA64, let alone other * architectures and non-Linux. (XXX) */ - fp = fopen ("/proc/cpuinfo", "r"); - if (fp == NULL) { - if (errno == ENOENT) - goto nocpuinfo; - virXenPerror (conn, "/proc/cpuinfo"); - return NULL; + if (cpuinfo) { + while (fgets (line, sizeof line, cpuinfo)) { + if (regexec (&flags_hvm_rec, line, sizeof(subs)/sizeof(regmatch_t), subs, 0) == 0 + && subs[0].rm_so != -1) { + strncpy (hvm_type, + &line[subs[1].rm_so], subs[1].rm_eo-subs[1].rm_so+1); + hvm_type[subs[1].rm_eo-subs[1].rm_so] = '\0'; + } else if (regexec (&flags_pae_rec, line, 0, NULL, 0) == 0) + host_pae = 1; + } } - while (fgets (line, sizeof line, fp)) { - if (regexec (&flags_hvm_rec, line, sizeof(subs)/sizeof(regmatch_t), subs, 0) == 0 - && subs[0].rm_so != -1) { - strncpy (hvm_type, - &line[subs[1].rm_so], subs[1].rm_eo-subs[1].rm_so+1); - hvm_type[subs[1].rm_eo-subs[1].rm_so] = '\0'; - } else if (regexec (&flags_pae_rec, line, 0, NULL, 0) == 0) - host_pae = 1; - } - - fclose (fp); - - nocpuinfo: /* Most of the useful info is in /sys/hypervisor/properties/capabilities * which is documented in the code in xen-unstable.hg/xen/arch/.../setup.c. * @@ -1553,63 +1543,81 @@ xenHypervisorGetCapabilities (virConnectPtr conn) * | +----------- the version of Xen, eg. "3.0" * +--------------- "xen" or "hvm" for para or full virt respectively */ - fp = fopen ("/sys/hypervisor/properties/capabilities", "r"); - if (fp == NULL) { - if (errno == ENOENT) - goto noxencaps; - virXenPerror (conn, "/sys/hypervisor/properties/capabilities"); - return NULL; - } /* Expecting one line in this file - ignore any more. */ - if (!fgets (line, sizeof line, fp)) { - fclose (fp); - goto noxencaps; - } + if (fgets (line, sizeof line, capabilities)) { + /* Split the line into tokens. strtok_r is OK here because we "own" + * this buffer. Parse out the features from each token. + */ + for (str = line, nr_guest_archs = 0; + nr_guest_archs < sizeof guest_archs / sizeof guest_archs[0] + && (token = strtok_r (str, " ", &saveptr)) != NULL; + str = NULL) { - fclose (fp); + if (regexec (&xen_cap_rec, token, sizeof subs / sizeof subs[0], + subs, 0) == 0) { + int hvm = strncmp (&token[subs[1].rm_so], "hvm", 3) == 0; + const char *model; + int bits, pae = 0, nonpae = 0, ia64_be = 0; + if (strncmp (&token[subs[2].rm_so], "x86_32", 6) == 0) { + model = "i686"; + bits = 32; + if (strncmp (&token[subs[3].rm_so], "p", 1) == 0) + pae = 1; + else + nonpae = 1; + } + else if (strncmp (&token[subs[2].rm_so], "x86_64", 6) == 0) { + model = "x86_64"; + bits = 64; + } + else if (strncmp (&token[subs[2].rm_so], "ia64", 4) == 0) { + model = "ia64"; + bits = 64; + if (strncmp (&token[subs[3].rm_so], "be", 2) == 0) + ia64_be = 1; + } + else if (strncmp (&token[subs[2].rm_so], "powerpc64", 4) == 0) { + model = "ppc64"; + bits = 64; + } else { + /* XXX surely no other Xen archs exist */ + continue; + } - /* Split the line into tokens. strtok_r is OK here because we "own" - * this buffer. Parse out the features from each token. - */ - for (str = line, nr_guest_archs = 0; - nr_guest_archs < sizeof guest_archs / sizeof guest_archs[0] - && (token = strtok_r (str, " ", &saveptr)) != NULL; - str = NULL) { - if (regexec (&xen_cap_rec, token, sizeof subs / sizeof subs[0], - subs, 0) == 0) { - token[subs[0].rm_eo] = '\0'; - guest_archs[nr_guest_archs].token = token; - guest_archs[nr_guest_archs].hvm = - strncmp (&token[subs[1].rm_so], "hvm", 3) == 0; - if (strncmp (&token[subs[2].rm_so], "x86_32", 6) == 0) { - guest_archs[nr_guest_archs].model = "i686"; - guest_archs[nr_guest_archs].bits = 32; + /* Search for existing matching (model,hvm) tuple */ + for (i = 0 ; i < nr_guest_archs ; i++) { + if (!strcmp(guest_archs[i].model, model) && + guest_archs[i].hvm == hvm) { + break; + } + } + + /* Too many arch flavours - highly unlikely ! */ + if (i >= sizeof(guest_archs)/sizeof(guest_archs[0])) + continue; + /* Didn't find a match, so create a new one */ + if (i == nr_guest_archs) + nr_guest_archs++; + + guest_archs[i].model = model; + guest_archs[i].bits = bits; + guest_archs[i].hvm = hvm; + + /* Careful not to overwrite a previous positive + setting with a negative one here - some archs + can do both pae & non-pae, but Xen reports + separately capabilities so we're merging archs */ + if (pae) + guest_archs[i].pae = pae; + if (nonpae) + guest_archs[i].nonpae = nonpae; + if (ia64_be) + guest_archs[i].ia64_be = ia64_be; } - else if (strncmp (&token[subs[2].rm_so], "x86_64", 6) == 0) { - guest_archs[nr_guest_archs].model = "x86_64"; - guest_archs[nr_guest_archs].bits = 64; - } - else if (strncmp (&token[subs[2].rm_so], "ia64", 4) == 0) { - guest_archs[nr_guest_archs].model = "ia64"; - guest_archs[nr_guest_archs].bits = 64; - } - else { - guest_archs[nr_guest_archs].model = ""; /* can never happen */ - } - guest_archs[nr_guest_archs].pae = - guest_archs[nr_guest_archs].ia64_be = 0; - if (subs[2].rm_so != -1) { - if (strncmp (&token[subs[3].rm_so], "p", 1) == 0) - guest_archs[nr_guest_archs].pae = 1; - else if (strncmp (&token[subs[3].rm_so], "be", 2) == 0) - guest_archs[nr_guest_archs].ia64_be = 1; - } - nr_guest_archs++; } } - noxencaps: /* Construct the final XML. */ xml = virBufferNew (1024); if (!xml) return NULL; @@ -1620,19 +1628,15 @@ xenHypervisorGetCapabilities (virConnectPtr conn) \n\ %s\n\ \n", - utsname.machine); - if (r == -1) return NULL; + hostmachine); + if (r == -1) goto vir_buffer_failed; if (strcmp (hvm_type, "") != 0) { r = virBufferVSprintf (xml, "\ <%s/>\n", hvm_type); - if (r == -1) { - vir_buffer_failed: - virBufferFree (xml); - return NULL; - } + if (r == -1) goto vir_buffer_failed; } if (host_pae) { r = virBufferAdd (xml, "\ @@ -1650,25 +1654,23 @@ xenHypervisorGetCapabilities (virConnectPtr conn) r = virBufferVSprintf (xml, "\ \n\ - \n\ \n\ %s\n\ \n\ %d\n\ - \n\ - /usr/lib%s/xen/bin/qemu-dm\n", - guest_archs[i].token, + \n", guest_archs[i].hvm ? "hvm" : "xen", guest_archs[i].model, - guest_archs[i].bits, - guest_archs[i].bits == 64 ? "64" : ""); + guest_archs[i].bits); if (r == -1) goto vir_buffer_failed; if (guest_archs[i].hvm) { - r = virBufferAdd (xml, + r = virBufferVSprintf (xml, "\ + /usr/lib%s/xen/bin/qemu-dm\n\ pc\n\ isapc\n\ - /usr/lib/xen/boot/hvmloader\n", -1); + /usr/lib/xen/boot/hvmloader\n", + guest_archs[i].bits == 64 ? "64" : ""); if (r == -1) goto vir_buffer_failed; } r = virBufferAdd (xml, @@ -1679,7 +1681,12 @@ xenHypervisorGetCapabilities (virConnectPtr conn) if (guest_archs[i].pae) { r = virBufferAdd (xml, "\ - \n\ + \n", -1); + if (r == -1) goto vir_buffer_failed; + } + if (guest_archs[i].nonpae) { + r = virBufferAdd (xml, + "\ \n", -1); if (r == -1) goto vir_buffer_failed; } @@ -1707,6 +1714,53 @@ xenHypervisorGetCapabilities (virConnectPtr conn) virBufferFree (xml); return xml_str; + + vir_buffer_failed: + virBufferFree (xml); + return NULL; +} + +/** + * xenHypervisorGetCapabilities: + * @conn: pointer to the connection block + * + * Return the capabilities of this hypervisor. + */ +char * +xenHypervisorGetCapabilities (virConnectPtr conn) +{ + char *xml; + FILE *cpuinfo, *capabilities; + struct utsname utsname; + + /* Really, this never fails - look at the man-page. */ + uname (&utsname); + + cpuinfo = fopen ("/proc/cpuinfo", "r"); + if (cpuinfo == NULL) { + if (errno != ENOENT) { + virXenPerror (conn, "/proc/cpuinfo"); + return NULL; + } + } + + capabilities = fopen ("/sys/hypervisor/properties/capabilities", "r"); + if (capabilities == NULL) { + if (errno != ENOENT) { + fclose(cpuinfo); + virXenPerror (conn, "/sys/hypervisor/properties/capabilities"); + return NULL; + } + } + + xml = xenHypervisorMakeCapabilitiesXML(conn, utsname.machine, cpuinfo, capabilities); + + if (cpuinfo) + fclose(cpuinfo); + if (capabilities) + fclose(capabilities); + + return xml; } /** diff --git a/src/xen_internal.h b/src/xen_internal.h index e296d81225..584fa5fc99 100644 --- a/src/xen_internal.h +++ b/src/xen_internal.h @@ -22,6 +22,11 @@ int xenHypervisorOpen (virConnectPtr conn, int xenHypervisorClose (virConnectPtr conn); int xenHypervisorGetVersion (virConnectPtr conn, unsigned long *hvVer); +char * + xenHypervisorMakeCapabilitiesXML (virConnectPtr conn, + const char *hostmachine, + FILE *cpuinfo, + FILE *capabilities); char * xenHypervisorGetCapabilities (virConnectPtr conn); unsigned long diff --git a/tests/Makefile.am b/tests/Makefile.am index a2a74444fa..77a965e77d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata xmconfigdata +SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata xmconfigdata xencapsdata # Wierd libtool related juju... # @@ -31,9 +31,9 @@ LDADDS = \ EXTRA_DIST = xmlrpcserver.py test_conf.sh noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \ - reconnect xmconfigtest + reconnect xmconfigtest xencapstest -TESTS = xml2sexprtest sexpr2xmltest virshtest test_conf.sh xmconfigtest +TESTS = xml2sexprtest sexpr2xmltest virshtest test_conf.sh xmconfigtest xencapstest if ENABLE_XEN_TESTS TESTS += reconnect endif @@ -80,6 +80,11 @@ conftest_SOURCES = \ conftest_LDFLAGS = conftest_LDADD = $(LDADDS) +xencapstest_SOURCES = \ + xencapstest.c testutils.h testutils.c +xencapstest_LDFLAGS = +xencapstest_LDADD = $(LDADDS) + reconnect_SOURCES = \ reconnect.c reconnect_LDFLAGS = diff --git a/tests/xencapsdata/.cvsignore b/tests/xencapsdata/.cvsignore new file mode 100644 index 0000000000..282522db03 --- /dev/null +++ b/tests/xencapsdata/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/tests/xencapsdata/Makefile.am b/tests/xencapsdata/Makefile.am new file mode 100644 index 0000000000..7d775758f5 --- /dev/null +++ b/tests/xencapsdata/Makefile.am @@ -0,0 +1,2 @@ + +EXTRA_DIST = $(wildcard *.xml) $(wildcard *.cpuinfo) $(wildcard *.caps) diff --git a/tests/xencapsdata/xen-i686-pae-hvm.caps b/tests/xencapsdata/xen-i686-pae-hvm.caps new file mode 100644 index 0000000000..904b67f286 --- /dev/null +++ b/tests/xencapsdata/xen-i686-pae-hvm.caps @@ -0,0 +1 @@ +xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p diff --git a/tests/xencapsdata/xen-i686-pae-hvm.cpuinfo b/tests/xencapsdata/xen-i686-pae-hvm.cpuinfo new file mode 100644 index 0000000000..c492924643 --- /dev/null +++ b/tests/xencapsdata/xen-i686-pae-hvm.cpuinfo @@ -0,0 +1,38 @@ +processor : 0 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Core(TM)2 CPU T7600 @ 2.33GHz +stepping : 6 +cpu MHz : 2327.560 +cache size : 4096 KB +fdiv_bug : no +hlt_bug : no +f00f_bug : no +coma_bug : no +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm +bogomips : 5821.44 + +processor : 1 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Core(TM)2 CPU T7600 @ 2.33GHz +stepping : 6 +cpu MHz : 2327.560 +cache size : 4096 KB +fdiv_bug : no +hlt_bug : no +f00f_bug : no +coma_bug : no +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm +bogomips : 5821.44 + diff --git a/tests/xencapsdata/xen-i686-pae-hvm.xml b/tests/xencapsdata/xen-i686-pae-hvm.xml new file mode 100644 index 0000000000..a9347a9832 --- /dev/null +++ b/tests/xencapsdata/xen-i686-pae-hvm.xml @@ -0,0 +1,37 @@ + + + + i686 + + + + + + + + xen + + 32 + + + + + + + + + hvm + + 32 + + /usr/lib/xen/bin/qemu-dm + pc + isapc + /usr/lib/xen/boot/hvmloader + + + + + + + diff --git a/tests/xencapsdata/xen-i686-pae.caps b/tests/xencapsdata/xen-i686-pae.caps new file mode 100644 index 0000000000..886855c401 --- /dev/null +++ b/tests/xencapsdata/xen-i686-pae.caps @@ -0,0 +1 @@ +xen-3.0-x86_32p diff --git a/tests/xencapsdata/xen-i686-pae.cpuinfo b/tests/xencapsdata/xen-i686-pae.cpuinfo new file mode 100644 index 0000000000..a249cf08ea --- /dev/null +++ b/tests/xencapsdata/xen-i686-pae.cpuinfo @@ -0,0 +1,20 @@ +processor : 0 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Core(TM)2 CPU T7600 @ 2.33GHz +stepping : 6 +cpu MHz : 2327.560 +cache size : 4096 KB +fdiv_bug : no +hlt_bug : no +f00f_bug : no +coma_bug : no +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm +bogomips : 5821.44 + + diff --git a/tests/xencapsdata/xen-i686-pae.xml b/tests/xencapsdata/xen-i686-pae.xml new file mode 100644 index 0000000000..d54b1cbe39 --- /dev/null +++ b/tests/xencapsdata/xen-i686-pae.xml @@ -0,0 +1,21 @@ + + + + i686 + + + + + + + + xen + + 32 + + + + + + + diff --git a/tests/xencapsdata/xen-i686.caps b/tests/xencapsdata/xen-i686.caps new file mode 100644 index 0000000000..8253fd33e0 --- /dev/null +++ b/tests/xencapsdata/xen-i686.caps @@ -0,0 +1 @@ +xen-3.0-x86_32 diff --git a/tests/xencapsdata/xen-i686.cpuinfo b/tests/xencapsdata/xen-i686.cpuinfo new file mode 100644 index 0000000000..ef8c0f8eef --- /dev/null +++ b/tests/xencapsdata/xen-i686.cpuinfo @@ -0,0 +1,19 @@ +processor : 0 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Core(TM)2 CPU T7600 @ 2.33GHz +stepping : 6 +cpu MHz : 2327.560 +cache size : 4096 KB +fdiv_bug : no +hlt_bug : no +f00f_bug : no +coma_bug : no +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu tsc msr mce cx8 apic mtrr mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor +bogomips : 5821.44 + diff --git a/tests/xencapsdata/xen-i686.xml b/tests/xencapsdata/xen-i686.xml new file mode 100644 index 0000000000..fa932a451f --- /dev/null +++ b/tests/xencapsdata/xen-i686.xml @@ -0,0 +1,20 @@ + + + + i686 + + + + + + + xen + + 32 + + + + + + + diff --git a/tests/xencapsdata/xen-ia64-be-hvm.caps b/tests/xencapsdata/xen-ia64-be-hvm.caps new file mode 100644 index 0000000000..aec634d6a9 --- /dev/null +++ b/tests/xencapsdata/xen-ia64-be-hvm.caps @@ -0,0 +1 @@ +xen-3.0-ia64be hvm-3.0-ia64be diff --git a/tests/xencapsdata/xen-ia64-be-hvm.cpuinfo b/tests/xencapsdata/xen-ia64-be-hvm.cpuinfo new file mode 100644 index 0000000000..0b70bfd870 --- /dev/null +++ b/tests/xencapsdata/xen-ia64-be-hvm.cpuinfo @@ -0,0 +1,29 @@ +processor : 0 +vendor : Xen/ia64 +arch : IA-64 +family : 32 +model : 0 +revision : 7 +archrev : 0 +features : branchlong, 16-byte atomic ops +cpu number : 0 +cpu regs : 4 +cpu MHz : 1594.000670 +itc MHz : 399.165930 +BogoMIPS : 3186.68 +siblings : 1 + +processor : 1 +vendor : Xen/ia64 +arch : IA-64 +family : 32 +model : 0 +revision : 7 +archrev : 0 +features : branchlong, 16-byte atomic ops +cpu number : 0 +cpu regs : 4 +cpu MHz : 1594.000670 +itc MHz : 399.165930 +BogoMIPS : 3186.68 +siblings : 1 diff --git a/tests/xencapsdata/xen-ia64-be-hvm.xml b/tests/xencapsdata/xen-ia64-be-hvm.xml new file mode 100644 index 0000000000..5e933d494d --- /dev/null +++ b/tests/xencapsdata/xen-ia64-be-hvm.xml @@ -0,0 +1,35 @@ + + + + ia64 + + + + + + + xen + + 64 + + + + + + + + + hvm + + 64 + + /usr/lib64/xen/bin/qemu-dm + pc + isapc + /usr/lib/xen/boot/hvmloader + + + + + + diff --git a/tests/xencapsdata/xen-ia64-be.caps b/tests/xencapsdata/xen-ia64-be.caps new file mode 100644 index 0000000000..d39c45e217 --- /dev/null +++ b/tests/xencapsdata/xen-ia64-be.caps @@ -0,0 +1 @@ +xen-3.0-ia64be diff --git a/tests/xencapsdata/xen-ia64-be.cpuinfo b/tests/xencapsdata/xen-ia64-be.cpuinfo new file mode 100644 index 0000000000..0b70bfd870 --- /dev/null +++ b/tests/xencapsdata/xen-ia64-be.cpuinfo @@ -0,0 +1,29 @@ +processor : 0 +vendor : Xen/ia64 +arch : IA-64 +family : 32 +model : 0 +revision : 7 +archrev : 0 +features : branchlong, 16-byte atomic ops +cpu number : 0 +cpu regs : 4 +cpu MHz : 1594.000670 +itc MHz : 399.165930 +BogoMIPS : 3186.68 +siblings : 1 + +processor : 1 +vendor : Xen/ia64 +arch : IA-64 +family : 32 +model : 0 +revision : 7 +archrev : 0 +features : branchlong, 16-byte atomic ops +cpu number : 0 +cpu regs : 4 +cpu MHz : 1594.000670 +itc MHz : 399.165930 +BogoMIPS : 3186.68 +siblings : 1 diff --git a/tests/xencapsdata/xen-ia64-be.xml b/tests/xencapsdata/xen-ia64-be.xml new file mode 100644 index 0000000000..507ef762f3 --- /dev/null +++ b/tests/xencapsdata/xen-ia64-be.xml @@ -0,0 +1,20 @@ + + + + ia64 + + + + + + + xen + + 64 + + + + + + + diff --git a/tests/xencapsdata/xen-ia64-hvm.caps b/tests/xencapsdata/xen-ia64-hvm.caps new file mode 100644 index 0000000000..21c7a21593 --- /dev/null +++ b/tests/xencapsdata/xen-ia64-hvm.caps @@ -0,0 +1 @@ +xen-3.0-ia64 hvm-3.0-ia64 diff --git a/tests/xencapsdata/xen-ia64-hvm.cpuinfo b/tests/xencapsdata/xen-ia64-hvm.cpuinfo new file mode 100644 index 0000000000..0b70bfd870 --- /dev/null +++ b/tests/xencapsdata/xen-ia64-hvm.cpuinfo @@ -0,0 +1,29 @@ +processor : 0 +vendor : Xen/ia64 +arch : IA-64 +family : 32 +model : 0 +revision : 7 +archrev : 0 +features : branchlong, 16-byte atomic ops +cpu number : 0 +cpu regs : 4 +cpu MHz : 1594.000670 +itc MHz : 399.165930 +BogoMIPS : 3186.68 +siblings : 1 + +processor : 1 +vendor : Xen/ia64 +arch : IA-64 +family : 32 +model : 0 +revision : 7 +archrev : 0 +features : branchlong, 16-byte atomic ops +cpu number : 0 +cpu regs : 4 +cpu MHz : 1594.000670 +itc MHz : 399.165930 +BogoMIPS : 3186.68 +siblings : 1 diff --git a/tests/xencapsdata/xen-ia64-hvm.xml b/tests/xencapsdata/xen-ia64-hvm.xml new file mode 100644 index 0000000000..61bcdf2b94 --- /dev/null +++ b/tests/xencapsdata/xen-ia64-hvm.xml @@ -0,0 +1,33 @@ + + + + ia64 + + + + + + + xen + + 64 + + + + + + + + hvm + + 64 + + /usr/lib64/xen/bin/qemu-dm + pc + isapc + /usr/lib/xen/boot/hvmloader + + + + + diff --git a/tests/xencapsdata/xen-ia64.caps b/tests/xencapsdata/xen-ia64.caps new file mode 100644 index 0000000000..b93c0b9413 --- /dev/null +++ b/tests/xencapsdata/xen-ia64.caps @@ -0,0 +1 @@ +xen-3.0-ia64 diff --git a/tests/xencapsdata/xen-ia64.cpuinfo b/tests/xencapsdata/xen-ia64.cpuinfo new file mode 100644 index 0000000000..0b70bfd870 --- /dev/null +++ b/tests/xencapsdata/xen-ia64.cpuinfo @@ -0,0 +1,29 @@ +processor : 0 +vendor : Xen/ia64 +arch : IA-64 +family : 32 +model : 0 +revision : 7 +archrev : 0 +features : branchlong, 16-byte atomic ops +cpu number : 0 +cpu regs : 4 +cpu MHz : 1594.000670 +itc MHz : 399.165930 +BogoMIPS : 3186.68 +siblings : 1 + +processor : 1 +vendor : Xen/ia64 +arch : IA-64 +family : 32 +model : 0 +revision : 7 +archrev : 0 +features : branchlong, 16-byte atomic ops +cpu number : 0 +cpu regs : 4 +cpu MHz : 1594.000670 +itc MHz : 399.165930 +BogoMIPS : 3186.68 +siblings : 1 diff --git a/tests/xencapsdata/xen-ia64.xml b/tests/xencapsdata/xen-ia64.xml new file mode 100644 index 0000000000..b1f97056bb --- /dev/null +++ b/tests/xencapsdata/xen-ia64.xml @@ -0,0 +1,19 @@ + + + + ia64 + + + + + + + xen + + 64 + + + + + + diff --git a/tests/xencapsdata/xen-ppc64.caps b/tests/xencapsdata/xen-ppc64.caps new file mode 100644 index 0000000000..df0fe93abd --- /dev/null +++ b/tests/xencapsdata/xen-ppc64.caps @@ -0,0 +1 @@ +xen-3.0-powerpc64 diff --git a/tests/xencapsdata/xen-ppc64.cpuinfo b/tests/xencapsdata/xen-ppc64.cpuinfo new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/xencapsdata/xen-ppc64.xml b/tests/xencapsdata/xen-ppc64.xml new file mode 100644 index 0000000000..1c4a8fa61f --- /dev/null +++ b/tests/xencapsdata/xen-ppc64.xml @@ -0,0 +1,19 @@ + + + + ppc64 + + + + + + + xen + + 64 + + + + + + diff --git a/tests/xencapsdata/xen-x86_64-hvm.caps b/tests/xencapsdata/xen-x86_64-hvm.caps new file mode 100644 index 0000000000..1701a34a9a --- /dev/null +++ b/tests/xencapsdata/xen-x86_64-hvm.caps @@ -0,0 +1 @@ +xen-3.0-x86_64 hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64 diff --git a/tests/xencapsdata/xen-x86_64-hvm.cpuinfo b/tests/xencapsdata/xen-x86_64-hvm.cpuinfo new file mode 100644 index 0000000000..1beedd2eb2 --- /dev/null +++ b/tests/xencapsdata/xen-x86_64-hvm.cpuinfo @@ -0,0 +1,47 @@ +processor : 0 +vendor_id : AuthenticAMD +cpu family : 15 +model : 67 +model name : AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ +stepping : 2 +cpu MHz : 2600.000 +cache size : 1024 KB +physical id : 0 +siblings : 1 +core id : 0 +cpu cores : 1 +fpu : yes +fpu_exception : yes +cpuid level : 1 +wp : yes +flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm cr8_legacy +bogomips : 6469.52 +TLB size : 1024 4K pages +clflush size : 64 +cache_alignment : 64 +address sizes : 40 bits physical, 48 bits virtual +power management: ts fid vid ttp tm stc + +processor : 1 +vendor_id : AuthenticAMD +cpu family : 15 +model : 67 +model name : AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ +stepping : 2 +cpu MHz : 2600.000 +cache size : 1024 KB +physical id : 1 +siblings : 1 +core id : 0 +cpu cores : 1 +fpu : yes +fpu_exception : yes +cpuid level : 1 +wp : yes +flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm cr8_legacy +bogomips : 6469.52 +TLB size : 1024 4K pages +clflush size : 64 +cache_alignment : 64 +address sizes : 40 bits physical, 48 bits virtual +power management: ts fid vid ttp tm stc diff --git a/tests/xencapsdata/xen-x86_64-hvm.xml b/tests/xencapsdata/xen-x86_64-hvm.xml new file mode 100644 index 0000000000..b8bb2b7571 --- /dev/null +++ b/tests/xencapsdata/xen-x86_64-hvm.xml @@ -0,0 +1,50 @@ + + + + x86_64 + + + + + + + + xen + + 64 + + + + + + + + hvm + + 32 + + /usr/lib/xen/bin/qemu-dm + pc + isapc + /usr/lib/xen/boot/hvmloader + + + + + + + + + hvm + + 64 + + /usr/lib64/xen/bin/qemu-dm + pc + isapc + /usr/lib/xen/boot/hvmloader + + + + + diff --git a/tests/xencapsdata/xen-x86_64.caps b/tests/xencapsdata/xen-x86_64.caps new file mode 100644 index 0000000000..d627a0eed1 --- /dev/null +++ b/tests/xencapsdata/xen-x86_64.caps @@ -0,0 +1 @@ +xen-3.0-x86_64 diff --git a/tests/xencapsdata/xen-x86_64.cpuinfo b/tests/xencapsdata/xen-x86_64.cpuinfo new file mode 100644 index 0000000000..1beedd2eb2 --- /dev/null +++ b/tests/xencapsdata/xen-x86_64.cpuinfo @@ -0,0 +1,47 @@ +processor : 0 +vendor_id : AuthenticAMD +cpu family : 15 +model : 67 +model name : AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ +stepping : 2 +cpu MHz : 2600.000 +cache size : 1024 KB +physical id : 0 +siblings : 1 +core id : 0 +cpu cores : 1 +fpu : yes +fpu_exception : yes +cpuid level : 1 +wp : yes +flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm cr8_legacy +bogomips : 6469.52 +TLB size : 1024 4K pages +clflush size : 64 +cache_alignment : 64 +address sizes : 40 bits physical, 48 bits virtual +power management: ts fid vid ttp tm stc + +processor : 1 +vendor_id : AuthenticAMD +cpu family : 15 +model : 67 +model name : AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ +stepping : 2 +cpu MHz : 2600.000 +cache size : 1024 KB +physical id : 1 +siblings : 1 +core id : 0 +cpu cores : 1 +fpu : yes +fpu_exception : yes +cpuid level : 1 +wp : yes +flags : fpu tsc msr pae mce cx8 apic mtrr mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm cr8_legacy +bogomips : 6469.52 +TLB size : 1024 4K pages +clflush size : 64 +cache_alignment : 64 +address sizes : 40 bits physical, 48 bits virtual +power management: ts fid vid ttp tm stc diff --git a/tests/xencapsdata/xen-x86_64.xml b/tests/xencapsdata/xen-x86_64.xml new file mode 100644 index 0000000000..85bd10f5a3 --- /dev/null +++ b/tests/xencapsdata/xen-x86_64.xml @@ -0,0 +1,20 @@ + + + + x86_64 + + + + + + + + xen + + 64 + + + + + + diff --git a/tests/xencapstest.c b/tests/xencapstest.c new file mode 100644 index 0000000000..ecdea0ecf7 --- /dev/null +++ b/tests/xencapstest.c @@ -0,0 +1,199 @@ +#include +#include + +#include "xml.h" +#include "testutils.h" +#include "internal.h" +#include "xen_internal.h" + +static char *progname; + +#define MAX_FILE 4096 + +static int testCompareFiles(const char *hostmachine, + const char *xml, + const char *cpuinfo, + const char *capabilities) { + char xmlData[MAX_FILE]; + char *expectxml = &(xmlData[0]); + char *actualxml = NULL; + FILE *fp1 = NULL, *fp2 = NULL; + + int ret = -1; + + if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0) + goto fail; + + if (!(fp1 = fopen(cpuinfo, "r"))) + goto fail; + + if (!(fp2 = fopen(capabilities, "r"))) + goto fail; + + if (!(actualxml = xenHypervisorMakeCapabilitiesXML(NULL, hostmachine, fp1, fp2))) + goto fail; + + if (getenv("DEBUG_TESTS")) { + printf("Expect %d '%s'\n", (int)strlen(expectxml), expectxml); + printf("Actual %d '%s'\n", (int)strlen(actualxml), actualxml); + } + if (strcmp(expectxml, actualxml)) + goto fail; + + ret = 0; + + fail: + + if (actualxml) + free(actualxml); + if (fp1) + fclose(fp1); + if (fp2) + fclose(fp2); + + return ret; +} + +static int testXeni686(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("i686", + "xencapsdata/xen-i686.xml", + "xencapsdata/xen-i686.cpuinfo", + "xencapsdata/xen-i686.caps"); +} + +static int testXeni686PAE(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("i686", + "xencapsdata/xen-i686-pae.xml", + "xencapsdata/xen-i686-pae.cpuinfo", + "xencapsdata/xen-i686-pae.caps"); +} + +static int testXeni686PAEHVM(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("i686", + "xencapsdata/xen-i686-pae-hvm.xml", + "xencapsdata/xen-i686-pae-hvm.cpuinfo", + "xencapsdata/xen-i686-pae-hvm.caps"); +} + +/* No PAE + HVM is non-sensical - all VMX capable + CPUs have PAE */ +/* +static int testXeni686HVM(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("i686", + "xencapsdata/xen-i686-hvm.xml", + "xencapsdata/xen-i686.cpuinfo", + "xencapsdata/xen-i686-hvm.caps"); +} +*/ + +static int testXenx86_64(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("x86_64", + "xencapsdata/xen-x86_64.xml", + "xencapsdata/xen-x86_64.cpuinfo", + "xencapsdata/xen-x86_64.caps"); +} +static int testXenx86_64HVM(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("x86_64", + "xencapsdata/xen-x86_64-hvm.xml", + "xencapsdata/xen-x86_64-hvm.cpuinfo", + "xencapsdata/xen-x86_64-hvm.caps"); +} + +static int testXenia64(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("ia64", + "xencapsdata/xen-ia64.xml", + "xencapsdata/xen-ia64.cpuinfo", + "xencapsdata/xen-ia64.caps"); +} +static int testXenia64BE(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("ia64", + "xencapsdata/xen-ia64-be.xml", + "xencapsdata/xen-ia64-be.cpuinfo", + "xencapsdata/xen-ia64-be.caps"); +} + +static int testXenia64HVM(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("ia64", + "xencapsdata/xen-ia64-hvm.xml", + "xencapsdata/xen-ia64-hvm.cpuinfo", + "xencapsdata/xen-ia64-hvm.caps"); +} +static int testXenia64BEHVM(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("ia64", + "xencapsdata/xen-ia64-be-hvm.xml", + "xencapsdata/xen-ia64-be-hvm.cpuinfo", + "xencapsdata/xen-ia64-be-hvm.caps"); +} + +static int testXenppc64(void *data ATTRIBUTE_UNUSED) { + return testCompareFiles("ppc64", + "xencapsdata/xen-ppc64.xml", + "xencapsdata/xen-ppc64.cpuinfo", + "xencapsdata/xen-ppc64.caps"); +} + + +int +main(int argc, char **argv) +{ + int ret = 0; + + progname = argv[0]; + + if (argc > 1) { + fprintf(stderr, "Usage: %s\n", progname); + exit(EXIT_FAILURE); + } + + virInitialize(); + + if (virtTestRun("Capabilities for i686, no PAE, no HVM", + 1, testXeni686, NULL) != 0) + ret = -1; + + if (virtTestRun("Capabilities for i686, PAE, no HVM", + 1, testXeni686PAE, NULL) != 0) + ret = -1; + + /* No PAE + HVM is non-sensical - all VMX capable + CPUs have PAE */ + /*if (virtTestRun("Capabilities for i686, no PAE, HVM", + 1, testXeni686HVM, NULL) != 0) + ret = -1; + */ + + if (virtTestRun("Capabilities for i686, PAE, HVM", + 1, testXeni686PAEHVM, NULL) != 0) + ret = -1; + + if (virtTestRun("Capabilities for x86_64, no HVM", + 1, testXenx86_64, NULL) != 0) + ret = -1; + + if (virtTestRun("Capabilities for x86_64, HVM", + 1, testXenx86_64HVM, NULL) != 0) + ret = -1; + + if (virtTestRun("Capabilities for ia64, no HVM, LE", + 1, testXenia64, NULL) != 0) + ret = -1; + + if (virtTestRun("Capabilities for ia64, HVM, LE", + 1, testXenia64HVM, NULL) != 0) + ret = -1; + + if (virtTestRun("Capabilities for ia64, no HVM, BE", + 1, testXenia64BE, NULL) != 0) + ret = -1; + + if (virtTestRun("Capabilities for ia64, HVM, BE", + 1, testXenia64BEHVM, NULL) != 0) + ret = -1; + + if (virtTestRun("Capabilities for ppc64", + 1, testXenppc64, NULL) != 0) + ret = -1; + + + exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); +}