Re: [PATCH v2 1/7] tests: qemu: Add helper code to lookup most recent capability file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 18, 2018 at 12:53:55 +0200, Ján Tomko wrote:
> On Wed, Apr 18, 2018 at 11:38:41AM +0200, Peter Krempa wrote:
> > The helper iterates the directory with files for the capability test and
> > looks up the most recent one for the given architecture. This will allow
> > testing against the newest qemu capabilities so that we can catch
> > regressions in behaviour more easily.
> > 
> > Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
> > ---
> > tests/testutilsqemu.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
> > tests/testutilsqemu.h |  5 +++
> > 2 files changed, 99 insertions(+)
> > 
> > diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
> > index 9671a46f12..9dbcee6e3b 100644
> > --- a/tests/testutilsqemu.c
> > +++ b/tests/testutilsqemu.c
> > @@ -674,3 +674,97 @@ testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps,
> > }
> > 
> > #endif
> > +
> > +
> > +static bool
> > +testQemuCapsIsNewerVersion(char **cur,
> > +                           char **max)
> > +{
> > +    size_t i;
> > +    int rc;
> > +
> > +    for (i = 0; i < 3; i++) {
> > +        rc = strlen(cur[i]) - strlen(max[i]);
> > +
> > +        if (rc > 0)
> > +            return true;
> > +
> > +        if (rc < 0)
> > +            return false;
> > +
> > +        rc = strcmp(cur[i], max[i]);
> > +
> > +        if (rc > 0)
> > +            return true;
> > +
> > +        if (rc < 0)
> > +            return false;
> > +    }
> > +
> > +    return false;
> > +}
> > +
> > +
> > +char *
> > +testQemuGetNewestCapsForArch(const char *dirname,
> > +                             const char *arch,
> > +                             const char *suffix)
> > +{
> > +    struct dirent *ent;
> > +    int rc;
> > +    DIR *dir = NULL;
> > +    char *ret = NULL;
> > +    const char *tmp;
> > +    char **max = NULL;
> > +    size_t nmax = 0;
> > +    const char *maxname = NULL;
> > +    char **cur = NULL;
> > +    size_t ncur = 0;
> > +
> > +    if (virDirOpen(&dir, dirname) < 0)
> > +        goto cleanup;
> > +
> > +    while ((rc = virDirRead(dir, &ent, dirname)) > 0) {
> > +        virStringListFreeCount(cur, ncur);
> > +        cur = NULL;
> > +        ncur = 0;
> > +
> > +        if (!(tmp = STRSKIP(ent->d_name, "caps_")))
> > +            continue;
> > +
> > +        if (!strstr(tmp, suffix) || !strstr(tmp, arch))
> > +            continue;
> > +
> 
> This helper assumes the prefix is "caps_" but leaves the suffix
> configurable.

Suffix is configurable for cases when you might want to select the
.replies file instead of the .xml file. This is planned to be used when
I'll want to replace tests/qemuqapischema.json with the newest reply
from the capabilitiestest.

On the other hand, prefix is not really going to change, and if so, it
will need to be fixed.

> You can concatenate arch and suffix into some real_suffix, then
> 1. STRDUP(tmp, STRSKIP( "caps_"))
> 2. virFileStripSuffix(tmp, real_suffix)
> 3. Either use virParseVersionString and a plain numeric comparison,
>   or import strverscmp from gnulib instead of subjecting the reader
>   to testQemuCapsIsNewerVersion.

Okay.

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux