From nobody Fri May 3 06:05:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 148881406533120.704200731950095; Mon, 6 Mar 2017 07:27:45 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26FORgu010669; Mon, 6 Mar 2017 10:24:27 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v26FOQdq009604 for ; Mon, 6 Mar 2017 10:24:26 -0500 Received: from andariel.redhat.com (ovpn-204-73.brq.redhat.com [10.40.204.73]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26FONSe030039; Mon, 6 Mar 2017 10:24:25 -0500 From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 6 Mar 2017 16:24:36 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 1/4] util: sysinfo: Reduce amount of conditionally compiled code 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Whole implementations along with helper totalling screens of code were conditionally compiled. That made the code totally unreadable and untestable. Rename functions to have the architecture in the name so that all can be compiled at the same time and introduce header to allow testing them all. --- src/Makefile.am | 2 +- src/libvirt_private.syms | 7 ++ src/util/virsysinfo.c | 163 ++++++++++++++++++++++++------------------= ---- src/util/virsysinfopriv.h | 39 +++++++++++ 4 files changed, 132 insertions(+), 79 deletions(-) create mode 100644 src/util/virsysinfopriv.h diff --git a/src/Makefile.am b/src/Makefile.am index 7d42eac31..8f5d1e9ba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -173,7 +173,7 @@ UTIL_SOURCES =3D \ util/virstorageencryption.c util/virstorageencryption.h \ util/virstoragefile.c util/virstoragefile.h \ util/virstring.h util/virstring.c \ - util/virsysinfo.c util/virsysinfo.h \ + util/virsysinfo.c util/virsysinfo.h util/virsysinfopriv.h \ util/virsystemd.c util/virsystemd.h \ util/virthread.c util/virthread.h \ util/virthreadjob.c util/virthreadjob.h \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index aed1d3d50..34bdc7e32 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2558,6 +2558,13 @@ virSysinfoSetup; virSysinfoSystemDefFree; +# util/virsysinfopriv.h +virSysinfoReadARM; +virSysinfoReadPPC; +virSysinfoReadS390; +virSysinfoReadX86; + + # util/virsystemd.h virSystemdCanHibernate; virSystemdCanHybridSleep; diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index e8dbd4d01..bdd430470 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -37,6 +37,9 @@ #include "virfile.h" #include "virstring.h" +#define __VIR_SYSINFO_PRIV_H_ALLOW__ +#include "virsysinfopriv.h" + #define VIR_FROM_THIS VIR_FROM_SYSINFO @@ -156,17 +159,9 @@ void virSysinfoDefFree(virSysinfoDefPtr def) VIR_FREE(def); } -/** - * virSysinfoRead: - * - * Tries to read the SMBIOS information from the current host - * - * Returns: a filled up sysinfo structure or NULL in case of error - */ -#if defined(__powerpc__) static int -virSysinfoParseSystem(const char *base, virSysinfoSystemDefPtr *sysdef) +virSysinfoParsePPCSystem(const char *base, virSysinfoSystemDefPtr *sysdef) { int ret =3D -1; char *eol =3D NULL; @@ -218,7 +213,7 @@ virSysinfoParseSystem(const char *base, virSysinfoSyste= mDefPtr *sysdef) } static int -virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) +virSysinfoParsePPCProcessor(const char *base, virSysinfoDefPtr ret) { const char *cur; char *eol, *tmp_base; @@ -265,7 +260,7 @@ virSysinfoParseProcessor(const char *base, virSysinfoDe= fPtr ret) /* virSysinfoRead for PowerPC * Gathers sysinfo data from /proc/cpuinfo */ virSysinfoDefPtr -virSysinfoRead(void) +virSysinfoReadPPC(void) { virSysinfoDefPtr ret =3D NULL; char *outbuf =3D NULL; @@ -281,10 +276,10 @@ virSysinfoRead(void) ret->nprocessor =3D 0; ret->processor =3D NULL; - if (virSysinfoParseProcessor(outbuf, ret) < 0) + if (virSysinfoParsePPCProcessor(outbuf, ret) < 0) goto no_memory; - if (virSysinfoParseSystem(outbuf, &ret->system) < 0) + if (virSysinfoParsePPCSystem(outbuf, &ret->system) < 0) goto no_memory; return ret; @@ -294,9 +289,9 @@ virSysinfoRead(void) return NULL; } -#elif defined(__arm__) || defined(__aarch64__) + static int -virSysinfoParseSystem(const char *base, virSysinfoSystemDefPtr *sysdef) +virSysinfoParseARMSystem(const char *base, virSysinfoSystemDefPtr *sysdef) { int ret =3D -1; char *eol =3D NULL; @@ -348,7 +343,7 @@ virSysinfoParseSystem(const char *base, virSysinfoSyste= mDefPtr *sysdef) } static int -virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) +virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret) { const char *cur; char *eol, *tmp_base; @@ -397,7 +392,7 @@ virSysinfoParseProcessor(const char *base, virSysinfoDe= fPtr ret) /* virSysinfoRead for ARMv7 * Gathers sysinfo data from /proc/cpuinfo */ virSysinfoDefPtr -virSysinfoRead(void) +virSysinfoReadARM(void) { virSysinfoDefPtr ret =3D NULL; char *outbuf =3D NULL; @@ -413,10 +408,10 @@ virSysinfoRead(void) ret->nprocessor =3D 0; ret->processor =3D NULL; - if (virSysinfoParseProcessor(outbuf, ret) < 0) + if (virSysinfoParseARMProcessor(outbuf, ret) < 0) goto no_memory; - if (virSysinfoParseSystem(outbuf, &ret->system) < 0) + if (virSysinfoParseARMSystem(outbuf, &ret->system) < 0) goto no_memory; return ret; @@ -427,13 +422,12 @@ virSysinfoRead(void) } -#elif defined(__s390__) || defined(__s390x__) VIR_WARNINGS_NO_WLOGICALOP_STRCHR static char * -virSysinfoParseDelimited(const char *base, const char *name, char **value, - char delim1, char delim2) +virSysinfoParseS390Delimited(const char *base, const char *name, char **va= lue, + char delim1, char delim2) { const char *start; char *end; @@ -453,13 +447,13 @@ virSysinfoParseDelimited(const char *base, const char= *name, char **value, } static char * -virSysinfoParseLine(const char *base, const char *name, char **value) +virSysinfoParseS390Line(const char *base, const char *name, char **value) { - return virSysinfoParseDelimited(base, name, value, ':', '\n'); + return virSysinfoParseS390Delimited(base, name, value, ':', '\n'); } static int -virSysinfoParseSystem(const char *base, virSysinfoSystemDefPtr *sysdef) +virSysinfoParseS390System(const char *base, virSysinfoSystemDefPtr *sysdef) { int ret =3D -1; virSysinfoSystemDefPtr def; @@ -467,16 +461,13 @@ virSysinfoParseSystem(const char *base, virSysinfoSys= temDefPtr *sysdef) if (VIR_ALLOC(def) < 0) return ret; - if (!virSysinfoParseLine(base, "Manufacturer", - &def->manufacturer)) + if (!virSysinfoParseS390Line(base, "Manufacturer", &def->manufacturer)) goto cleanup; - if (!virSysinfoParseLine(base, "Type", - &def->family)) + if (!virSysinfoParseS390Line(base, "Type", &def->family)) goto cleanup; - if (!virSysinfoParseLine(base, "Sequence Code", - &def->serial)) + if (!virSysinfoParseS390Line(base, "Sequence Code", &def->serial)) goto cleanup; if (!def->manufacturer && !def->product && !def->version && @@ -494,7 +485,7 @@ virSysinfoParseSystem(const char *base, virSysinfoSyste= mDefPtr *sysdef) } static int -virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) +virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret) { char *tmp_base; char *manufacturer =3D NULL; @@ -502,28 +493,28 @@ virSysinfoParseProcessor(const char *base, virSysinfo= DefPtr ret) int result =3D -1; virSysinfoProcessorDefPtr processor; - if (!(tmp_base =3D virSysinfoParseLine(base, "vendor_id", &manufacture= r))) + if (!(tmp_base =3D virSysinfoParseS390Line(base, "vendor_id", &manufac= turer))) goto cleanup; /* Find processor N: line and gather the processor manufacturer, version, serial number, and family */ while ((tmp_base =3D strstr(tmp_base, "processor ")) - && (tmp_base =3D virSysinfoParseLine(tmp_base, "processor ", - &procline))) { + && (tmp_base =3D virSysinfoParseS390Line(tmp_base, "processor ", + &procline))) { if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) goto cleanup; processor =3D &ret->processor[ret->nprocessor - 1]; if (VIR_STRDUP(processor->processor_manufacturer, manufacturer) < = 0) goto cleanup; - if (!virSysinfoParseDelimited(procline, "version", - &processor->processor_version, - '=3D', ',') || - !virSysinfoParseDelimited(procline, "identification", - &processor->processor_serial_number, - '=3D', ',') || - !virSysinfoParseDelimited(procline, "machine", - &processor->processor_family, - '=3D', '\n')) + if (!virSysinfoParseS390Delimited(procline, "version", + &processor->processor_version, + '=3D', ',') || + !virSysinfoParseS390Delimited(procline, "identification", + &processor->processor_serial_num= ber, + '=3D', ',') || + !virSysinfoParseS390Delimited(procline, "machine", + &processor->processor_family, + '=3D', '\n')) goto cleanup; } result =3D 0; @@ -537,7 +528,7 @@ virSysinfoParseProcessor(const char *base, virSysinfoDe= fPtr ret) /* virSysinfoRead for s390x * Gathers sysinfo data from /proc/sysinfo and /proc/cpuinfo */ virSysinfoDefPtr -virSysinfoRead(void) +virSysinfoReadS390(void) { virSysinfoDefPtr ret =3D NULL; char *outbuf =3D NULL; @@ -554,7 +545,7 @@ virSysinfoRead(void) ret->nprocessor =3D 0; ret->processor =3D NULL; - if (virSysinfoParseProcessor(outbuf, ret) < 0) + if (virSysinfoParseS390Processor(outbuf, ret) < 0) goto no_memory; /* Free buffer before reading next file */ @@ -567,7 +558,7 @@ virSysinfoRead(void) return NULL; } - if (virSysinfoParseSystem(outbuf, &ret->system) < 0) + if (virSysinfoParseS390System(outbuf, &ret->system) < 0) goto no_memory; return ret; @@ -578,26 +569,6 @@ virSysinfoRead(void) return NULL; } -#elif defined(WIN32) || \ - !(defined(__x86_64__) || \ - defined(__i386__) || \ - defined(__amd64__) || \ - defined(__arm__) || \ - defined(__aarch64__) || \ - defined(__powerpc__)) -virSysinfoDefPtr -virSysinfoRead(void) -{ - /* - * this can probably be extracted from Windows using API or registry - * http://www.microsoft.com/whdc/system/platform/firmware/SMBIOS.mspx - */ - virReportSystemError(ENOSYS, "%s", - _("Host sysinfo extraction not supported on this = platform")); - return NULL; -} - -#else /* !WIN32 && x86 */ static int virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios) @@ -653,7 +624,7 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDef= Ptr *bios) } static int -virSysinfoParseSystem(const char *base, virSysinfoSystemDefPtr *sysdef) +virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef) { int ret =3D -1; const char *cur, *eol =3D NULL; @@ -724,9 +695,9 @@ virSysinfoParseSystem(const char *base, virSysinfoSyste= mDefPtr *sysdef) } static int -virSysinfoParseBaseBoard(const char *base, - virSysinfoBaseBoardDefPtr *baseBoard, - size_t *nbaseBoard) +virSysinfoParseX86BaseBoard(const char *base, + virSysinfoBaseBoardDefPtr *baseBoard, + size_t *nbaseBoard) { int ret =3D -1; const char *cur, *eol =3D NULL; @@ -802,7 +773,7 @@ virSysinfoParseBaseBoard(const char *base, } static int -virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) +virSysinfoParseX86Processor(const char *base, virSysinfoDefPtr ret) { const char *cur, *tmp_base; char *eol; @@ -909,7 +880,7 @@ virSysinfoParseProcessor(const char *base, virSysinfoDe= fPtr ret) } static int -virSysinfoParseMemory(const char *base, virSysinfoDefPtr ret) +virSysinfoParseX86Memory(const char *base, virSysinfoDefPtr ret) { const char *cur, *tmp_base; char *eol; @@ -1008,7 +979,7 @@ virSysinfoParseMemory(const char *base, virSysinfoDefP= tr ret) } virSysinfoDefPtr -virSysinfoRead(void) +virSysinfoReadX86(void) { char *path; virSysinfoDefPtr ret =3D NULL; @@ -1037,20 +1008,20 @@ virSysinfoRead(void) if (virSysinfoParseBIOS(outbuf, &ret->bios) < 0) goto error; - if (virSysinfoParseSystem(outbuf, &ret->system) < 0) + if (virSysinfoParseX86System(outbuf, &ret->system) < 0) goto error; - if (virSysinfoParseBaseBoard(outbuf, &ret->baseBoard, &ret->nbaseBoard= ) < 0) + if (virSysinfoParseX86BaseBoard(outbuf, &ret->baseBoard, &ret->nbaseBo= ard) < 0) goto error; ret->nprocessor =3D 0; ret->processor =3D NULL; - if (virSysinfoParseProcessor(outbuf, ret) < 0) + if (virSysinfoParseX86Processor(outbuf, ret) < 0) goto error; ret->nmemory =3D 0; ret->memory =3D NULL; - if (virSysinfoParseMemory(outbuf, ret) < 0) + if (virSysinfoParseX86Memory(outbuf, ret) < 0) goto error; cleanup: @@ -1064,7 +1035,43 @@ virSysinfoRead(void) ret =3D NULL; goto cleanup; } + + +/** + * virSysinfoRead: + * + * Tries to read the SMBIOS information from the current host + * + * Returns: a filled up sysinfo structure or NULL in case of error + */ +virSysinfoDefPtr +virSysinfoRead(void) +{ +#if defined(__powerpc__) + return virSysinfoReadPPC(); +#elif defined(__arm__) || defined(__aarch64__) + return virSysinfoReadARM(); +#elif defined(__s390__) || defined(__s390x__) + return virSysinfoReadS390(); +#elif defined(WIN32) || \ + !(defined(__x86_64__) || \ + defined(__i386__) || \ + defined(__amd64__) || \ + defined(__arm__) || \ + defined(__aarch64__) || \ + defined(__powerpc__)) + /* + * this can probably be extracted from Windows using API or registry + * http://www.microsoft.com/whdc/system/platform/firmware/SMBIOS.mspx + */ + virReportSystemError(ENOSYS, "%s", + _("Host sysinfo extraction not supported on this = platform")); + return NULL; +#else /* !WIN32 && x86 */ + return virSysinfoReadX86(); #endif /* !WIN32 && x86 */ +} + static void virSysinfoBIOSFormat(virBufferPtr buf, virSysinfoBIOSDefPtr def) diff --git a/src/util/virsysinfopriv.h b/src/util/virsysinfopriv.h new file mode 100644 index 000000000..915236479 --- /dev/null +++ b/src/util/virsysinfopriv.h @@ -0,0 +1,39 @@ +/* + * virsysinfopriv.h: Header for functions tested in the test suite + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#ifndef __VIR_SYSINFO_PRIV_H_ALLOW__ +# error "virsysinfopriv.h may only be included by virsysinfo.c or test sui= tes" +#endif + +#ifndef __VIR_SYSINFO_PRIV_H__ +# define __VIR_SYSINFO_PRIV_H__ + +virSysinfoDefPtr +virSysinfoReadPPC(void); + +virSysinfoDefPtr +virSysinfoReadARM(void); + +virSysinfoDefPtr +virSysinfoReadS390(void); + +virSysinfoDefPtr +virSysinfoReadX86(void); + +#endif /* __VIR_SYSINFO_PRIV_H__ */ --=20 2.11.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:05:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 1488814056343665.0002247059671; Mon, 6 Mar 2017 07:27:36 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v26FOU3o015594; Mon, 6 Mar 2017 10:24:30 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v26FORGK009614 for ; Mon, 6 Mar 2017 10:24:27 -0500 Received: from andariel.redhat.com (ovpn-204-73.brq.redhat.com [10.40.204.73]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26FONSf030039; Mon, 6 Mar 2017 10:24:26 -0500 From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 6 Mar 2017 16:24:37 +0100 Message-Id: <4f599e8218cb13a861fcc9b2015a9ff442a49677.1488813740.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 2/4] tests: sysinfo: Export virSysinfoSetup via the private header 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" virSysinfoSetup should be used only in tests so it can be moved to the new header file rather than using an extern declaration. --- src/util/virsysinfo.c | 9 ++++----- src/util/virsysinfopriv.h | 5 +++++ tests/sysinfotest.c | 8 +++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index bdd430470..7b54bda12 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -55,12 +55,11 @@ static const char *sysinfoCpuinfo =3D "/proc/cpuinfo"; #define CPUINFO sysinfoCpuinfo #define CPUINFO_FILE_LEN (1024*1024) /* 1MB limit for /proc/cpuinfo file */ -/* only to be used test programs, therefore not in sysinfo.h */ -extern void virSysinfoSetup(const char *dmidecode, const char *sysinfo, - const char *cpuinfo); -void virSysinfoSetup(const char *dmidecode, const char *sysinfo, - const char *cpuinfo) +void +virSysinfoSetup(const char *dmidecode, + const char *sysinfo, + const char *cpuinfo) { sysinfoDmidecode =3D dmidecode; sysinfoSysinfo =3D sysinfo; diff --git a/src/util/virsysinfopriv.h b/src/util/virsysinfopriv.h index 915236479..a50b280f6 100644 --- a/src/util/virsysinfopriv.h +++ b/src/util/virsysinfopriv.h @@ -24,6 +24,11 @@ #ifndef __VIR_SYSINFO_PRIV_H__ # define __VIR_SYSINFO_PRIV_H__ +void +virSysinfoSetup(const char *dmidecode, + const char *sysinfo, + const char *cpuinfo); + virSysinfoDefPtr virSysinfoReadPPC(void); diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index 457c3415e..f81a0466c 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -37,6 +37,9 @@ #include "virfile.h" #include "virstring.h" +#define __VIR_SYSINFO_PRIV_H_ALLOW__ +#include "virsysinfopriv.h" + #define VIR_FROM_THIS VIR_FROM_NONE #if defined (__linux__) @@ -46,11 +49,6 @@ defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \ defined(__arm__) || defined(__aarch64__) -/* from sysinfo.c */ -void virSysinfoSetup(const char *decoder, - const char *sysinfo, - const char *cpuinfo); - struct testSysinfoData { char *decoder; /* name of dmi decoder binary/script */ char *sysinfo; /* name of /proc/sysinfo substitute file */ --=20 2.11.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:05:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1488814062555113.5132171156489; Mon, 6 Mar 2017 07:27:42 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v26FOVpQ011794; Mon, 6 Mar 2017 10:24:31 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v26FOT9I009620 for ; Mon, 6 Mar 2017 10:24:29 -0500 Received: from andariel.redhat.com (ovpn-204-73.brq.redhat.com [10.40.204.73]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26FONSg030039; Mon, 6 Mar 2017 10:24:28 -0500 From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 6 Mar 2017 16:24:38 +0100 Message-Id: <8658794a26cd50ce30731e4657bf29b40e8bb1e7.1488813740.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 3/4] tests: sysinfo: Run all sysinfo tests all the time 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There's no reason why we should avoid running all sysinfo tests on all platforms. Refactor the test to get rid of the conditionally compiled cruft. --- tests/sysinfotest.c | 106 ++++++++++++------------------------------------= ---- 1 file changed, 23 insertions(+), 83 deletions(-) diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index f81a0466c..3dd569b73 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -42,14 +42,8 @@ #define VIR_FROM_THIS VIR_FROM_NONE -#if defined (__linux__) - -# if defined(__s390__) || defined(__s390x__) || \ - defined(__powerpc__) || defined(__powerpc64__) || \ - defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \ - defined(__arm__) || defined(__aarch64__) - struct testSysinfoData { + 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 */ @@ -68,7 +62,7 @@ testSysinfo(const void *data) virSysinfoSetup(testdata->decoder, testdata->sysinfo, testdata->cpuinf= o); if (!testdata->expected || - !(ret =3D virSysinfoRead())) + !(ret =3D testdata->func())) goto cleanup; if (virSysinfoFormat(&buf, ret) < 0) @@ -91,6 +85,7 @@ testSysinfo(const void *data) static int sysinfotest_run(const char *test, + virSysinfoDefPtr (*func)(void), const char *decoder, const char *sysinfo, const char *cpuinfo, @@ -99,6 +94,8 @@ sysinfotest_run(const char *test, struct testSysinfoData testdata =3D { NULL }; int ret =3D EXIT_FAILURE; + testdata.func =3D func; + if ((decoder && virAsprintf(&testdata.decoder, "%s/%s", abs_srcdir, decoder) < 0)= || (sysinfo && @@ -122,91 +119,34 @@ sysinfotest_run(const char *test, VIR_FREE(testdata.expected); return ret; } -# endif -# if defined(__s390__) || defined(__s390x__) -static int -test_s390(void) -{ - return sysinfotest_run("s390 sysinfo", - NULL, - "/sysinfodata/s390sysinfo.data", - "/sysinfodata/s390cpuinfo.data", - "/sysinfodata/s390sysinfo.expect"); -} +#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 -VIRT_TEST_MAIN(test_s390) -# elif defined(__powerpc__) || defined(__powerpc64__) -static int -test_ppc(void) -{ - return sysinfotest_run("ppc sysinfo", - NULL, - NULL, - "/sysinfodata/ppccpuinfo.data", - "/sysinfodata/ppcsysinfo.expect"); -} -VIRT_TEST_MAIN(test_ppc) -# elif defined(__i386__) || defined(__x86_64__) || defined(__amd64__) -static int -test_x86(void) -{ - return sysinfotest_run("x86 sysinfo", - "/sysinfodata/dmidecode.sh", - NULL, - NULL, - "/sysinfodata/x86sysinfo.expect"); -} +#define TEST(name, func) \ + TEST_FULL(name, func, NULL) -VIRT_TEST_MAIN(test_x86) -# elif defined(__arm__) static int -test_arm(void) +mymain(void) { int ret =3D EXIT_SUCCESS; - if (sysinfotest_run("arm sysinfo", - NULL, - NULL, - "/sysinfodata/armcpuinfo.data", - "/sysinfodata/armsysinfo.expect") !=3D EXIT_SUCCES= S) - ret =3D EXIT_FAILURE; - - if (sysinfotest_run("Raspberry Pi 2 sysinfo", - NULL, - NULL, - "/sysinfodata/arm-rpi2cpuinfo.data", - "/sysinfodata/arm-rpi2sysinfo.expect") !=3D EXIT_S= UCCESS) - ret =3D EXIT_FAILURE; + TEST("s390", virSysinfoReadS390); + TEST("ppc", virSysinfoReadPPC); + TEST_FULL("x86", virSysinfoReadX86, "/sysinfodata/dmidecode.sh"); + TEST("arm", virSysinfoReadARM); + TEST("arm-rpi2", virSysinfoReadARM); + TEST("aarch64", virSysinfoReadARM); return ret; } -VIRT_TEST_MAIN(test_arm) -# elif defined(__aarch64__) -static int -test_aarch64(void) -{ - return sysinfotest_run("aarch64 sysinfo", - NULL, - NULL, - "/sysinfodata/aarch64cpuinfo.data", - "/sysinfodata/aarch64sysinfo.expect"); -} +#undef TEST +#undef TEST_FULL -VIRT_TEST_MAIN(test_aarch64) -# else -int -main(void) -{ - return EXIT_AM_SKIP; -} -# endif /* defined(__s390__) ... */ -#else -int -main(void) -{ - return EXIT_AM_SKIP; -} -#endif /* defined(__linux__) */ +VIRT_TEST_MAIN(mymain) --=20 2.11.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:05:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1488814063520470.6357594628479; Mon, 6 Mar 2017 07:27:43 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v26FOV98011789; Mon, 6 Mar 2017 10:24:31 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v26FOUJj009630 for ; Mon, 6 Mar 2017 10:24:30 -0500 Received: from andariel.redhat.com (ovpn-204-73.brq.redhat.com [10.40.204.73]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26FONSh030039; Mon, 6 Mar 2017 10:24:29 -0500 From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 6 Mar 2017 16:24:39 +0100 Message-Id: <31e4b3afcf989b6bd5e50b33e5282e417ea6bb50.1488813740.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 4/4] tests: sysinfo: Add test data for HP moonshot aarch64 box 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the kernel does not report much data for that box the sysinfo output is comparatively sparse. --- tests/sysinfodata/aarch64-moonshotcpuinfo.data | 72 ++++++++++++++++++++= ++++ tests/sysinfodata/aarch64-moonshotsysinfo.expect | 1 + tests/sysinfotest.c | 1 + 3 files changed, 74 insertions(+) create mode 100644 tests/sysinfodata/aarch64-moonshotcpuinfo.data create mode 100644 tests/sysinfodata/aarch64-moonshotsysinfo.expect diff --git a/tests/sysinfodata/aarch64-moonshotcpuinfo.data b/tests/sysinfo= data/aarch64-moonshotcpuinfo.data new file mode 100644 index 000000000..b694fa809 --- /dev/null +++ b/tests/sysinfodata/aarch64-moonshotcpuinfo.data @@ -0,0 +1,72 @@ +processor : 0 +BogoMIPS : 100.00 +Features : fp asimd evtstrm +CPU implementer : 0x50 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0x000 +CPU revision : 1 + +processor : 1 +BogoMIPS : 100.00 +Features : fp asimd evtstrm +CPU implementer : 0x50 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0x000 +CPU revision : 1 + +processor : 2 +BogoMIPS : 100.00 +Features : fp asimd evtstrm +CPU implementer : 0x50 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0x000 +CPU revision : 1 + +processor : 3 +BogoMIPS : 100.00 +Features : fp asimd evtstrm +CPU implementer : 0x50 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0x000 +CPU revision : 1 + +processor : 4 +BogoMIPS : 100.00 +Features : fp asimd evtstrm +CPU implementer : 0x50 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0x000 +CPU revision : 1 + +processor : 5 +BogoMIPS : 100.00 +Features : fp asimd evtstrm +CPU implementer : 0x50 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0x000 +CPU revision : 1 + +processor : 6 +BogoMIPS : 100.00 +Features : fp asimd evtstrm +CPU implementer : 0x50 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0x000 +CPU revision : 1 + +processor : 7 +BogoMIPS : 100.00 +Features : fp asimd evtstrm +CPU implementer : 0x50 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0x000 +CPU revision : 1 + diff --git a/tests/sysinfodata/aarch64-moonshotsysinfo.expect b/tests/sysin= fodata/aarch64-moonshotsysinfo.expect new file mode 100644 index 000000000..73ea466bc --- /dev/null +++ b/tests/sysinfodata/aarch64-moonshotsysinfo.expect @@ -0,0 +1 @@ + diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index 3dd569b73..047e87b7a 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -142,6 +142,7 @@ mymain(void) TEST("arm", virSysinfoReadARM); TEST("arm-rpi2", virSysinfoReadARM); TEST("aarch64", virSysinfoReadARM); + TEST("aarch64-moonshot", virSysinfoReadARM); return ret; } --=20 2.11.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list