From nobody Wed May 14 13:31:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524044351067392.24802267618475; Wed, 18 Apr 2018 02:39:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5A2331500A6; Wed, 18 Apr 2018 09:39:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75F536A240; Wed, 18 Apr 2018 09:39:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2B9374CAA0; Wed, 18 Apr 2018 09:39:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3I9csYf022455 for ; Wed, 18 Apr 2018 05:38:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id B7E4D2023229; Wed, 18 Apr 2018 09:38:54 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E8532023227; Wed, 18 Apr 2018 09:38:54 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 18 Apr 2018 11:38:41 +0200 Message-Id: <31234b3d8e4d4a95a3d4b53cd95544ff9c661f0d.1524043990.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 1/7] tests: qemu: Add helper code to lookup most recent capability file X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 18 Apr 2018 09:39:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D 0; i < 3; i++) { + rc =3D strlen(cur[i]) - strlen(max[i]); + + if (rc > 0) + return true; + + if (rc < 0) + return false; + + rc =3D 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 =3D NULL; + char *ret =3D NULL; + const char *tmp; + char **max =3D NULL; + size_t nmax =3D 0; + const char *maxname =3D NULL; + char **cur =3D NULL; + size_t ncur =3D 0; + + if (virDirOpen(&dir, dirname) < 0) + goto cleanup; + + while ((rc =3D virDirRead(dir, &ent, dirname)) > 0) { + virStringListFreeCount(cur, ncur); + cur =3D NULL; + ncur =3D 0; + + if (!(tmp =3D STRSKIP(ent->d_name, "caps_"))) + continue; + + if (!strstr(tmp, suffix) || !strstr(tmp, arch)) + continue; + + if (!(cur =3D virStringSplitCount(tmp, ".", 4, &ncur))) + goto cleanup; + + if (ncur !=3D 4) { + VIR_TEST_DEBUG("skipping caps file '%s'\n", ent->d_name); + continue; + } + + if (!max || testQemuCapsIsNewerVersion(cur, max)) { + VIR_STEAL_PTR(max, cur); + maxname =3D ent->d_name; + nmax =3D ncur; + ncur =3D 0; + } + } + + if (rc < 0) + goto cleanup; + + if (!maxname) { + VIR_TEST_VERBOSE("failed to find capabilities for '%s' in '%s'\n", + arch, dirname); + goto cleanup; + } + + ignore_value(virAsprintf(&ret, "%s/%s", dirname, maxname)); + + cleanup: + virStringListFreeCount(max, nmax); + virStringListFreeCount(cur, ncur); + virDirClose(&dir); + return ret; +} diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 7ae8324933..6490db4b95 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -39,4 +39,9 @@ int qemuTestCapsCacheInsert(virFileCachePtr cache, int testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps, int gic); + +char *testQemuGetNewestCapsForArch(const char *dirname, + const char *arch, + const char *suffix); + #endif --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list