From nobody Mon Feb 9 01:06:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1591629005; cv=none; d=zohomail.com; s=zohoarc; b=gmYlV8YFL+GnDbv8+Uw6aR2ugeIaXbrJdjZqeRqExexbaZawmRHHY/uMUZFV7PUSWErXS1nc7CKQ/IEcFJd0ubavGWD53dEWXJ2T+HOguAvgcdm/VWNknTIQ8Brs0FKQzXKp2qHYOnIqaGLcDLlFB0bp1RA/A8j+ExJbFHCINxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591629005; 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=A5Vr1N+Hq5BHFsHt+ceaFOiXsLhtrw9VUFrqwgo79kg=; b=FnqyOlY4uuMknKWzk+XYkl+OSaprHmHmrdXR75ipC+Lb2Tk+qsRJMzO+3vbYsuAeMywx7qulyBGq4bbAWNi1CET/MwNB9Xwy2LGuwKn5eIaHHB+NR+WM8TRGpGZlAG/xnv6DAK5+SH/ydiDWG5W0SMPV/kKkz/u371DUE46lC7k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1591629005154730.6760737364277; Mon, 8 Jun 2020 08:10:05 -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-351-8FZcuKaUOvGDZXXhy2kcqQ-1; Mon, 08 Jun 2020 11:10:01 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E3644108BD0E; Mon, 8 Jun 2020 15:09:55 +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 A045C61169; Mon, 8 Jun 2020 15:09:55 +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 27D94ADABD; Mon, 8 Jun 2020 15:09:55 +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 058F6T5s004851 for ; Mon, 8 Jun 2020 11:06:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id C875A10013D4; Mon, 8 Jun 2020 15:06:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47E8810013C1 for ; Mon, 8 Jun 2020 15:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591629003; 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=A5Vr1N+Hq5BHFsHt+ceaFOiXsLhtrw9VUFrqwgo79kg=; b=NAUdy01v7JANClBjGLw3qn9X7PddZEvTEg+73IjT9IXWZoE0o8mB6Zv8RcHeVE7H92flb+ FvB8jRXns/Tug5t6qUzNYd6zolyfET6NUPqFW7bgAgeFDZeC+Et0dqsfAx7AuxArcWe6Jl fYUlwFxQRChhp+Vxxle3qamB0ndMJsM= X-MC-Unique: 8FZcuKaUOvGDZXXhy2kcqQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 5/7] sysinfotest: Move from custom dmidecode scripts to virCommandSetDryRun() Date: Mon, 8 Jun 2020 17:06:19 +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.12 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" Problem with custom dmidecode scripts is that they are hard to modify, especially if we will want them to act differently based on passed arguments. So far, we have two scripts which do no more than 'cat $sysinfo' where $sysinfo is saved dmidecode output. The virCommandSetDryRun() can be used to trick virSysinfoReadDMI() thinking it executed real dmidecode. Signed-off-by: Michal Privoznik --- src/util/virsysinfo.c | 3 +- .../sysinfodata/aarch64-gigabytedmidecode.sh | 3 -- tests/sysinfodata/x86dmidecode.sh | 3 -- tests/sysinfotest.c | 51 +++++++++++++------ 4 files changed, 38 insertions(+), 22 deletions(-) delete mode 100755 tests/sysinfodata/aarch64-gigabytedmidecode.sh delete mode 100755 tests/sysinfodata/x86dmidecode.sh diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 0f1210ab37..0bf80c339b 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -60,7 +60,8 @@ virSysinfoSetup(const char *dmidecode, const char *sysinfo, const char *cpuinfo) { - sysinfoDmidecode =3D dmidecode; + if (dmidecode) + sysinfoDmidecode =3D dmidecode; sysinfoSysinfo =3D sysinfo; sysinfoCpuinfo =3D cpuinfo; } diff --git a/tests/sysinfodata/aarch64-gigabytedmidecode.sh b/tests/sysinfo= data/aarch64-gigabytedmidecode.sh deleted file mode 100755 index 202918103c..0000000000 --- a/tests/sysinfodata/aarch64-gigabytedmidecode.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -DATAFILE=3D`dirname $0`/aarch64-gigabytesysinfo.data -cat $DATAFILE diff --git a/tests/sysinfodata/x86dmidecode.sh b/tests/sysinfodata/x86dmide= code.sh deleted file mode 100755 index 28aed61459..0000000000 --- a/tests/sysinfodata/x86dmidecode.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -DATAFILE=3D`dirname $0`/x86sysinfo.data -cat $DATAFILE diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index 558dd60294..f080569730 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -34,14 +34,39 @@ #define LIBVIRT_VIRSYSINFOPRIV_H_ALLOW #include "virsysinfopriv.h" =20 +#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW +#include "vircommandpriv.h" + #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 */ - const char *decoder; /* name of dmi decoder binary/script */ }; =20 + +static void +testDMIDecodeDryRun(const char *const*args G_GNUC_UNUSED, + const char *const*env G_GNUC_UNUSED, + const char *input G_GNUC_UNUSED, + char **output, + char **error, + int *status, + void *opaque) +{ + const char *sysinfo =3D opaque; + + if (virFileReadAll(sysinfo, 10 * 1024 * 1024, output) < 0) { + *error =3D g_strdup(virGetLastErrorMessage()); + *status =3D EXIT_FAILURE; + return; + } + + *error =3D g_strdup(""); + *status =3D 0; +} + + static int testSysinfo(const void *data) { @@ -52,18 +77,19 @@ testSysinfo(const void *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 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->decoder) - decoder =3D g_strdup_printf("%s/%s", abs_srcdir, testdata->decoder= ); + virCommandSetDryRun(NULL, testDMIDecodeDryRun, sysinfo); =20 - virSysinfoSetup(decoder, sysinfo, cpuinfo); + virSysinfoSetup(NULL, sysinfo, cpuinfo); =20 - if (!(ret =3D testdata->func())) + ret =3D testdata->func(); + virCommandSetDryRun(NULL, NULL, NULL); + + if (!ret) return -1; =20 if (virSysinfoFormat(&buf, ret) < 0) @@ -76,17 +102,13 @@ testSysinfo(const void *data) } =20 =20 -#define TEST_FULL(name, func, decoder) \ +#define TEST(name, func) \ do { \ - struct testSysinfoData data =3D { name, func, decoder }; \ + struct testSysinfoData data =3D { name, func }; \ if (virTestRun(name " sysinfo", testSysinfo, &data) < 0) \ ret =3D EXIT_FAILURE; \ } while (0) =20 - -#define TEST(name, func) \ - TEST_FULL(name, func, NULL) - static int mymain(void) { @@ -95,13 +117,12 @@ mymain(void) TEST("s390", virSysinfoReadS390); TEST("s390-freq", virSysinfoReadS390); TEST("ppc", virSysinfoReadPPC); - TEST_FULL("x86", virSysinfoReadDMI, "/sysinfodata/x86dmidecode.sh"); + TEST("x86", virSysinfoReadDMI); TEST("arm", virSysinfoReadARM); TEST("arm-rpi2", virSysinfoReadARM); TEST("aarch64", virSysinfoReadARM); TEST("aarch64-moonshot", virSysinfoReadARM); - TEST_FULL("aarch64-gigabyte", virSysinfoReadARM, - "/sysinfodata/aarch64-gigabytedmidecode.sh"); + TEST("aarch64-gigabyte", virSysinfoReadARM); =20 return ret; } --=20 2.26.2