[PATCH 2/4] bugfixies

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* slight modification of the subtests executions
* modified clean-up function
* raise errors instead of returns
* more failure checking

Signed-off-by: Lukas Doktor <ldoktor@xxxxxxxxxx>
---
 client/tests/cgroup/cgroup.py        |  116 +++++++++++++++++----------------
 client/tests/cgroup/cgroup_client.py |    3 +-
 client/tests/cgroup/cgroup_common.py |   45 +++++++++++++-
 3 files changed, 106 insertions(+), 58 deletions(-)

diff --git a/client/tests/cgroup/cgroup.py b/client/tests/cgroup/cgroup.py
index 112f012..45636f2 100755
--- a/client/tests/cgroup/cgroup.py
+++ b/client/tests/cgroup/cgroup.py
@@ -23,20 +23,24 @@ class cgroup(test.test):
         err = ""
         # Run available tests
         for i in ['memory']:
+            logging.info("---< 'test_%s' START >---", i)
             try:
-                if self.modules.get_pwd(i):
-                    if (eval ("self.test_%s()" % i)):
-                        err += "%s, " % i
-                else:
-                    logging.error("CGROUP: Skipping test_%s, module not "
-                                  "available/mounted", i)
-                    err += "%s, " % i
+                if not self.modules.get_pwd(i):
+                    raise error.TestFail("module not available/mounted")
+                eval ("self.test_%s()" % i)
+                logging.info("---< 'test_%s' PASSED >---", i)
+            except AttributeError:
+                err += "%s, " % i
+                logging.error("test_%s: Test doesn't exist", i)
+                logging.info("---< 'test_%s' FAILED >---", i)
             except Exception, inst:
-                logging.error("CGROUP: test_%s fatal failure: %s", i, inst)
                 err += "%s, " % i
+                logging.error("test_%s: %s", i, inst)
+                logging.info("---< 'test_%s' FAILED >---", i)
 
         if err:
-            raise error.TestFail('CGROUP: Some subtests failed (%s)' % err[:-2])
+            logging.error('Some subtests failed (%s)' % err[:-2])
+            raise error.TestFail('Some subtests failed (%s)' % err[:-2])
 
 
     def setup(self):
@@ -68,21 +72,31 @@ class cgroup(test.test):
         """
         Memory test
         """
+        def cleanup(supress=False):
+            # cleanup
+            logging.debug("test_memory: Cleanup")
+            err = ""
+            if item.rm_cgroup(pwd):
+                err += "\nCan't remove cgroup directory"
+
+            os.system("swapon -a")
+            if err:
+                if supress:
+                    logging.warn("Some parts of cleanup failed%s" % err)
+                else:
+                    raise error.TestFail("Some parts of cleanup failed%s" % err)
+
         # Preparation
-        logging.info("Entering 'test_memory'")
         item = CG('memory', self._client)
         if item.initialize(self.modules):
-            logging.error("test_memory: cgroup init failed")
-            return -1
+            raise error.TestFail("cgroup init failed")
 
         if item.smoke_test():
-            logging.error("test_memory: smoke_test failed")
-            return -1
+            raise error.TestFail("smoke_test failed")
 
         pwd = item.mk_cgroup()
         if pwd == None:
-            logging.error("test_memory: Can't create cgroup")
-            return -1
+            raise error.TestFail("Can't create cgroup")
 
         logging.debug("test_memory: Memory filling test")
 
@@ -128,13 +142,15 @@ class cgroup(test.test):
             i += 1
             time.sleep(1)
         if i > 60:
-            logging.error("test_memory: Memory filling failed (WO cgroup)")
             ps.terminate()
-            return -1
-        if not ps.stdout.readlines()[-1].startswith("PASS"):
-            logging.error("test_memory: Unsuccessful memory filling "
+            raise error.TestFail("Memory filling failed (WO cgroup)")
+        out = ps.stdout.readlines()
+        if (len(out) < 2) or (ps.poll() != 0):
+            raise error.TestFail("Process failed (WO cgroup); output:\n%s"
+                          "\nReturn: %d", out, ps.poll())
+        if not out[-1].startswith("PASS"):
+            raise error.TestFail("Unsuccessful memory filling "
                           "(WO cgroup)")
-            return -1
         logging.debug("test_memory: Memfill WO cgroup passed")
 
         ################################################
@@ -145,11 +161,9 @@ class cgroup(test.test):
         logging.debug("test_memory: Memfill mem only limit")
         ps = item.test("memfill %d" % mem)
         if item.set_cgroup(ps.pid, pwd):
-            logging.error("test_memory: Could not set cgroup")
-            return -1
-        if item.set_property("memory.limit_in_bytes", (1024*1024*mem/2), pwd):
-            logging.error("test_memory: Could not set mem limit (mem)")
-            return -1
+            raise error.TestFail("Could not set cgroup")
+        if item.set_prop("memory.limit_in_bytes", ("%dM" % (mem/2)), pwd):
+            raise error.TestFail("Could not set mem limit (mem)")
         ps.stdin.write('\n')
         i = 0
         while ps.poll() == None:
@@ -158,23 +172,20 @@ class cgroup(test.test):
             i += 1
             time.sleep(1)
         if i > 60:
-            logging.error("test_memory: Memory filling failed (mem)")
             ps.terminate()
-            return -1
+            raise error.TestFail("Memory filling failed (mem)")
         out = ps.stdout.readlines()
-        if len(out) < 2:
-            logging.error("test_memory: Process failed; output:\n%s", out)
-            return -1
+        if (len(out)) < 2 or (ps.poll() != 0):
+            raise error.TestFail("Process failed (mem); output:\n%s"
+                          "\nReturn: %d", out, ps.poll())
         if memsw:
             if not out[-1].startswith("PASS"):
-                logging.error("test_memory: Unsuccessful memory filling (mem)")
                 logging.error("test_memory: cgroup_client.py returned %d; "
                               "output:\n%s", ps.poll(), out)
-                return -1
+                raise error.TestFail("Unsuccessful memory filling (mem)")
         else:
             if out[-1].startswith("PASS"):
-                logging.error("test_memory: Unexpected memory filling (mem)")
-                return -1
+                raise error.TestFail("Unexpected memory filling (mem)")
             else:
                 filled = int(out[-2].split()[1][:-1])
                 if mem/2 > 1.5*filled:
@@ -193,12 +204,9 @@ class cgroup(test.test):
         if memsw:
             ps = item.test("memfill %d" % mem)
             if item.set_cgroup(ps.pid, pwd):
-                logging.error("test_memory: Could not set cgroup (memsw)")
-                return -1
-            if item.set_property("memory.memsw.limit_in_bytes",
-                                 (1024*1024*mem/2), pwd):
-                logging.error("test_memory: Could not set mem limit (memsw)")
-                return -1
+                raise error.TestFail("Could not set cgroup (memsw)")
+            if item.set_prop("memory.memsw.limit_in_bytes", "%dM"%(mem/2), pwd):
+                raise error.TestFail("Could not set mem limit (memsw)")
             ps.stdin.write('\n')
             i = 0
             while ps.poll() == None:
@@ -207,17 +215,15 @@ class cgroup(test.test):
                 i += 1
                 time.sleep(1)
             if i > 60:
-                logging.error("test_memory: Memory filling failed (mem)")
                 ps.terminate()
-                return -1
+                raise error.TestFail("Memory filling failed (mem)")
             out = ps.stdout.readlines()
-            if len(out) < 2:
-                logging.error("test_memory: Process failed; output:\n%s", out)
-                return -1
+            if (len(out) < 2) or (ps.poll() != 0):
+                raise error.TestFail("Process failed (memsw); output:\n%s"
+                              "\nReturn: %d", out, ps.poll())
             if out[-1].startswith("PASS"):
-                logging.error("test_memory: Unexpected memory filling (memsw)",
+                raise error.TestFail("Unexpected memory filling (memsw)",
                               mem)
-                return -1
             else:
                 filled = int(out[-2].split()[1][:-1])
                 if mem/2 > 1.5*filled:
@@ -228,12 +234,10 @@ class cgroup(test.test):
                               "python overhead upto 1/3 (memsw)", mem/2, filled)
             logging.debug("test_memory: Memfill mem+swap cgroup passed")
 
-        # cleanup
-        logging.debug("test_memory: Cleanup")
-        if item.rm_cgroup(pwd):
-            logging.error("test_memory: Can't remove cgroup directory")
-            return -1
-        os.system("swapon -a")
+        ################################################
+        # CLEANUP
+        ################################################
+        cleanup()
+
+
 
-        logging.info("Leaving 'test_memory': PASSED")
-        return 0
diff --git a/client/tests/cgroup/cgroup_client.py b/client/tests/cgroup/cgroup_client.py
index ff098ef..03553c4 100755
--- a/client/tests/cgroup/cgroup_client.py
+++ b/client/tests/cgroup/cgroup_client.py
@@ -6,7 +6,7 @@ Interactive python script for testing cgroups
 @copyright: 2011 Red Hat Inc.
 @author: Lukas Doktor <ldoktor@xxxxxxxxxx>
 """
-import array, sys, time, math
+import array, sys, time, math, os
 
 def test_smoke():
     """
@@ -34,6 +34,7 @@ def test_memfill(size=1024):
         #for j in range(1024*1024):
         #    mem.append(0)
         print "TEST: %dM" % i
+        sys.stdout.flush()
     print "PASS: memfill (%dM)" % size
 
 
diff --git a/client/tests/cgroup/cgroup_common.py b/client/tests/cgroup/cgroup_common.py
index 3fd1cf7..6cc8089 100755
--- a/client/tests/cgroup/cgroup_common.py
+++ b/client/tests/cgroup/cgroup_common.py
@@ -135,13 +135,30 @@ class Cgroup:
         return self.set_cgroup(pid, self.root)
 
 
+    def get_prop(self, prop, pwd=None, supress=False):
+        """
+        Gets one line of the property value
+        @param prop: property name (file)
+        @param pwd: cgroup directory
+        @param supress: supress the output
+        @return: String value or None when FAILED
+        """
+        tmp = self.get_property(prop, pwd, supress)
+        if tmp:
+            if tmp[0][-1] == '\n':
+                tmp[0] = tmp[0][:-1]
+            return tmp[0]
+        else:
+            return None
+
+
     def get_property(self, prop, pwd=None, supress=False):
         """
         Gets the property value
         @param prop: property name (file)
         @param pwd: cgroup directory
         @param supress: supress the output
-        @return: String value or None when FAILED
+        @return: [] values or None when FAILED
         """
         if pwd == None:
             pwd = self.root
@@ -154,6 +171,32 @@ class Cgroup:
         return ret
 
 
+    def set_prop(self, prop, value, pwd=None, check=True):
+        """
+        Sets the one-line property value concerning the K,M,G postfix
+        @param prop: property name (file)
+        @param value: desired value
+        @param pwd: cgroup directory
+        @param check: check the value after setup
+        @return: 0 when PASSED
+        """
+        _value = value
+        try:
+            value = str(value)
+            if value[-1] == '\n':
+                value = value[:-1]
+            if value[-1] == 'K':
+                value = int(value[:-1]) * 1024
+            elif value[-1] == 'M':
+                value = int(value[:-1]) * 1048576
+            elif value[-1] == 'G':
+                value = int(value[:-1]) * 1073741824
+        except:
+            logging.error("cg.set_prop() fallback into cg.set_property.")
+            value = _value
+        return self.set_property(prop, value, pwd, check)
+
+
     def set_property(self, prop, value, pwd=None, check=True):
         """
         Sets the property value
-- 
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux