tests: Add support for multiple variants of data for the same qemu version+architecture

'qemucapabilitiestest' and other users of the capability data can
benefit from adding a discriminator string to have multiple instances
for the same version+architecture tuple.

This will in the future allow us to have specific capability versions
for test cases which require a specific host feature or are based on a
different operating system.

Add the basic skeleton for parsing the variant string and passing it
around into test cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-03-08 14:49:56 +01:00
parent 36a735c553
commit 2102a31bc2
7 changed files with 55 additions and 11 deletions

View File

@ -312,11 +312,16 @@ doTestQemu(const char *inputDir G_GNUC_UNUSED,
const char *prefix G_GNUC_UNUSED,
const char *version,
const char *arch,
const char *variant,
const char *suffix G_GNUC_UNUSED,
void *opaque)
{
int ret = 0;
/* currently variant tests are not handled here */
if (STRNEQ(variant, ""))
return 0;
if (STREQ(arch, "x86_64")) {
/* For x86_64 we test three combinations:
*

View File

@ -22,6 +22,10 @@ Files in this directory have the following naming scheme::
caps_$QEMUVERSION_$ARCHITECTURE.$SUFFIX
or::
caps_$QEMUVERSION_$ARCHITECTURE+$VARIANT.$SUFFIX
``$QEMUVERSION``
Numeric representation of the qemu version, e.g.: ``7.0.0``
@ -35,6 +39,21 @@ Files in this directory have the following naming scheme::
``.replies`` for the dump of the QMP communication used to probe qemu.
``.xml`` for the generated capability dump
``$VARIANT``
The variant name is an optional arbitrary string, not containing any dot.
A variant is an additional named version of capabilities for given version and
architecture tuple. This allows for testing special cases which e.g. depend
on a specific host platform or operating system feature, which differs from
the main tests. Note that in the test code the variant name is an empty string
or includes the '+' sign for ease of use.
Known test variants
-------------------
This section will contain a list of variants that are used in the test suite.
Usage in tests
==============

View File

@ -221,10 +221,13 @@ iterateCapsFile(const char *inputDir,
const char *prefix,
const char *version,
const char *archName,
const char *variant,
const char *suffix,
void *opaque G_GNUC_UNUSED)
{
g_autofree char *repliesFile = g_strdup_printf("%s/%s_%s_%s.%s", inputDir, prefix, version, archName, suffix);
g_autofree char *repliesFile = g_strdup_printf("%s/%s_%s_%s%s.%s",
inputDir, prefix, version,
archName, variant, suffix);
return virTestRun(repliesFile, testCapsFile, repliesFile);
}

View File

@ -39,6 +39,7 @@ struct _testQemuData {
const char *prefix;
const char *version;
const char *archName;
const char *variant;
const char *suffix;
int ret;
};
@ -78,12 +79,12 @@ testQemuCaps(const void *opaque)
unsigned int fakeMicrocodeVersion = 0;
const char *p;
repliesFile = g_strdup_printf("%s/%s_%s_%s.%s",
repliesFile = g_strdup_printf("%s/%s_%s_%s%s.%s",
data->inputDir, data->prefix, data->version,
data->archName, data->suffix);
capsFile = g_strdup_printf("%s/%s_%s_%s.xml",
data->archName, data->variant, data->suffix);
capsFile = g_strdup_printf("%s/%s_%s_%s%s.xml",
data->outputDir, data->prefix, data->version,
data->archName);
data->archName, data->variant);
if (!(mon = qemuMonitorTestNewFromFileFull(repliesFile, &data->driver, NULL,
NULL)))
@ -142,9 +143,9 @@ testQemuCapsCopy(const void *opaque)
g_autoptr(virQEMUCaps) copy = NULL;
g_autofree char *actual = NULL;
capsFile = g_strdup_printf("%s/%s_%s_%s.xml",
capsFile = g_strdup_printf("%s/%s_%s_%s%s.xml",
data->outputDir, data->prefix, data->version,
data->archName);
data->archName, data->variant);
if (!(orig = qemuTestParseCapabilitiesArch(
virArchFromString(data->archName), capsFile)))
@ -167,6 +168,7 @@ doCapsTest(const char *inputDir,
const char *prefix,
const char *version,
const char *archName,
const char *variant,
const char *suffix,
void *opaque)
{
@ -181,6 +183,7 @@ doCapsTest(const char *inputDir,
data->prefix = prefix;
data->version = version;
data->archName = archName;
data->variant = variant,
data->suffix = suffix;
if (virTestRun(title, testQemuCaps, data) < 0)

View File

@ -33,6 +33,7 @@ struct _testQemuData {
const char *prefix;
const char *version;
const char *archName;
const char *variant;
const char *suffix;
int ret;
};
@ -122,11 +123,11 @@ testQemuCapsXML(const void *opaque)
g_autofree char *capsXml = NULL;
g_autoptr(virCaps) capsProvided = NULL;
xmlFile = g_strdup_printf("%s/caps.%s.xml", data->outputDir, data->archName);
xmlFile = g_strdup_printf("%s/caps.%s%s.xml", data->outputDir, data->archName, data->variant);
capsFile = g_strdup_printf("%s/%s_%s_%s.%s",
capsFile = g_strdup_printf("%s/%s_%s_%s%s.%s",
data->inputDir, data->prefix, data->version,
data->archName, data->suffix);
data->archName, data->variant, data->suffix);
if (virTestLoadFile(capsFile, &capsData) < 0)
return -1;
@ -149,6 +150,7 @@ doCapsTest(const char *inputDir,
const char *prefix,
const char *version,
const char *archName,
const char *variant,
const char *suffix,
void *opaque)
{
@ -161,6 +163,7 @@ doCapsTest(const char *inputDir,
data->prefix = prefix;
data->version = version;
data->archName = archName;
data->variant = variant;
data->suffix = suffix;
if (virTestRun(title, testQemuCapsXML, data) < 0)

View File

@ -834,6 +834,8 @@ testQemuCapsIterate(const char *suffix,
g_autofree char *tmp = g_strdup(ent->d_name);
char *version = NULL;
char *archName = NULL;
g_autofree char *variant = NULL;
char *var;
/* Strip the trailing suffix, moving on if it's not present */
if (!virStringStripSuffix(tmp, suffix))
@ -857,6 +859,14 @@ testQemuCapsIterate(const char *suffix,
archName[0] = '\0';
archName++;
/* Find the 'variant' of the test and split it including the leading '+' */
if ((var = strchr(archName, '+'))) {
variant = g_strdup(var);
var[0] = '\0';
} else {
variant = g_strdup("");
}
/* Run the user-provided callback.
*
* We skip the dot that, as verified earlier, starts the suffix
@ -864,7 +874,7 @@ testQemuCapsIterate(const char *suffix,
* the callback.
*/
if (callback(TEST_QEMU_CAPS_PATH, "caps", version,
archName, suffix + 1, opaque) < 0)
archName, variant, suffix + 1, opaque) < 0)
fail = true;
}

View File

@ -143,6 +143,7 @@ typedef int (*testQemuCapsIterateCallback)(const char *inputDir,
const char *prefix,
const char *version,
const char *archName,
const char *variant,
const char *suffix,
void *opaque);
int testQemuCapsIterate(const char *suffix,