[PATCH 1/3] [kvm-autotest] tests.cgroup: Add TestFreezer
This subtest tests the 'freezer.state' cgroup functionality. It assignes the virtual machine into freezer cgroup, schedule cpu-intensive work and verifies the correct function in both states (frozen/thawed) during long and short period of time. * Adds TestFreezer (freezer) test * Adds assign_vm_into_cgroup() function * Code cleanup Signed-off-by: Lukas Doktor --- client/tests/cgroup/cgroup_common.py | 16 +--- client/tests/kvm/tests/cgroup.py | 158 +++--- 2 files changed, 145 insertions(+), 29 deletions(-) diff --git a/client/tests/cgroup/cgroup_common.py b/client/tests/cgroup/cgroup_common.py index 0c86398..7d5daf2 100755 --- a/client/tests/cgroup/cgroup_common.py +++ b/client/tests/cgroup/cgroup_common.py @@ -6,25 +6,11 @@ Helpers for cgroup testing. @copyright: 2011 Red Hat Inc. @author: Lukas Doktor """ -import logging, os, shutil, subprocess, time, traceback +import logging, os, shutil, subprocess, time from tempfile import mkdtemp from autotest_lib.client.bin import utils from autotest_lib.client.common_lib import error -def _traceback(name, exc_info): -""" -Formats traceback into lines "name: line\nname: line" -@param name: desired line preposition -@param exc_info: sys.exc_info of the exception -@return: string which contains beautifully formatted exception -""" -out = "\n" -for line in traceback.format_exception(exc_info[0], exc_info[1], - exc_info[2]): -out += "%s: %s" % (name, line) -return out - - class Cgroup(object): """ Cgroup handling class. diff --git a/client/tests/kvm/tests/cgroup.py b/client/tests/kvm/tests/cgroup.py index f31ef0c..fd36f9a 100644 --- a/client/tests/kvm/tests/cgroup.py +++ b/client/tests/kvm/tests/cgroup.py @@ -40,6 +40,20 @@ def run_cgroup(test, params, env): raise error.TestFail("WM [%s] had to be recreated" % err[:-2]) +def assign_vm_into_cgroup(vm, cgroup, pwd=None): +""" +Assigns all threads of VM into cgroup +@param vm: desired VM +@param cgroup: cgroup handler +@param pwd: desired cgroup's pwd, cgroup index or None for root cgroup +""" +if isinstance(pwd, int): +pwd = cgroup.cgroups[pwd] +cgroup.set_cgroup(vm.get_shell_pid(), pwd) +for pid in utils.get_children_pids(vm.get_shell_pid()): +cgroup.set_cgroup(int(pid), pwd) + + def distance(actual, reference): """ Absolute value of relative distance of two numbers @@ -118,10 +132,12 @@ def run_cgroup(test, params, env): utils.system("dd if=/dev/zero of=%s bs=1M count=8 &>/dev/null" % (host_file.name)) ret_file = host_file -logging.debug("add_file_drive: new file %s as drive", host_file.name) +logging.debug("add_file_drive: new file %s as drive", + host_file.name) else: ret_file = None -logging.debug("add_file_drive: using file %s as drive", host_file.name) +logging.debug("add_file_drive: using file %s as drive", + host_file.name) out = vm.monitor.cmd("pci_add auto storage file=%s,if=%s,snapshot=off," "cache=off" % (host_file.name, driver)) @@ -277,10 +293,7 @@ def run_cgroup(test, params, env): blkio.initialize(self.modules) for i in range(2): pwd.append(blkio.mk_cgroup()) -blkio.set_cgroup(self.vms[i].get_shell_pid(), pwd[i]) -# Move all existing threads into cgroup -for tmp in utils.get_children_pids(self.vms[i].get_shell_pid()): -blkio.set_cgroup(int(tmp), pwd[i]) +assign_vm_into_cgroup(self.vms[i], blkio, pwd[i]) self.blkio.set_property("blkio.weight", 100, pwd[0]) self.blkio.set_property("blkio.weight", 1000, pwd[1]) @@ -475,9 +488,7 @@ def run_cgroup(test, params, env): for i in range(len(self.cgroups)): logging.info("Limiting speed to: %s", (self.speeds[i])) # Assign all threads of vm -self.cgroup.set_cgroup(self.vm.get_shell_pid(), self.cgroups[i]) -for pid in utils.get_children_pids(self.vm.get_shell_pid()): -self.cgroup.set_cgroup(int(pid), self.cgroups[i]) +assign_vm_into_cgroup(self.vm, self.cgroup, self.cgroups[i]) # Standard test-time is 60s. If the slice time is less than 30s, # test-time is prolonged to 30s per slice. @@ -668,10 +679,7 @@ def run_cgroup(test, params, env): self.cgroup.initialize(self.modules) self.cgroup.mk_cgroup() -self.cgroup.set_cgroup(self.vm.get_shell_pid(), - self.cgroup.cgroups[0]) -for pid in
[PATCH] [kvm-autotest] tests.cgroup: Add TestFreezer
This subtest tests the 'freezer.state' cgroup functionality. It assignes the virtual machine into freezer cgroup, schedule cpu-intensive work and verifies the correct function in both states (frozen/thawed) during long and short period of time. * Adds TestFreezer (freezer) test * Adds assign_vm_into_cgroup() function * Code cleanup Signed-off-by: Lukas Doktor --- client/tests/cgroup/cgroup_common.py | 16 +--- client/tests/kvm/tests/cgroup.py | 159 +++--- 2 files changed, 146 insertions(+), 29 deletions(-) diff --git a/client/tests/cgroup/cgroup_common.py b/client/tests/cgroup/cgroup_common.py index 0c86398..7d5daf2 100755 --- a/client/tests/cgroup/cgroup_common.py +++ b/client/tests/cgroup/cgroup_common.py @@ -6,25 +6,11 @@ Helpers for cgroup testing. @copyright: 2011 Red Hat Inc. @author: Lukas Doktor """ -import logging, os, shutil, subprocess, time, traceback +import logging, os, shutil, subprocess, time from tempfile import mkdtemp from autotest_lib.client.bin import utils from autotest_lib.client.common_lib import error -def _traceback(name, exc_info): -""" -Formats traceback into lines "name: line\nname: line" -@param name: desired line preposition -@param exc_info: sys.exc_info of the exception -@return: string which contains beautifully formatted exception -""" -out = "\n" -for line in traceback.format_exception(exc_info[0], exc_info[1], - exc_info[2]): -out += "%s: %s" % (name, line) -return out - - class Cgroup(object): """ Cgroup handling class. diff --git a/client/tests/kvm/tests/cgroup.py b/client/tests/kvm/tests/cgroup.py index f31ef0c..b482bce 100644 --- a/client/tests/kvm/tests/cgroup.py +++ b/client/tests/kvm/tests/cgroup.py @@ -40,6 +40,20 @@ def run_cgroup(test, params, env): raise error.TestFail("WM [%s] had to be recreated" % err[:-2]) +def assign_vm_into_cgroup(vm, cgroup, pwd=None): +""" +Assigns all threads of VM into cgroup +@param vm: desired VM +@param cgroup: cgroup handler +@param pwd: desired cgroup's pwd, cgroup index or None for root cgroup +""" +if isinstance(pwd, int): +pwd = cgroup.cgroups[pwd] +cgroup.set_cgroup(vm.get_shell_pid(),pwd) +for pid in utils.get_children_pids(vm.get_shell_pid()): +cgroup.set_cgroup(int(pid), pwd) + + def distance(actual, reference): """ Absolute value of relative distance of two numbers @@ -118,10 +132,12 @@ def run_cgroup(test, params, env): utils.system("dd if=/dev/zero of=%s bs=1M count=8 &>/dev/null" % (host_file.name)) ret_file = host_file -logging.debug("add_file_drive: new file %s as drive", host_file.name) +logging.debug("add_file_drive: new file %s as drive", + host_file.name) else: ret_file = None -logging.debug("add_file_drive: using file %s as drive", host_file.name) +logging.debug("add_file_drive: using file %s as drive", + host_file.name) out = vm.monitor.cmd("pci_add auto storage file=%s,if=%s,snapshot=off," "cache=off" % (host_file.name, driver)) @@ -277,10 +293,7 @@ def run_cgroup(test, params, env): blkio.initialize(self.modules) for i in range(2): pwd.append(blkio.mk_cgroup()) -blkio.set_cgroup(self.vms[i].get_shell_pid(), pwd[i]) -# Move all existing threads into cgroup -for tmp in utils.get_children_pids(self.vms[i].get_shell_pid()): -blkio.set_cgroup(int(tmp), pwd[i]) +assign_vm_into_cgroup(self.vms[i], blkio, pwd[i]) self.blkio.set_property("blkio.weight", 100, pwd[0]) self.blkio.set_property("blkio.weight", 1000, pwd[1]) @@ -475,9 +488,7 @@ def run_cgroup(test, params, env): for i in range(len(self.cgroups)): logging.info("Limiting speed to: %s", (self.speeds[i])) # Assign all threads of vm -self.cgroup.set_cgroup(self.vm.get_shell_pid(), self.cgroups[i]) -for pid in utils.get_children_pids(self.vm.get_shell_pid()): -self.cgroup.set_cgroup(int(pid), self.cgroups[i]) +assign_vm_into_cgroup(self.vm, self.cgroup, self.cgroups[i]) # Standard test-time is 60s. If the slice time is less than 30s, # test-time is prolonged to 30s per slice. @@ -668,10 +679,7 @@ def run_cgroup(test, params, env): self.cgroup.initialize(self.modules) self.cgroup.mk_cgroup() -self.cgroup.set_cgroup(self.vm.get_shell_pid(), - self.cgroup.cgroups[0]) -for pid in u
[kvm-autotest] tests.cgroup: Add TestFreezer
This subtest tests the 'freezer.state' cgroup functionality. It assignes the virtual machine into freezer cgroup, schedule cpu-intensive work and verifies the correct function in both states (frozen/thawed) during long and short period of time. * Adds TestFreezer (freezer) test * Adds assign_vm_into_cgroup() function * Code cleanup Signed-off-by: Lukas Doktor ldok...@redhat.com Please see the pull request for updates: https://github.com/autotest/autotest/pull/55 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html