From nobody Mon Feb 9 06:02:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1591628812; cv=none; d=zohomail.com; s=zohoarc; b=nI5Fi6W/P+TcNfsU821Hg61DOrfwwcvAPFpqEv+l0takMf8+5+63SpFOsqrut24vpTy3dHb6ZzCE2+n+EqXoOO2t663IdutygWfjf7Q5IAsH1fAk4JtCP34F9QNADXHhHazOLHMB0p/6Q4BcQnGausaLo9w3L3i/vN9xw053jdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591628812; 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=fLBFWmBvBKFhtJUIT8AkIayprCrLIIMmltXa3YADNLY=; b=la3/OQvlIyIy6VYzWxsnLR58mY1+qinw86hd/KX3cQDL8NOgXW+5xHsMgPSnLsGRUCVq7L+QZWUnspeg642yOGQf1tYpbaPEFRJ2YDlmBzEnVvf+eenTYReEs48eGU2hp3liH2ymDZ0KLCmsIqYCkFvqJl8buFxmo939OeBtLso= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1591628812457816.9957216300749; Mon, 8 Jun 2020 08:06:52 -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-235-5qRRnpqZNt65UT5CCdHlPA-1; Mon, 08 Jun 2020 11:06:49 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F00F8018A5; Mon, 8 Jun 2020 15:06:38 +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 5E101891E6; Mon, 8 Jun 2020 15:06:38 +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 2E1DAADABD; Mon, 8 Jun 2020 15:06:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 058F6SCW004846 for ; Mon, 8 Jun 2020 11:06:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id E7F8A10013D4; Mon, 8 Jun 2020 15:06:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67E2710013C1 for ; Mon, 8 Jun 2020 15:06:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591628811; 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=fLBFWmBvBKFhtJUIT8AkIayprCrLIIMmltXa3YADNLY=; b=Sh2liN96s29+q9Uud4yTR4qRs6NJKbAeFeyYxxqh5OWfUzrvjFl0DN8CZi8RXqTR2Q9dkW R+DiIDtWeBCglIjl3DTse5NcE+PeUH6rX8oHqyK+vlXcUi3czpf1bLPWfyB3HpwKbsDYoC nZiXRn6+8hf2sai1zo6M3FnhT2bLTaQ= X-MC-Unique: 5qRRnpqZNt65UT5CCdHlPA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 4/7] sysinfotest: Dissolve sysinfotest_run() in testSysinfo() Date: Mon, 8 Jun 2020 17:06:18 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.13 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" There is no real need to have two separate functions. They can be merged together which not only saves couple of lines, but prepares the structure of the code for future expansion. See next commits. Signed-off-by: Michal Privoznik --- tests/sysinfotest.c | 70 ++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index 4807c5b1ba..558dd60294 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -37,25 +37,33 @@ #define VIR_FROM_THIS VIR_FROM_NONE =20 struct testSysinfoData { + const char *name; /* test name, also base name for result files */ virSysinfoDefPtr (*func)(void); /* sysinfo gathering function */ - char *decoder; /* name of dmi decoder binary/script */ - char *sysinfo; /* name of /proc/sysinfo substitute file */ - char *cpuinfo; /* name of /proc/cpuinfo substitute file */ - char *expected; /* (required) file containing output of virSysinfoForm= at */ + const char *decoder; /* name of dmi decoder binary/script */ }; =20 static int testSysinfo(const void *data) { + const struct testSysinfoData *testdata =3D data; const char *sysfsActualData; g_auto(virSysinfoDefPtr) ret =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - const struct testSysinfoData *testdata =3D data; + g_autofree char *sysinfo =3D NULL; + g_autofree char *cpuinfo =3D NULL; + g_autofree char *expected =3D NULL; + g_autofree char *decoder =3D NULL; =20 - virSysinfoSetup(testdata->decoder, testdata->sysinfo, testdata->cpuinf= o); + sysinfo =3D g_strdup_printf("%s/sysinfodata/%ssysinfo.data", abs_srcdi= r, testdata->name); + cpuinfo =3D g_strdup_printf("%s/sysinfodata/%scpuinfo.data", abs_srcdi= r, testdata->name); + expected =3D g_strdup_printf("%s/sysinfodata/%ssysinfo.expect", abs_sr= cdir, testdata->name); =20 - if (!testdata->expected || - !(ret =3D testdata->func())) + if (testdata->decoder) + decoder =3D g_strdup_printf("%s/%s", abs_srcdir, testdata->decoder= ); + + virSysinfoSetup(decoder, sysinfo, cpuinfo); + + if (!(ret =3D testdata->func())) return -1; =20 if (virSysinfoFormat(&buf, ret) < 0) @@ -64,50 +72,16 @@ testSysinfo(const void *data) if (!(sysfsActualData =3D virBufferCurrentContent(&buf))) return -1; =20 - return virTestCompareToFile(sysfsActualData, testdata->expected); + return virTestCompareToFile(sysfsActualData, expected); } =20 -static int -sysinfotest_run(const char *test, - virSysinfoDefPtr (*func)(void), - const char *decoder, - const char *sysinfo, - const char *cpuinfo, - const char *expected) -{ - struct testSysinfoData testdata =3D { 0 }; - int ret =3D EXIT_FAILURE; - - testdata.func =3D func; - - if (decoder) - testdata.decoder =3D g_strdup_printf("%s/%s", abs_srcdir, decoder); - if (sysinfo) - testdata.sysinfo =3D g_strdup_printf("%s/%s", abs_srcdir, sysinfo); - if (cpuinfo) - testdata.cpuinfo =3D g_strdup_printf("%s/%s", abs_srcdir, cpuinfo); - if (expected) - testdata.expected =3D g_strdup_printf("%s/%s", abs_srcdir, expecte= d); - - if (virTestRun(test, testSysinfo, &testdata) < 0) - goto error; - - ret =3D EXIT_SUCCESS; - - error: - VIR_FREE(testdata.decoder); - VIR_FREE(testdata.sysinfo); - VIR_FREE(testdata.cpuinfo); - VIR_FREE(testdata.expected); - return ret; -} =20 #define TEST_FULL(name, func, decoder) \ - if (sysinfotest_run(name " sysinfo", func, decoder, \ - "/sysinfodata/" name "sysinfo.data", \ - "/sysinfodata/" name "cpuinfo.data", \ - "/sysinfodata/" name "sysinfo.expect") !=3D EXIT_S= UCCESS) \ - ret =3D EXIT_FAILURE + do { \ + struct testSysinfoData data =3D { name, func, decoder }; \ + if (virTestRun(name " sysinfo", testSysinfo, &data) < 0) \ + ret =3D EXIT_FAILURE; \ + } while (0) =20 =20 #define TEST(name, func) \ --=20 2.26.2