From nobody Sun Feb 8 21:11:41 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=1629470969; cv=none; d=zohomail.com; s=zohoarc; b=Jv/jLnHxKmNTsvFUbRgm3YRltRvQV9LL94HNiiFBgAxxi3CwFFh5idMWYZHt5K6T3gLXUiyeGwYcrE9yPpUv960Ak+vX2GuA/K6LU5wNVmg3VcTMZxRyQiEMH3aN2AixJrIs9GfSa3tQ/tmuXykDPnszs0ohTNtJQ59hUyMEomU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629470969; 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=xSzPwNouP+HYX61V4Q5uEZxNnlI6afwjLOwe5tfwRx0=; b=WjTnBj+ojrJxnrzV9lML7WvL4QbVaXyQ7Romjqxh7LRiDKvPf4uTrrWVdjpUsK9bcRCN0QK/t9oBaT0jor0CN6hx5nQhuNxbQWLuQe7cNkCY2UCNmO2lX2ptu9VdXbQwBTXE/W/T0Y8Z6MF3E5WOVLVXZkvQdWz3p8GJNInBd5c= 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) 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 1629470969475722.2923606018384; Fri, 20 Aug 2021 07:49:29 -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-403-SmzZVC5DM56qBzB6bOfZew-1; Fri, 20 Aug 2021 10:49:27 -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 E8A0E8799FB; Fri, 20 Aug 2021 14:49:20 +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 CA7165F724; Fri, 20 Aug 2021 14:49:20 +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 9592A4A707; Fri, 20 Aug 2021 14:49:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KEn5i3025568 for ; Fri, 20 Aug 2021 10:49:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1AC426A901; Fri, 20 Aug 2021 14:49:05 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97DDB5D741 for ; Fri, 20 Aug 2021 14:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629470968; 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=xSzPwNouP+HYX61V4Q5uEZxNnlI6afwjLOwe5tfwRx0=; b=KeRDPXr2J3EoiL27vFZinZ95/ptfh/w6KSipkhV9yQu2MgmI83+6HuDdr9Q9NHi10DwISU By1KjpSqOxQi78/FVUu4e2AZ3oalPrP1PwYF+B7CXYU+37Zb3yKbR2iFIcBENAYGiFr/vM 0R0Wl8KturPxzGr6UDFWKE4wvMVbh4E= X-MC-Unique: SmzZVC5DM56qBzB6bOfZew-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 8/9] tests: cputests: introduce and use virTestRunLog Date: Fri, 20 Aug 2021 16:48:50 +0200 Message-Id: <13c6ec1ac0976aeb891ebdd863ef907f8921c765.1629470763.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629471090920100009 A helper that resets the log before each test and prints it on failure. It also takes the return variable as an argument, so it can be used to eliminate number of branches the compiler has to consider in the main function. Signed-off-by: J=C3=A1n Tomko --- tests/cputest.c | 14 +------------- tests/testutils.c | 30 ++++++++++++++++++++++++++++++ tests/testutils.h | 4 ++++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/tests/cputest.c b/tests/cputest.c index c8030be093..3e99b9486b 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -912,23 +912,11 @@ mymain(void) flags, result \ }; \ g_autofree char *testLabel =3D NULL; \ - \ - g_free(virTestLogContentAndReset());\ \ testLabel =3D g_strdup_printf("%s(%s): %s", #api, \ virArchToString(arch), name); \ \ - if (virTestRun(testLabel, api, &data) < 0) { \ - if (virTestGetDebug()) { \ - char *log; \ - if ((log =3D virTestLogContentAndReset()) && \ - strlen(log) > 0) \ - VIR_TEST_DEBUG("\n%s", log); \ - VIR_FREE(log); \ - } \ - ret =3D -1; \ - } \ - \ + virTestRunLog(&ret, testLabel, api, &data); \ } while (0) =20 #define DO_TEST_COMPARE(arch, host, cpu, result) \ diff --git a/tests/testutils.c b/tests/testutils.c index 682fa142b5..5e9835ee89 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -180,6 +180,36 @@ virTestRun(const char *title, } =20 =20 +/* + * A wrapper for virTestRun that resets the log content before each run + * and sets ret to -1 on failure. On success, ret is untouched. + */ +void +virTestRunLog(int *ret, + const char *title, + int (*body)(const void *data), + const void *data) +{ + int rc; + + g_free(virTestLogContentAndReset()); + + rc =3D virTestRun(title, body, data); + + if (rc >=3D 0) + return; + + *ret =3D -1; + + if (virTestGetDebug()) { + g_autofree char *log =3D virTestLogContentAndReset(); + + if (strlen(log) > 0) + VIR_TEST_DEBUG("\n%s", log); + } +} + + /** * virTestLoadFile: * @file: name of the file to load diff --git a/tests/testutils.h b/tests/testutils.h index 6848323586..48de864131 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -40,6 +40,10 @@ extern virArch virTestHostArch; int virTestRun(const char *title, int (*body)(const void *data), const void *data); +void virTestRunLog(int *ret, + const char *title, + int (*body)(const void *data), + const void *data); int virTestLoadFile(const char *file, char **buf); char *virTestLoadFilePath(const char *p, ...) G_GNUC_NULL_TERMINATED; --=20 2.31.1