From fc216db4fb789cbd30917be036d0b94d965bdf7f Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 4 Apr 2023 17:07:21 +0200 Subject: [PATCH] tests: Introduce viracpitest Introduce a test that checks newly introduced virAcpi module. There are three IORT tables from a real HW (IORT_ampere, IORT_gigabyte and IORT_qualcomm), then there's one from a VM (IORT_virt_aarch64) and one that I handcrafted to be empty (IORT_empty). Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani --- build-aux/syntax-check.mk | 2 +- tests/meson.build | 1 + tests/viracpidata/IORT_ampere | Bin 0 -> 2304 bytes tests/viracpidata/IORT_empty | Bin 0 -> 65 bytes tests/viracpidata/IORT_gigabyte | Bin 0 -> 10100 bytes tests/viracpidata/IORT_qualcomm | Bin 0 -> 3560 bytes tests/viracpidata/IORT_virt_aarch64 | Bin 0 -> 128 bytes tests/viracpitest.c | 135 ++++++++++++++++++++++++++++ 8 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 tests/viracpidata/IORT_ampere create mode 100644 tests/viracpidata/IORT_empty create mode 100644 tests/viracpidata/IORT_gigabyte create mode 100644 tests/viracpidata/IORT_qualcomm create mode 100644 tests/viracpidata/IORT_virt_aarch64 create mode 100644 tests/viracpitest.c diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 5829dc9011..64c1e2773e 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1370,7 +1370,7 @@ exclude_file_name_regexp--sc_prohibit_close = \ (\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/vir(file|event)\.c|src/libvirt-stream\.c|tests/(vir.+mock\.c|commandhelper\.c|qemusecuritymock\.c)|tools/nss/libvirt_nss_(leases|macs)\.c)|tools/virt-qemu-qmp-proxy$$) exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = \ - (^tests/(nodedevmdevctl|virhostcpu|virpcitest|virstoragetest)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.conf$$) + (^tests/(nodedevmdevctl|viracpi|virhostcpu|virpcitest|virstoragetest)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.conf$$) exclude_file_name_regexp--sc_prohibit_fork_wrappers = \ (^(src/(util/(vircommand|virdaemon)|lxc/lxc_controller)|tests/testutils)\.c$$) diff --git a/tests/meson.build b/tests/meson.build index 24d08e4f97..35adbc2d56 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -269,6 +269,7 @@ tests += [ { 'name': 'storagevolxml2xmltest' }, { 'name': 'sysinfotest' }, { 'name': 'utiltest' }, + { 'name': 'viracpitest' }, { 'name': 'viralloctest' }, { 'name': 'virauthconfigtest' }, { 'name': 'virbitmaptest' }, diff --git a/tests/viracpidata/IORT_ampere b/tests/viracpidata/IORT_ampere new file mode 100644 index 0000000000000000000000000000000000000000..02e7fd98499729025346c6ac3ae5cf10b0f1074d GIT binary patch literal 2304 zc-ozmy-EW?6h`l4f3v$u3LDD>0}6s#SOhF&!9oi$h^2)h!NQ0VECLq3fmrwemOg}q zWgfxO!UxD3th>4EPrUQF!wh6+IG3|03?zF8hey;TqWkRfdN3Mf!<*4*nx+MzY`?#@ zK%~0Gd4sC8NOMaSp9bI#;4a`E;6C61;1S?4;0fR@z}tX#%Dd>zjpfrNjSaj&<9!%-p~mY6^0r##;&Ny;$QtR-QZLpKJNpVf3DF@pm*?YVN&_pZ|sL88d}i+qNx-cEyYtY%STg zTsjdmX0Wwv+wy2EX3St~)wbo+gP1Xct##X0K+j^v47P5~T1vDcdKE2ZuytqKis?ysfBbiklP$_G z(TaCuNhYaqQowZ5198$L2!gd`?ia~&k|a+0@yr>|BGa(QG&PwrUq(z{J`rC&gCJO2 z=6-QlzI2F_0$=Z>W2Tc{h?8DH5Uee8zql+Xxx`7IU2|r`BGa#&@(MVvG|G-tLgGCLNTP?Pxu)W#AY literal 0 Hc-jL100001 diff --git a/tests/viracpidata/IORT_qualcomm b/tests/viracpidata/IORT_qualcomm new file mode 100644 index 0000000000000000000000000000000000000000..5364a9968fa024f34b5e911513a08e8a7f88cf91 GIT binary patch literal 3560 zc-obfPfOfD7{(`)1d7GRi_qiPDtIVmHoM+>P&ZZub=j_m9tyVp0S_WVMNm<}i=IlM zz1T~y{U|*a>IV??;Bmp;x0B86yvbzD%sa4TGSBm5-~8BzU2MHuy&ooo%(t7ZWyadc z+ql6w^Tg5O%IeZ+ILhY4o)fvAlfv@kHQ33vRD6>D$)8^DDd=SAZ~s1ByTWupv;AjU zd`_>IUAguh>C?E}(*~R~$ogI`GkDH|ybl@C)^&fLJ(_t+`iMnm7M&OMGM^ib&#mIK zFHA?0%b}5vSK@Qy$VcbA?LEflPR*Zs%6u$3v*^62m-%!xJ`ak|xiB3|E*C~Vw8W?D z$cJitF6m=@{;By>PnnNJXBM3obz{FGtzS{L{US^!a_({q1qOY-?HOsA5|m61X#FrK;!c}sOXoRKlK>)bKok=b~jeJ5=znu7l8lU^HqF-|U)MM;dmCh_WFY4YKn0YeyUeCnb(;wD4 zvum%DWzKUfo{+)&x@BwX+(Tz$bxzUQx;ppK*@ij~(Ag<<9%8dKp8Ne^v%q-_odwP> z&{^R85}gIkOItl>* literal 0 Hc-jL100001 diff --git a/tests/viracpitest.c b/tests/viracpitest.c new file mode 100644 index 0000000000..f5dd542ffb --- /dev/null +++ b/tests/viracpitest.c @@ -0,0 +1,135 @@ +/* + * viracpitest.c: Test ACPI table parsing + * + * Copyright (C) 2023 Red Hat, Inc. + * + * 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 + * . + * + */ + +#include + +#define LIBVIRT_VIRACPIPRIV_H_ALLOW +#include "testutils.h" +#include "viracpi.h" +#include "viracpipriv.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +typedef struct testAarch64SMMUData testAarch64SMMUData; +struct testAarch64SMMUData { + const char *filename; + ssize_t nnodes; + const virIORTNodeType *node_types; +}; + +static void +printBitmap(virBitmap *types) +{ + size_t i; + + for (i = 0; i < VIR_IORT_NODE_TYPE_LAST; i++) { + if (virBitmapIsBitSet(types, i)) { + fprintf(stderr, "%s\n", virIORTNodeTypeTypeToString(i)); + } + } +} + +static int +testAarch64SMMU(const void *opaque) +{ + const testAarch64SMMUData *data = opaque; + g_autofree char *path = NULL; + g_autofree virIORTNodeHeader *nodes = NULL; + ssize_t nnodes = 0; + + path = g_strdup_printf("%s/viracpidata/%s", + abs_srcdir, data->filename); + + nnodes = virAcpiParseIORT(&nodes, path); + + if (nnodes != data->nnodes) { + fprintf(stderr, + "virAcpiParseIORT() returned wrong number of nodes: %zd, expected %zd\n", + nnodes, data->nnodes); + return -1; + } + + if (nnodes > 0) { + g_autoptr(virBitmap) typesSeen = virBitmapNew(VIR_IORT_NODE_TYPE_LAST); + g_autoptr(virBitmap) typesExp = virBitmapNew(VIR_IORT_NODE_TYPE_LAST); + size_t i = 0; + + for (i = 0; data->node_types[i] != VIR_IORT_NODE_TYPE_LAST; i++) { + size_t type = data->node_types[i]; + + ignore_value(virBitmapSetBit(typesExp, type)); + } + + for (i = 0; i < nnodes; i++) { + virIORTNodeHeader *h = &nodes[i]; + + ignore_value(virBitmapSetBit(typesSeen, h->type)); + } + + if (!virBitmapEqual(typesSeen, typesExp)) { + fprintf(stderr, "node types mismatch.\n\nExpected:\n"); + printBitmap(typesExp); + fprintf(stderr, "\nActual:\n"); + printBitmap(typesSeen); + return -1; + } + } + + return 0; +} + + +static int +mymain(void) +{ + int ret = 0; + +#define DO_TEST(filename, nnodes, ...) \ + do { \ + const virIORTNodeType node_types[] = { __VA_ARGS__, VIR_IORT_NODE_TYPE_LAST }; \ + const testAarch64SMMUData data = {filename, nnodes, node_types }; \ + if (virTestRun("aarch64 SMMU " filename, testAarch64SMMU, &data) < 0) \ + ret = -1; \ + } while (0) + + DO_TEST("IORT_empty", 0, VIR_IORT_NODE_TYPE_LAST); + DO_TEST("IORT_virt_aarch64", 2, + VIR_IORT_NODE_TYPE_ITS_GROUP, + VIR_IORT_NODE_TYPE_ROOT_COMPLEX); + DO_TEST("IORT_ampere", 36, + VIR_IORT_NODE_TYPE_ITS_GROUP, + VIR_IORT_NODE_TYPE_ROOT_COMPLEX, + VIR_IORT_NODE_TYPE_SMMUV3); + DO_TEST("IORT_gigabyte", 30, + VIR_IORT_NODE_TYPE_ITS_GROUP, + VIR_IORT_NODE_TYPE_ROOT_COMPLEX, + VIR_IORT_NODE_TYPE_SMMUV1_OR_SMMUV2); + DO_TEST("IORT_qualcomm", 69, + VIR_IORT_NODE_TYPE_ITS_GROUP, + VIR_IORT_NODE_TYPE_NAMED_COMPONENT, + VIR_IORT_NODE_TYPE_ROOT_COMPLEX, + VIR_IORT_NODE_TYPE_SMMUV3, + VIR_IORT_NODE_TYPE_PMCG); + + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) -- 2.47.2