From nobody Mon Feb 9 06:34:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631177459; cv=none; d=zohomail.com; s=zohoarc; b=BjrTm10jyrRfQbzKrWJ6pQvEo8DF7Mieth40e3qCAgVvbxXBy6Ko/ml1JWAtGWDjOz3qD0UtRbgV57z/P+kwuExFxWnGb0p34Ai8O2CwVdPjSmPHr7dkh8xm3DFaEZ4uom2gYU/AWcK5AXCNi3A6x6oJ16uNWw5gRqNqJpdqE/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631177459; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=q8pNWu/+42wHdBIPhDcSiXmb+l7hC0VlzxIMR19RKgQ=; b=ldowd+qoRsL3kdddb56RJ8/6cLyqfVTXeGJaoXxN282mDYakxATPkSz8bQt/VIiMizvid37RZ/wzvY/RhxE1PSfytMmudZoH+z7oMLhwIjAu5+Ji9Ct0eX/4C6V1hxfA5QR0zrjXMy3qN85kiPln504ZaZUgEN24UZ+CY1fX6HY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631177459002885.9702273675002; Thu, 9 Sep 2021 01:50:59 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-526-M_eIG6OMPdu5R1Tx-5Q_ZA-1; Thu, 09 Sep 2021 04:50:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B42DC18A0745; Thu, 9 Sep 2021 08:50:49 +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 95CF25453A; Thu, 9 Sep 2021 08:50:49 +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 16AF54EA3A; Thu, 9 Sep 2021 08:50:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1898oj7T030837 for ; Thu, 9 Sep 2021 04:50:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id E7EE91A26A; Thu, 9 Sep 2021 08:50:44 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 498F526DFF for ; Thu, 9 Sep 2021 08:50:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631177457; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=q8pNWu/+42wHdBIPhDcSiXmb+l7hC0VlzxIMR19RKgQ=; b=YwUbr8BTlruJ8RSoXhZ7dqx4mJAFZOSxQrnysA9HzY01Y4ZklN+Rp3VZABvhliq+MaL1wm 8lt2fO4MwUU8828Pro6agybwW6dqJr2raAUjs5VQ0zMfrS5ddiaw7orhJ5trqFKTYE2yAv uVPz7afWUZX9OiojsvsD0cpNvzWMSLo= X-MC-Unique: M_eIG6OMPdu5R1Tx-5Q_ZA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 22/24] virstoragetest: Don't skip the whole test when qemu-img fails to format images Date: Thu, 9 Sep 2021 10:49:22 +0200 Message-Id: <2c1f4730c72ae577787d0adc0346ced678753464.1631177237.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631177460480100002 Content-Type: text/plain; charset="utf-8" We have plenty of other work to do in this test. Skip only the real image testing case when we can't find qemu-img or it failed to format the image. This allows us to also remove the last global variable in the test and move the creation and cleanup of the images closer to the actual test. Signed-off-by: Peter Krempa --- tests/virstoragetest.c | 73 ++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index d9ab630600..bbeb5ecd88 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -37,13 +37,9 @@ VIR_LOG_INIT("tests.storagetest"); #define datadir abs_builddir "/virstoragedata" -static char *abswrap; - static void testCleanupImages(void) { - VIR_FREE(abswrap); - if (chdir(abs_builddir) < 0) { fprintf(stderr, "unable to return to correct directory, refusing t= o " "clean up %s\n", datadir); @@ -82,75 +78,60 @@ testStorageFileGetMetadata(const char *path, return g_steal_pointer(&def); } -static int +static char * testPrepImages(void) { - int ret =3D EXIT_FAILURE; g_autoptr(virCommand) cmdraw =3D NULL; g_autoptr(virCommand) cmdqcow2 =3D NULL; g_autoptr(virCommand) cmdwrap =3D NULL; g_autofree char *absraw =3D g_strdup_printf("%s/raw", datadir); g_autofree char *absqcow2 =3D g_strdup_printf("%s/qcow2", datadir); + g_autofree char *abswrap =3D g_strdup_printf("%s/wrap", datadir); g_autofree char *qemuimg =3D virFindFileInPath("qemu-img"); if (!qemuimg) - goto skip; + return NULL; /* Clean up from any earlier failed tests */ virFileDeleteTree(datadir); - abswrap =3D g_strdup_printf("%s/wrap", datadir); - if (g_mkdir_with_parents(datadir, 0777) < 0) { - fprintf(stderr, "unable to create directory %s\n", datadir); - goto cleanup; - } - - if (chdir(datadir) < 0) { - fprintf(stderr, "unable to test relative backing chains\n"); - goto cleanup; + VIR_TEST_VERBOSE("unable to create directory '%s'\n", datadir); + return NULL; } + /* create the folowing real backing chain with qcow2 images with absol= ute + * backing and different qcow2 versions: + * datadir/raw <- datadir/qcow2 (qcow2v2) <- datadir/wrap (qcow2v3) */ cmdraw =3D virCommandNewArgList(qemuimg, "create", "-f", "raw", absraw, "1k", NULL); - if (virCommandRun(cmdraw, NULL) < 0) - goto skip; - /* Create a qcow2 wrapping relative raw; later on, we modify its - * metadata to test other configurations */ cmdqcow2 =3D virCommandNewArgList(qemuimg, "create", "-f", "qcow2", "-F", "raw", "-b", absraw, "-o", "compat=3D0.10", absqcow2, NULL); - if (virCommandRun(cmdqcow2, NULL) < 0) - goto skip; - /* Create a second qcow2 wrapping the first, to be sure that we - * can correctly avoid insecure probing. */ cmdwrap =3D virCommandNewArgList(qemuimg, "create", "-f", "qcow2", "-F", "qcow2", "-b", absqcow2, "-o", "compat=3D1.1", abswrap, NULL); - if (virCommandRun(cmdwrap, NULL) < 0) - goto skip; - ret =3D 0; - cleanup: - if (ret) - testCleanupImages(); - return ret; + if (virCommandRun(cmdraw, NULL) < 0 || + virCommandRun(cmdqcow2, NULL) < 0 || + virCommandRun(cmdwrap, NULL) < 0) { + VIR_TEST_VERBOSE("failed to create backing chain in '%s'\n", datad= ir); + return NULL; + } - skip: - fputs("qemu-img is too old; skipping this test\n", stderr); - ret =3D EXIT_AM_SKIP; - goto cleanup; + return g_steal_pointer(&abswrap); } + enum { EXP_PASS =3D 0, EXP_FAIL =3D 1, @@ -432,11 +413,12 @@ testBackingParse(const void *args) static int mymain(void) { - int ret; + int ret =3D 0; struct testChainData data; struct testLookupData data2; struct testPathRelativeBacking data4; struct testBackingParseData data5; + g_autofree char *realchain =3D NULL; virStorageSource fakeChain[4]; virStorageSource *chain =3D &fakeChain[0]; virStorageSource *chain2 =3D &fakeChain[1]; @@ -445,11 +427,6 @@ mymain(void) if (storageRegisterAll() < 0) return EXIT_FAILURE; - /* Prep some files with qemu-img; if that is not found on PATH, or - * if it lacks support for qcow2 and qed, skip this test. */ - if ((ret =3D testPrepImages()) !=3D 0) - return ret; - #define TEST_CHAIN(testname, start, format, flags) \ do { \ data =3D (struct testChainData){ testname, start, format, flags };= \ @@ -477,8 +454,15 @@ mymain(void) VIR_STORAGE_FILE_AUTO, EXP_PASS); /* qcow2 chain with absolute backing formatted with a real qemu-img */ - TEST_CHAIN("qcow2-qcow2_qcow2-qcow2_raw-raw", abswrap, VIR_STORAGE_FIL= E_QCOW2, EXP_PASS); - TEST_CHAIN("qcow2-auto_qcow2-qcow2_raw-raw", abswrap, VIR_STORAGE_FILE= _AUTO, EXP_PASS); + + /* Prep some files with qemu-img; if that is not found on PATH, the te= st + * using the data skips itself if the data can't be prepared */ + realchain =3D testPrepImages(); + + TEST_CHAIN("qcow2-qcow2_qcow2-qcow2_raw-raw", realchain, VIR_STORAGE_F= ILE_QCOW2, EXP_PASS); + TEST_CHAIN("qcow2-auto_qcow2-qcow2_raw-raw", realchain, VIR_STORAGE_FI= LE_AUTO, EXP_PASS); + + testCleanupImages(); /* Qcow2 file with missing backing file but specified type */ TEST_CHAIN("qcow2-qcow2_missing", @@ -1188,9 +1172,6 @@ mymain(void) #endif /* WITH_YAJL */ cleanup: - /* Final cleanup */ - testCleanupImages(); - return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.31.1