From patchwork Mon Aug 15 12:23:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?THVrw6HFoSBEb2t0b3I=?= X-Patchwork-Id: 1067182 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7FCPbgB012565 for ; Mon, 15 Aug 2011 12:25:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753133Ab1HOMZe (ORCPT ); Mon, 15 Aug 2011 08:25:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12412 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753149Ab1HOMZd (ORCPT ); Mon, 15 Aug 2011 08:25:33 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7FCPXAv025328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 15 Aug 2011 08:25:33 -0400 Received: from dhcp-26-193.brq.redhat.com (dhcp-27-187.brq.redhat.com [10.34.27.187]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p7FCPLnj019749; Mon, 15 Aug 2011 08:25:31 -0400 From: Lukas Doktor To: autotest@test.kernel.org, kvm@vger.kernel.org, kvm-autotest@redhat.com, fyang@redhat.com, lmr@redhat.com, ldoktor@redhat.com, jzupka@redhat.com Subject: [PATCH 4/4] [FIX] Use file instead of PIPE in memfill test (problem with sync) Date: Mon, 15 Aug 2011 14:23:37 +0200 Message-Id: <1313411017-2873-5-git-send-email-ldoktor@redhat.com> In-Reply-To: <1313411017-2873-1-git-send-email-ldoktor@redhat.com> References: <1313411017-2873-1-git-send-email-ldoktor@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 15 Aug 2011 12:25:51 +0000 (UTC) Signed-off-by: Lukas Doktor --- client/tests/cgroup/cgroup.py | 44 +++++++++++++++--------- client/tests/cgroup/cgroup_client.py | 61 ++++++++++++++++++++------------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/client/tests/cgroup/cgroup.py b/client/tests/cgroup/cgroup.py index dc5a1b3..0f56ad5 100755 --- a/client/tests/cgroup/cgroup.py +++ b/client/tests/cgroup/cgroup.py @@ -4,6 +4,7 @@ import os, logging import time from cgroup_common import Cgroup as CG from cgroup_common import CgroupModules +from tempfile import NamedTemporaryFile class cgroup(test.test): """ @@ -13,7 +14,6 @@ class cgroup(test.test): _client = "" modules = CgroupModules() - def run_once(self): """ Try to access different resources which are restricted by cgroup. @@ -80,6 +80,7 @@ class cgroup(test.test): err += "\nCan't remove cgroup directory" os.system("swapon -a") + if err: if supress: logging.warn("Some parts of cleanup failed%s" % err) @@ -126,6 +127,8 @@ class cgroup(test.test): logging.info("'memsw' not supported") os.system("swapoff -a") memsw = False + outf = NamedTemporaryFile('w+', prefix="cgroup_client-", + dir="/tmp") logging.debug("test_memory: Initializition passed") ################################################ @@ -133,7 +136,7 @@ class cgroup(test.test): # Should pass ################################################ logging.debug("test_memory: Memfill WO cgroup") - ps = item.test("memfill %d" % mem) + ps = item.test("memfill %d %s" % (mem, outf.name)) ps.stdin.write('\n') i = 0 while ps.poll() == None: @@ -144,10 +147,12 @@ class cgroup(test.test): if i > 60: ps.terminate() raise error.TestFail("Memory filling failed (WO cgroup)") - out = ps.stdout.readlines() + outf.seek(0) + outf.flush() + out = outf.readlines() if (len(out) < 2) or (ps.poll() != 0): raise error.TestFail("Process failed (WO cgroup); output:\n%s" - "\nReturn: %d", out, ps.poll()) + "\nReturn: %d" % (out, ps.poll())) if not out[-1].startswith("PASS"): raise error.TestFail("Unsuccessful memory filling " "(WO cgroup)") @@ -159,7 +164,7 @@ class cgroup(test.test): # WO memsw: should fail (SIGKILL) ################################################ logging.debug("test_memory: Memfill mem only limit") - ps = item.test("memfill %d" % mem) + ps = item.test("memfill %d %s" % (mem, outf.name)) if item.set_cgroup(ps.pid, pwd): raise error.TestFail("Could not set cgroup") if item.set_prop("memory.limit_in_bytes", ("%dM" % (mem/2)), pwd): @@ -167,17 +172,19 @@ class cgroup(test.test): ps.stdin.write('\n') i = 0 while ps.poll() == None: - if i > 60: + if i > 120: break i += 1 time.sleep(1) - if i > 60: + if i > 120: ps.terminate() raise error.TestFail("Memory filling failed (mem)") - out = ps.stdout.readlines() - if (len(out)) < 2 or (ps.poll() != 0): + outf.seek(0) + outf.flush() + out = outf.readlines() + if (len(out) < 2): raise error.TestFail("Process failed (mem); output:\n%s" - "\nReturn: %d", out, ps.poll()) + "\nReturn: %d" % (out, ps.poll())) if memsw: if not out[-1].startswith("PASS"): logging.error("test_memory: cgroup_client.py returned %d; " @@ -199,10 +206,11 @@ class cgroup(test.test): ################################################ # Fill the memory with 1/2 memory+swap limit # Should fail + # (memory.limit_in_bytes have to be set prior to this test) ################################################ - logging.debug("test_memory: Memfill mem + swap limit") if memsw: - ps = item.test("memfill %d" % mem) + logging.debug("test_memory: Memfill mem + swap limit") + ps = item.test("memfill %d %s" % (mem, outf.name)) if item.set_cgroup(ps.pid, pwd): raise error.TestFail("Could not set cgroup (memsw)") if item.set_prop("memory.memsw.limit_in_bytes", "%dM"%(mem/2), pwd): @@ -210,17 +218,19 @@ class cgroup(test.test): ps.stdin.write('\n') i = 0 while ps.poll() == None: - if i > 60: + if i > 120: break i += 1 time.sleep(1) - if i > 60: + if i > 120: ps.terminate() raise error.TestFail("Memory filling failed (mem)") - out = ps.stdout.readlines() - if (len(out) < 2) or (ps.poll() != 0): + outf.seek(0) + outf.flush() + out = outf.readlines() + if (len(out) < 2): raise error.TestFail("Process failed (memsw); output:\n%s" - "\nReturn: %d", out, ps.poll()) + "\nReturn: %d" % (out, ps.poll())) if out[-1].startswith("PASS"): raise error.TestFail("Unexpected memory filling (memsw)", mem) diff --git a/client/tests/cgroup/cgroup_client.py b/client/tests/cgroup/cgroup_client.py index 03553c4..ab7311a 100755 --- a/client/tests/cgroup/cgroup_client.py +++ b/client/tests/cgroup/cgroup_client.py @@ -7,8 +7,9 @@ Interactive python script for testing cgroups @author: Lukas Doktor """ import array, sys, time, math, os +from tempfile import mktemp -def test_smoke(): +def test_smoke(args): """ SIGSTOP the process and after SIGCONT exits. """ @@ -18,12 +19,20 @@ def test_smoke(): print "PASS: smoke" -def test_memfill(size=1024): +def test_memfill(args): """ SIGSTOP and after SIGCONT fills the memory up to size size. """ + size = 1024 + f = sys.stdout + if args: + size = int(args[0]) + if len(args) > 1: + f = open(args[1], 'w', 0) print "TEST: memfill (%dM)" % size - print "TEST: wait for input" + print "Redirecting to: %s" % f.name + f.write("TEST: memfill (%dM)\n" % size) + f.write("TEST: wait for input\n") raw_input() mem = array.array('B') buf = "" @@ -31,14 +40,16 @@ def test_memfill(size=1024): buf += '\x00' for i in range(size): mem.fromstring(buf) - #for j in range(1024*1024): - # mem.append(0) - print "TEST: %dM" % i - sys.stdout.flush() - print "PASS: memfill (%dM)" % size + f.write("TEST: %dM\n" % i) + try: + f.flush() + os.fsync(f) + except: + pass + f.write("PASS: memfill (%dM)\n" % size) -def test_cpu(): +def test_cpu(args): """ Stress the CPU """ @@ -50,6 +61,16 @@ def test_cpu(): math.factorial(i) +def test_devices(args): + if args: + if args[0] == "write": + test_devices_write() + else: + test_devices_read() + else: + test_devices_read() + + def test_devices_read(): """ Inf read from /dev/zero @@ -90,27 +111,19 @@ def main(): Main (infinite) loop. """ if len(sys.argv) < 2: - print "FAIL: Incorrect usage" + print "FAIL: Incorrect usage (%s)" % sys.argv return -1 + args = sys.argv[2:] if sys.argv[1] == "smoke": - test_smoke() + test_smoke(args) elif sys.argv[1] == "memfill": - if len(sys.argv) > 2: - test_memfill(int(sys.argv[2])) - else: - test_memfill() + test_memfill(args) elif sys.argv[1] == "cpu": - test_cpu() + test_cpu(args) elif sys.argv[1] == "devices": - if len(sys.argv) > 2: - if (sys.argv[2] == "write"): - test_devices_write() - else: - test_devices_read() - else: - test_devices_read() + test_devices(args) else: - print "FAIL: No test specified" + print "FAIL: No test specified (%s)" % sys.argv if __name__ == "__main__": main()