From: Lukas Doktor <ldoktor@redhat.com>
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 [thread overview]
Message-ID: <1313411017-2873-5-git-send-email-ldoktor@redhat.com> (raw)
In-Reply-To: <1313411017-2873-1-git-send-email-ldoktor@redhat.com>
Signed-off-by: Lukas Doktor <ldoktor@redhat.com>
---
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 <ldoktor@redhat.com>
"""
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()
--
1.7.6
next prev parent reply other threads:[~2011-08-15 12:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-15 12:23 [autotest][PATCH] cgroup test + modifications Lukas Doktor
2011-08-15 12:23 ` [PATCH 1/4] [NEW] cgroup test * general smoke_test + module dependend subtests (memory test included) * library for future use in other tests (kvm) Lukas Doktor
2011-08-18 11:33 ` Jiri Zupka
2011-08-21 9:15 ` Lukáš Doktor
2011-08-15 12:23 ` [PATCH 2/4] bugfixies Lukas Doktor
2011-08-15 12:23 ` [PATCH 3/4] cpuset test Lukas Doktor
2011-08-15 12:23 ` Lukas Doktor [this message]
2011-09-01 8:03 ` [autotest][PATCH] cgroup test + modifications Jan Stancek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1313411017-2873-5-git-send-email-ldoktor@redhat.com \
--to=ldoktor@redhat.com \
--cc=autotest@test.kernel.org \
--cc=fyang@redhat.com \
--cc=jzupka@redhat.com \
--cc=kvm-autotest@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=lmr@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox