From nobody Mon Feb 9 01:45:25 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1541635945469400.68567148389604; Wed, 7 Nov 2018 16:12:25 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 683CE8046A; Thu, 8 Nov 2018 00:12:23 +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 2025060C60; Thu, 8 Nov 2018 00:12:23 +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 B9E5B4CAA7; Thu, 8 Nov 2018 00:12:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wA7NvjGG011900 for ; Wed, 7 Nov 2018 18:57:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1EEA168D22; Wed, 7 Nov 2018 23:57:45 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-225.phx2.redhat.com [10.3.116.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1FCF68D28; Wed, 7 Nov 2018 23:57:44 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 7 Nov 2018 18:57:40 -0500 Message-Id: <20181107235740.4514-3-jferlan@redhat.com> In-Reply-To: <20181107235740.4514-1-jferlan@redhat.com> References: <20181107235740.4514-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter.Chubb@data61.csiro.au Subject: [libvirt] [PATCH 2/2] tests: Augment vcgrouptest to add virCgroupGetMemoryStat 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 08 Nov 2018 00:12:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add a test to fetch the GetMemoryStat output. This only gets data for v1 only right now since the v2 data from commit 61ff6021 is rather useless returning all 0's. Signed-off-by: John Ferlan Reviewed-by: Pavel Hrdina --- tests/vircgrouptest.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 310e1fb6a2..06c4a8ef5c 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -802,6 +802,64 @@ static int testCgroupGetMemoryUsage(const void *args A= TTRIBUTE_UNUSED) return ret; } =20 + +static int +testCgroupGetMemoryStat(const void *args ATTRIBUTE_UNUSED) +{ + virCgroupPtr cgroup =3D NULL; + int rv, ret =3D -1; + size_t i; + + const unsigned long long expected_values[] =3D { + 1336619008ULL, + 67100672ULL, + 145887232ULL, + 661872640ULL, + 627400704UL, + 3690496ULL + }; + const char* names[] =3D { + "cache", + "active_anon", + "inactive_anon", + "active_file", + "inactive_file", + "unevictable" + }; + unsigned long long values[ARRAY_CARDINALITY(expected_values)]; + + if ((rv =3D virCgroupNewPartition("/virtualmachines", true, + (1 << VIR_CGROUP_CONTROLLER_MEMORY), + &cgroup)) < 0) { + fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", = -rv); + goto cleanup; + } + + if ((rv =3D virCgroupGetMemoryStat(cgroup, &values[0], + &values[1], &values[2], + &values[3], &values[4], + &values[5])) < 0) { + fprintf(stderr, "Could not retrieve GetMemoryStat for /virtualmach= ines cgroup: %d\n", -rv); + goto cleanup; + } + + for (i =3D 0; i < ARRAY_CARDINALITY(expected_values); i++) { + if (expected_values[i] !=3D (values[i] << 10)) { + fprintf(stderr, + "Wrong value (%llu) for %s from virCgroupGetMemoryStat= (expected %llu)\n", + values[i], names[i], expected_values[i]); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + virCgroupFree(&cgroup); + return ret; +} + + static int testCgroupGetBlkioIoServiced(const void *args ATTRIBUTE_UNUSED) { virCgroupPtr cgroup =3D NULL; @@ -1035,6 +1093,9 @@ mymain(void) if (virTestRun("virCgroupGetMemoryUsage works", testCgroupGetMemoryUsa= ge, NULL) < 0) ret =3D -1; =20 + if (virTestRun("virCgroupGetMemoryStat works", testCgroupGetMemoryStat= , NULL) < 0) + ret =3D -1; + if (virTestRun("virCgroupGetPercpuStats works", testCgroupGetPercpuSta= ts, NULL) < 0) ret =3D -1; cleanupFakeFS(fakerootdir); --=20 2.17.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list