]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virschematest: Improve testing schemas in 'tests/cputestdata'
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Oct 2020 10:01:29 +0000 (12:01 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 3 Nov 2022 08:19:54 +0000 (09:19 +0100)
The 'cputestdata' directory has a collection of XML files with very
complicated naming schemes for various input and output XML files.

Rather than trying to write complex regexes for selecting specific files
which diverged already multiple times we can introduce an internal
schema file which will cover all of the 3 top level elements used in the
XML files.

Schema for <cpu> is taken from our main RNG schema, <cpuTest> is just a
collection of <cpu> elements, and finally <cpudata> is a simple enough
to describe inline.

To keep the validator happy we have to generate the schema file to
place full paths for the included documents.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/meson.build
tests/schemas/cpu-baseline.rng.in [new file with mode: 0644]
tests/schemas/meson.build [new file with mode: 0644]
tests/virschematest.c

index 114921175639c6c88252c3e1f12194ab5d94d39b..3365dce3077f4f00181e798a3c2753eb8ad1a410 100644 (file)
@@ -208,6 +208,7 @@ tests_deps += executable(
   ],
 )
 
+subdir('schemas')
 
 # build and define libvirt tests
 
diff --git a/tests/schemas/cpu-baseline.rng.in b/tests/schemas/cpu-baseline.rng.in
new file mode 100644 (file)
index 0000000..1a3b19a
--- /dev/null
@@ -0,0 +1,84 @@
+<?xml version="1.0"?>
+<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+  <include href="@SCHEMADIR@/basictypes.rng"/>
+  <include href="@SCHEMADIR@/cputypes.rng"/>
+
+  <start>
+    <ref name="cputestdata"/>
+  </start>
+
+  <define name="cputestdata">
+    <choice>
+      <ref name="guestcpu"/>
+      <ref name="hostcpu"/>
+      <ref name="cputest"/>
+      <ref name="cpudata"/>
+    </choice>
+  </define>
+
+  <define name="cputest">
+    <element name="cpuTest">
+      <oneOrMore>
+        <choice>
+          <ref name="guestcpu"/>
+          <ref name="hostcpu"/>
+        </choice>
+      </oneOrMore>
+    </element>
+  </define>
+
+  <define name="cpudata">
+    <element name="cpudata">
+      <attribute name="arch">
+        <choice>
+          <value>x86</value>
+        </choice>
+      </attribute>
+      <interleave>
+        <oneOrMore>
+          <ref name="cpudata_cpuid"/>
+        </oneOrMore>
+        <zeroOrMore>
+          <ref name="cpudata_msr"/>
+        </zeroOrMore>
+      </interleave>
+    </element>
+  </define>
+
+  <define name="cpudata_cpuid">
+    <element name="cpuid">
+      <attribute name="eax_in">
+        <ref name="hexuint"/>
+      </attribute>
+      <attribute name="ecx_in">
+        <ref name="hexuint"/>
+      </attribute>
+      <attribute name="eax">
+        <ref name="hexuint"/>
+      </attribute>
+      <attribute name="ebx">
+        <ref name="hexuint"/>
+      </attribute>
+      <attribute name="ecx">
+        <ref name="hexuint"/>
+      </attribute>
+      <attribute name="edx">
+        <ref name="hexuint"/>
+      </attribute>
+    </element>
+  </define>
+
+  <define name="cpudata_msr">
+    <element name="msr">
+      <attribute name="index">
+        <ref name="hexuint"/>
+      </attribute>
+      <attribute name="eax">
+        <ref name="hexuint"/>
+      </attribute>
+      <attribute name="edx">
+        <ref name="hexuint"/>
+      </attribute>
+    </element>
+  </define>
+</grammar>
diff --git a/tests/schemas/meson.build b/tests/schemas/meson.build
new file mode 100644 (file)
index 0000000..33c16bb
--- /dev/null
@@ -0,0 +1,16 @@
+# we need to replace proper paths to our schemas in the test schemas
+virschematest_test_schemas_conf = configuration_data({
+  'SCHEMADIR': meson.project_source_root() / 'src' / 'conf' / 'schemas',
+})
+
+virschematest_schemas = [
+  'cpu-baseline.rng.in',
+]
+
+foreach file : virschematest_schemas
+  configure_file(
+    input: file,
+    output: '@BASENAME@',
+    configuration: virschematest_test_schemas_conf,
+  )
+endforeach
index 2a89f6a1c04279eb6a6c4fc0903c3726d3896860..29a1d5913433031e8c61546794c00dca430f64d3 100644 (file)
@@ -318,13 +318,8 @@ static const struct testSchemaEntry schemaStorageVol[] = {
     { .file = "examples/xml/test/testvol.xml" },
 };
 
-static const struct testSchemaEntry schemaCpu[] = {
-    { . dir = "tests/cputestdata",
-      . dirRegex = "^[^-]+-cpuid-.*(-host|-guest|-json)\\.xml$" },
-    { . dir = "tests/cputestdata",
-      . dirRegex = "^[^-]+-baseline-.*-result\\.xml$" },
-    { . dir = "tests/cputestdata",
-      . dirRegex = "^[^-]+-(?!cpuid|baseline).*$" },
+static const struct testSchemaEntry testsCpuBaseline[] = {
+    { . dir = "tests/cputestdata" },
 };
 
 static int
@@ -333,6 +328,7 @@ mymain(void)
     int ret = 0;
 
 #define SCHEMAS_PATH abs_top_srcdir "/src/conf/schemas/"
+#define INTERNAL_SCHEMAS_PATH abs_builddir "/schemas/"
 
 #define DO_TEST(sch, ent) \
     if (testSchemaEntries((sch), (ent), G_N_ELEMENTS(ent)) < 0) \
@@ -354,7 +350,8 @@ mymain(void)
     DO_TEST(SCHEMAS_PATH "storagepoolcaps.rng", schemaStoragepoolcaps);
     DO_TEST(SCHEMAS_PATH "storagepool.rng", schemaStoragePool);
     DO_TEST(SCHEMAS_PATH "storagevol.rng", schemaStorageVol);
-    DO_TEST(SCHEMAS_PATH "cpu.rng", schemaCpu);
+
+    DO_TEST(INTERNAL_SCHEMAS_PATH "cpu-baseline.rng", testsCpuBaseline);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }