From nobody Mon Feb 9 04:15:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1601898597; cv=none; d=zohomail.com; s=zohoarc; b=Bn5nnlOTFOhcdauZI/3TIpA895w7OHioFZNJbRhtMcdZIGDASs5XwfP+/AvnJlYXNSoLfYz/7Pp7fN2pChHcGWU+AnwWjhTsoQbaNzLDGv5+gX7A5V705W6SEdc3Haau9cob+p6cAi+YF7tQdTaCwrHzI5BtkyadXJLCMNMjMbw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601898597; 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=gkD+SQjcAlQdZMH8l0MtLF5GwuWLAHtQV0KpwbTaXbE=; b=P+WXbbhGtvVc1Cx41ldICmrVcChT+wNm5akPB4jNGKpWxpMO2b0ft3yPPe5xbl9Ui2ycAV/WZOvJLb8yJ4d1KR8pjfQMspzmO5T/dUB8CBCqjIaMLABzCnUy+ix1k4WoB9Iva7SwuRLip7CtbMCD2idePHL1RUZxs+HLOUls1m0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601898597273697.642493596538; Mon, 5 Oct 2020 04:49:57 -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-593-etiZ8WlhMAaPNpL5mCVRGQ-1; Mon, 05 Oct 2020 07:49:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C174801AE1; Mon, 5 Oct 2020 11:49:47 +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 E3E675C1BD; Mon, 5 Oct 2020 11:49:46 +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 A51DC44A5F; Mon, 5 Oct 2020 11:49:46 +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 095BngEn028069 for ; Mon, 5 Oct 2020 07:49:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD92A19C4F; Mon, 5 Oct 2020 11:49:42 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CABD277CF for ; Mon, 5 Oct 2020 11:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601898595; 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=gkD+SQjcAlQdZMH8l0MtLF5GwuWLAHtQV0KpwbTaXbE=; b=LbHwVpcF5KXJshlN9Cv4vUa7yd4FSEZ4ZC4gKqL9OQ8oXom5DiRFTgOzEGbE5k790p/CBx 8QCHFkLMSOXrTjynl8I9MZpooH7q53Rbpa9MZycj1ACfGUjszPsPVs7/zIvPJB9vZtH5xz csZq8fM80LQdxN0zP/4HMGmEHL1rxx4= X-MC-Unique: etiZ8WlhMAaPNpL5mCVRGQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 4/7] virbitmaptest: Turn 'TEST_MAP' macro into a helper function Date: Mon, 5 Oct 2020 13:49:26 +0200 Message-Id: <815ed58426644ec8f22807606a82f6dfc88bf3d8.1601898456.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.16 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) Content-Type: text/plain; charset="utf-8" The function will also be reusable in other places of the code by making the size check optional. For now only test12* is refactored since it used TEST_MAP directly. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virbitmaptest.c | 63 +++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index dc23431645..c16be62e23 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -26,6 +26,31 @@ #include "virbitmap.h" + +static int +checkBitmap(virBitmapPtr map, + const char *expect, + ssize_t expectedSize) +{ + g_autofree char *actual =3D virBitmapFormat(map); + + if (expectedSize !=3D -1 && + virBitmapSize(map) !=3D expectedSize) { + fprintf(stderr, "\n expected bitmap size: '%zd' actual size: " + "'%zu'\n", expectedSize, virBitmapSize(map)); + return -1; + } + + if (STRNEQ_NULLABLE(expect, actual)) { + fprintf(stderr, "\n expected bitmap contents '%s' actual contents = "\ + "'%s'\n", NULLSTR(expect), NULLSTR(actual)); + return -1; + } + + return 0; +} + + static int test1(const void *data G_GNUC_UNUSED) { @@ -630,25 +655,6 @@ test11(const void *opaque) return ret; } -#define TEST_MAP(sz, expect) \ - do { \ - char *actual; \ - if (virBitmapSize(map) !=3D sz) { \ - fprintf(stderr, "\n expected bitmap size: '%d' actual size: " \ - "'%zu'\n", sz, virBitmapSize(map)); \ - goto cleanup; \ - } \ - \ - actual =3D virBitmapFormat(map); \ - \ - if (STRNEQ_NULLABLE(expect, actual)) { \ - fprintf(stderr, "\n expected bitmap contents '%s' actual conte= nts "\ - "'%s'\n", NULLSTR(expect), NULLSTR(actual)); \ - VIR_FREE(actual); \ - goto cleanup; \ - } \ - VIR_FREE(actual); \ - } while (0) /* test self-expanding bitmap APIs */ static int @@ -657,17 +663,20 @@ test12a(const void *opaque G_GNUC_UNUSED) virBitmapPtr map =3D virBitmapNewEmpty(); int ret =3D -1; - TEST_MAP(0, ""); + if (checkBitmap(map, "", 0) < 0) + goto cleanup; if (virBitmapSetBitExpand(map, 128) < 0) goto cleanup; - TEST_MAP(129, "128"); + if (checkBitmap(map, "128", 129) < 0) + goto cleanup; if (virBitmapClearBitExpand(map, 150) < 0) goto cleanup; - TEST_MAP(151, "128"); + if (checkBitmap(map, "128", 151) < 0) + goto cleanup; ret =3D 0; @@ -686,13 +695,16 @@ test12b(const void *opaque G_GNUC_UNUSED) if (!(map =3D virBitmapParseUnlimited("34,1023"))) goto cleanup; - TEST_MAP(1024, "34,1023"); + if (checkBitmap(map, "34,1023", 1024) < 0) + goto cleanup; virBitmapShrink(map, 35); - TEST_MAP(35, "34"); + if (checkBitmap(map, "34", 35) < 0) + goto cleanup; virBitmapShrink(map, 34); - TEST_MAP(34, ""); + if (checkBitmap(map, "", 34) < 0) + goto cleanup; ret =3D 0; @@ -729,7 +741,6 @@ test13(const void *opaque G_GNUC_UNUSED) return 0; } -#undef TEST_MAP static int test14(const void *opaque) --=20 2.26.2