]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add unit test for virCgroupGetMemoryUsage.
authorThorsten Behrens <tbehrens@suse.com>
Fri, 14 Feb 2014 17:49:06 +0000 (18:49 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 20 Feb 2014 15:20:10 +0000 (16:20 +0100)
tests/vircgrouptest.c

index df2953192e3079233c104c94023a5dde582b6259..e05b8821365180760cf139d4315945936214f3e7 100644 (file)
@@ -530,6 +530,38 @@ static int testCgroupAvailable(const void *args)
     return 0;
 }
 
+static int testCgroupGetMemoryUsage(const void *args ATTRIBUTE_UNUSED)
+{
+    virCgroupPtr cgroup = NULL;
+    int rv, ret = -1;
+    unsigned long kb;
+
+    if ((rv = virCgroupNewPartition("/virtualmachines", true,
+                                    (1 << VIR_CGROUP_CONTROLLER_MEMORY),
+                                    &cgroup)) < 0) {
+        fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
+        goto cleanup;
+    }
+
+    if ((rv = virCgroupGetMemoryUsage(cgroup, &kb)) < 0) {
+        fprintf(stderr, "Could not retrieve GetMemoryUsage for /virtualmachines cgroup: %d\n", -rv);
+        goto cleanup;
+    }
+
+    if (kb != 1421212UL) {
+        fprintf(stderr,
+                "Wrong value from virCgroupGetMemoryUsage (expected %ld)\n",
+                1421212UL);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    virCgroupFree(&cgroup);
+    return ret;
+}
+
 static int testCgroupGetBlkioIoServiced(const void *args ATTRIBUTE_UNUSED)
 {
     virCgroupPtr cgroup = NULL;
@@ -700,6 +732,9 @@ mymain(void)
     if (virtTestRun("virCgroupGetBlkioIoDeviceServiced works", testCgroupGetBlkioIoDeviceServiced, NULL) < 0)
         ret = -1;
 
+    if (virtTestRun("virCgroupGetMemoryUsage works", testCgroupGetMemoryUsage, NULL) < 0)
+        ret = -1;
+
     setenv("VIR_CGROUP_MOCK_MODE", "allinone", 1);
     if (virtTestRun("New cgroup for self (allinone)", testCgroupNewForSelfAllInOne, NULL) < 0)
         ret = -1;