From nobody Thu May 15 09:59:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510563074437783.6300807230249; Mon, 13 Nov 2017 00:51:14 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id E0974BDE3; Mon, 13 Nov 2017 08:51:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B547E68D51; Mon, 13 Nov 2017 08:51:12 +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 847B9180212C; Mon, 13 Nov 2017 08:51:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vAD8olJe016328 for ; Mon, 13 Nov 2017 03:50:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id E028562537; Mon, 13 Nov 2017 08:50:47 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 672B467155 for ; Mon, 13 Nov 2017 08:50:47 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 00CCF123A91 for ; Mon, 13 Nov 2017 09:50:42 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Mon, 13 Nov 2017 09:50:34 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 19/21] tests: Add virresctrltest 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 13 Nov 2017 08:51:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This test has 2 different uses: 1) DO_TEST_FREE initializes capabilities from vircaps2xmldata (since it ex= ists there already) and then requests list of free bitmaps (all unallocated space) from virresctrl.c 2) DO_TEST_ALLOC takes capabilities from vircaps2xmldata, and uses resctrl= info to request an allocation from virresctrl.c for a VM from genericxml2xmlindata. Desirable outputs are saved in virresctrldata. Signed-off-by: Martin Kletzander Reviewed-by: John Ferlan , but not really fully Reviewed-by: Pavel Hrdina --- tests/Makefile.am | 8 +- .../resctrl--cachetune/vcpus-0-1.alloc | 1 + .../resctrl--cachetune/vcpus-3.alloc | 1 + .../resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc | 2 + .../resctrl-cdp--cachetune-cdp/vcpus-2.alloc | 1 + .../resctrl-cdp--cachetune-cdp/vcpus-3.alloc | 1 + tests/virresctrldata/resctrl-cdp.schemata | 2 + .../virresctrldata/resctrl-skx-twocaches.schemata | 1 + tests/virresctrldata/resctrl-skx.schemata | 1 + tests/virresctrldata/resctrl.schemata | 1 + tests/virresctrltest.c | 277 +++++++++++++++++= ++++ 11 files changed, 295 insertions(+), 1 deletion(-) create mode 100644 tests/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc create mode 100644 tests/virresctrldata/resctrl--cachetune/vcpus-3.alloc create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0= -1.alloc create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2= .alloc create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3= .alloc create mode 100644 tests/virresctrldata/resctrl-cdp.schemata create mode 100644 tests/virresctrldata/resctrl-skx-twocaches.schemata create mode 100644 tests/virresctrldata/resctrl-skx.schemata create mode 100644 tests/virresctrldata/resctrl.schemata create mode 100644 tests/virresctrltest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index effa259e3a45..04695c0ad250 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -231,6 +231,7 @@ if WITH_LINUX test_programs +=3D fchosttest test_programs +=3D scsihosttest test_programs +=3D vircaps2xmltest +test_programs +=3D virresctrltest test_libraries +=3D virusbmock.la \ virnetdevbandwidthmock.la \ virnumamock.la \ @@ -1172,8 +1173,13 @@ virnumamock_la_CFLAGS =3D $(AM_CFLAGS) virnumamock_la_LDFLAGS =3D $(MOCKLIBS_LDFLAGS) virnumamock_la_LIBADD =3D $(MOCKLIBS_LIBS) =20 +virresctrltest_SOURCES =3D \ + virresctrltest.c testutils.h testutils.c virfilewrapper.h virfilewrapper.c +virresctrltest_LDADD =3D $(LDADDS) + else ! WITH_LINUX -EXTRA_DIST +=3D vircaps2xmltest.c virnumamock.c virfilewrapper.c virfilewr= apper.h +EXTRA_DIST +=3D vircaps2xmltest.c virnumamock.c virfilewrapper.c \ + virfilewrapper.h virresctrltest.c endif ! WITH_LINUX =20 if WITH_NSS diff --git a/tests/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc b/test= s/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc new file mode 100644 index 000000000000..6f48dd99d5a1 --- /dev/null +++ b/tests/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc @@ -0,0 +1 @@ +L3:0=3D0000f;1=3D000f0 diff --git a/tests/virresctrldata/resctrl--cachetune/vcpus-3.alloc b/tests/= virresctrldata/resctrl--cachetune/vcpus-3.alloc new file mode 100644 index 000000000000..b47a36fecc8a --- /dev/null +++ b/tests/virresctrldata/resctrl--cachetune/vcpus-3.alloc @@ -0,0 +1 @@ +L3:0=3D000f0 diff --git a/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0-1.allo= c b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc new file mode 100644 index 000000000000..44886a2cfe38 --- /dev/null +++ b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc @@ -0,0 +1,2 @@ +L3CODE:0=3D00ffc +L3DATA:1=3D0001f diff --git a/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2.alloc = b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2.alloc new file mode 100644 index 000000000000..4225b0a36167 --- /dev/null +++ b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2.alloc @@ -0,0 +1 @@ +L3CODE:1=3D0ff00 diff --git a/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3.alloc = b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3.alloc new file mode 100644 index 000000000000..10be6844bd38 --- /dev/null +++ b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3.alloc @@ -0,0 +1 @@ +L3DATA:1=3D03fe0 diff --git a/tests/virresctrldata/resctrl-cdp.schemata b/tests/virresctrlda= ta/resctrl-cdp.schemata new file mode 100644 index 000000000000..2897e2afa603 --- /dev/null +++ b/tests/virresctrldata/resctrl-cdp.schemata @@ -0,0 +1,2 @@ +L3CODE:0=3D00ffc;1=3D0ff00 +L3DATA:0=3D00000;1=3D03fff diff --git a/tests/virresctrldata/resctrl-skx-twocaches.schemata b/tests/vi= rresctrldata/resctrl-skx-twocaches.schemata new file mode 100644 index 000000000000..86b3801a04c2 --- /dev/null +++ b/tests/virresctrldata/resctrl-skx-twocaches.schemata @@ -0,0 +1 @@ +L3:0=3D001;1=3D400 diff --git a/tests/virresctrldata/resctrl-skx.schemata b/tests/virresctrlda= ta/resctrl-skx.schemata new file mode 100644 index 000000000000..5e8b0d636277 --- /dev/null +++ b/tests/virresctrldata/resctrl-skx.schemata @@ -0,0 +1 @@ +L3:0=3D70f diff --git a/tests/virresctrldata/resctrl.schemata b/tests/virresctrldata/r= esctrl.schemata new file mode 100644 index 000000000000..fa980e58c9dd --- /dev/null +++ b/tests/virresctrldata/resctrl.schemata @@ -0,0 +1 @@ +L3:0=3D000ff;1=3D000f0 diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c new file mode 100644 index 000000000000..e84d9ff94299 --- /dev/null +++ b/tests/virresctrltest.c @@ -0,0 +1,277 @@ +#include +#include + +#include "testutils.h" +#include "virfilewrapper.h" +#include "virresctrlpriv.h" + + +#define VIR_FROM_THIS VIR_FROM_NONE + +struct virResctrlData { + const char *filename; + bool fail; + const char *test_name; +}; + + +static int +test_virResctrlGetFree(const void *opaque) +{ + struct virResctrlData *data =3D (struct virResctrlData *) opaque; + char *system_dir =3D NULL; + char *resctrl_dir =3D NULL; + int ret =3D -1; + virResctrlAllocPtr alloc =3D NULL; + char *schemata_str =3D NULL; + char *schemata_file; + virCapsPtr caps =3D NULL; + + if (virAsprintf(&system_dir, "%s/vircaps2xmldata/linux-%s/system", + abs_srcdir, data->filename) < 0) + goto cleanup; + + if (virAsprintf(&resctrl_dir, "%s/vircaps2xmldata/linux-%s/resctrl", + abs_srcdir, data->filename) < 0) + goto cleanup; + + if (virAsprintf(&schemata_file, "%s/virresctrldata/%s.schemata", + abs_srcdir, data->filename) < 0) + goto cleanup; + + virFileWrapperAddPrefix("/sys/devices/system", system_dir); + virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl_dir); + + caps =3D virCapabilitiesNew(VIR_ARCH_X86_64, false, false); + if (!caps || virCapabilitiesInitCaches(caps) < 0) { + fprintf(stderr, "Could not initialize capabilities"); + goto cleanup; + } + + alloc =3D virResctrlAllocGetFree(caps->host.resctrl); + + virFileWrapperClearPrefixes(); + + if (!alloc) { + if (data->fail) + ret =3D 0; + goto cleanup; + } else if (data->fail) { + VIR_TEST_DEBUG("Error expected but there wasn't any.\n"); + ret =3D -1; + goto cleanup; + } + + schemata_str =3D virResctrlAllocFormat(alloc); + + if (virTestCompareToFile(schemata_str, schemata_file) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virObjectUnref(caps); + virObjectUnref(alloc); + VIR_FREE(system_dir); + VIR_FREE(resctrl_dir); + VIR_FREE(schemata_str); + VIR_FREE(schemata_file); + return ret; +} + +static int +test_virResctrlGetAlloc(const void *opaque) +{ + struct virResctrlData *data =3D (struct virResctrlData *) opaque; + char *system_dir =3D NULL; + char *resctrl_dir =3D NULL; + int ret =3D -1; + int rv =3D 0; + virResctrlAllocPtr alloc =3D NULL; + char *schemata_str =3D NULL; + char *schemata_file =3D NULL; + char *domain_file =3D NULL; + char *vcpus =3D NULL; + virCapsPtr caps =3D NULL; + virDomainDefPtr def =3D NULL; + size_t i =3D 0; + virDomainXMLOptionPtr xmlopt =3D NULL; + void *save_ptr =3D NULL; + + if (virAsprintf(&system_dir, "%s/vircaps2xmldata/linux-%s/system", + abs_srcdir, data->filename) < 0) + goto cleanup; + + if (virAsprintf(&resctrl_dir, "%s/vircaps2xmldata/linux-%s/resctrl", + abs_srcdir, data->filename) < 0) + goto cleanup; + + if (virAsprintf(&domain_file, "%s/genericxml2xmlindata/generic-%s.xml", + abs_srcdir, data->test_name) < 0) + goto cleanup; + + virFileWrapperAddPrefix("/sys/devices/system", system_dir); + virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl_dir); + + caps =3D virTestGenericCapsInit(); + if (!caps || virCapabilitiesInitCaches(caps) < 0) { + fprintf(stderr, "Could not initialize capabilities"); + goto cleanup; + } + + xmlopt =3D virTestGenericDomainXMLConfInit(); + if (!xmlopt) + goto cleanup; + + def =3D virDomainDefParseFile(domain_file, caps, xmlopt, NULL, + VIR_DOMAIN_DEF_PARSE_INACTIVE); + if (!def) + goto cleanup; + + for (i =3D 0; i < def->ncachetunes; i++) { + if (virResctrlAllocMasksAssign(caps->host.resctrl, + def->cachetunes[i]->alloc, + &save_ptr) < 0) { + rv =3D -1; + break; + } + } + + virFileWrapperClearPrefixes(); + + if (rv < 0) { + if (data->fail) + ret =3D 0; + goto cleanup; + } else if (data->fail) { + VIR_TEST_DEBUG("Error expected but there wasn't any.\n"); + goto cleanup; + } + + for (i =3D 0; i < def->ncachetunes; i++) { + VIR_FREE(vcpus); + vcpus =3D virBitmapFormat(def->cachetunes[i]->vcpus); + + if (!vcpus) + goto cleanup; + + VIR_FREE(schemata_file); + VIR_FREE(schemata_str); + + if (virAsprintf(&schemata_file, "%s/virresctrldata/%s--%s/vcpus-%s= .alloc", + abs_srcdir, data->filename, data->test_name, vcpus= ) < 0) + goto cleanup; + + schemata_str =3D virResctrlAllocFormat(def->cachetunes[i]->alloc); + if (!schemata_str) + goto cleanup; + + if (virTestCompareToFile(schemata_str, schemata_file) < 0) + rv =3D -1; + } + + ret =3D rv; + cleanup: + virObjectUnref(save_ptr); + virObjectUnref(caps); + virObjectUnref(alloc); + virObjectUnref(xmlopt); + VIR_FREE(system_dir); + VIR_FREE(resctrl_dir); + VIR_FREE(schemata_str); + VIR_FREE(schemata_file); + VIR_FREE(domain_file); + VIR_FREE(vcpus); + virDomainDefFree(def); + return ret; +} + +static int +mymain(void) +{ + struct virResctrlData data =3D {0}; + int ret =3D 0; + +#define DO_TEST_FREE(_filename) \ + do { \ + data =3D (struct virResctrlData) { .filename =3D _filename }; \ + if (virTestRun("Free: " _filename, test_virResctrlGetFree, &data) = < 0) \ + ret =3D -1; \ + } while (0) + +#define DO_TEST_ALLOC_FULL(_filename, _test_name, _fail) \ + do { \ + data =3D (struct virResctrlData) { .filename =3D _filename, \ + .test_name =3D _test_name, \ + .fail =3D _fail }; \ + if (virTestRun("Alloc: " _filename "+" _test_name, \ + test_virResctrlGetAlloc, &data) < 0) \ + ret =3D -1; \ + } while (0) + +#define DO_TEST_ALLOC(_filename, _test_name) \ + DO_TEST_ALLOC_FULL(_filename, _test_name, false) + +#define DO_TEST_ALLOC_FAIL(_filename, _test_name) \ + DO_TEST_ALLOC_FULL(_filename, _test_name, true) + + DO_TEST_FREE("resctrl"); + DO_TEST_FREE("resctrl-cdp"); + DO_TEST_FREE("resctrl-skx"); + DO_TEST_FREE("resctrl-skx-twocaches"); + + + /************* + * Tests with generic-cachetune.xml (decently sized allocations for 2 = caches) + ***/ + + /* Simplest one, this one should fail because there is not resctrl sup= port + * on the host */ + DO_TEST_ALLOC_FAIL("caches", "cachetune"); + + DO_TEST_ALLOC("resctrl", "cachetune"); + + /* This one should fail because there are allocations for two caches + * requested, but only one exists */ + DO_TEST_ALLOC_FAIL("resctrl-skx", "cachetune"); + + /* This one should fail because there is not enough room available */ + DO_TEST_ALLOC_FAIL("resctrl-skx-twocaches", "cachetune"); + + /* This one should fail because non-CDP allocation is requested on + * CDP-enabled system, support for this can be added in the future */ + DO_TEST_ALLOC_FAIL("resctrl-cdp", "cachetune"); + + /************* + * Tests with generic-cachetune-small.xml (small allocation for 1 cach= e) + ***/ + + /* This one should fail because the allocation size is smaller than mi= nimum + * (although with the right granularity) */ + DO_TEST_ALLOC_FAIL("resctrl", "cachetune-small"); + + /* These two should fail because the allocations size is smaller than + * granularity */ + DO_TEST_ALLOC_FAIL("resctrl-skx", "cachetune-small"); + DO_TEST_ALLOC_FAIL("resctrl-skx-twocaches", "cachetune-small"); + + /* This one should fail because non-CDP allocation is requested on + * CDP-enabled system, support for this can be added in the future */ + DO_TEST_ALLOC_FAIL("resctrl-cdp", "cachetune-small"); + + /************* + * Tests with generic-cachetune-cdp.xml (decently sized allocations, + * separate for code and data) + ***/ + + /* These should fail because CDP allocation is requested on non-CDP + * system */ + DO_TEST_ALLOC_FAIL("resctrl", "cachetune-cdp"); + DO_TEST_ALLOC_FAIL("resctrl-skx", "cachetune-cdp"); + DO_TEST_ALLOC_FAIL("resctrl-skx-twocaches", "cachetune-cdp"); + + DO_TEST_ALLOC("resctrl-cdp", "cachetune-cdp"); + + return ret; +} + +VIR_TEST_MAIN(mymain) --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list