ia64/xen-unstable
changeset 8358:f85f52b508c3
Added a stress test for the Xenstore-Python interface layer.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | emellor@leeni.uk.xensource.com |
---|---|
date | Wed Dec 14 11:54:39 2005 +0000 (2005-12-14) |
parents | 62d9ac63e7f5 |
children | a55d4a167203 |
files | tools/python/setup.py tools/python/xen/xend/xenstore/tests/__init__.py tools/python/xen/xend/xenstore/tests/stress_xs.py |
line diff
1.1 --- a/tools/python/setup.py Tue Dec 13 18:08:26 2005 +0000 1.2 +++ b/tools/python/setup.py Wed Dec 14 11:54:39 2005 +0000 1.3 @@ -46,6 +46,7 @@ setup(name = 'xen', 1.4 1.5 'xen.xend.tests', 1.6 'xen.xend.server.tests', 1.7 + 'xen.xend.xenstore.tests', 1.8 'xen.xm.tests' 1.9 ], 1.10 ext_package = "xen.lowlevel",
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/tools/python/xen/xend/xenstore/tests/__init__.py Wed Dec 14 11:54:39 2005 +0000 2.3 @@ -0,0 +1,2 @@ 2.4 + 2.5 +
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/tools/python/xen/xend/xenstore/tests/stress_xs.py Wed Dec 14 11:54:39 2005 +0000 3.3 @@ -0,0 +1,121 @@ 3.4 +# This library is free software; you can redistribute it and/or 3.5 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 3.6 +# License as published by the Free Software Foundation. 3.7 +# 3.8 +# This library is distributed in the hope that it will be useful, 3.9 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 3.10 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 3.11 +# Lesser General Public License for more details. 3.12 +# 3.13 +# You should have received a copy of the GNU Lesser General Public 3.14 +# License along with this library; if not, write to the Free Software 3.15 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 3.16 +# 3.17 +# Copyright (c) 2005 XenSource Ltd 3.18 + 3.19 + 3.20 +import random 3.21 +import sys 3.22 +import threading 3.23 +import time 3.24 + 3.25 +import xen.lowlevel.xs 3.26 + 3.27 +from xen.xend.xenstore import xsutil 3.28 +from xen.xend.xenstore.xstransact import xstransact 3.29 +from xen.xend.xenstore.xswatch import xswatch 3.30 + 3.31 + 3.32 +PATH = '/tool/stress_xs' 3.33 + 3.34 + 3.35 +def stress(): 3.36 + xstransact.Remove(PATH) 3.37 + xstransact.Mkdir(PATH) 3.38 + 3.39 + xswatch(PATH, watch_callback) 3.40 + 3.41 + def do(f): 3.42 + t = threading.Thread(target=stress_write) 3.43 + t.setDaemon(True) 3.44 + t.start() 3.45 + 3.46 + do(stress_write) 3.47 + do(stress_get_domain_path) 3.48 + do(stress_get_domain_path_xsutil) 3.49 + do(stress_open_close) 3.50 + 3.51 + while True: 3.52 + # Wait for Ctrl-C. 3.53 + time.sleep(100000000) 3.54 + 3.55 + 3.56 +def stress_write(): 3.57 + xstransact.Write(PATH, 'key', '1') 3.58 + while True: 3.59 + val = xstransact.Gather(PATH, ('key', int)) 3.60 + xstransact.Store(PATH, ('key', val + 1)) 3.61 + 3.62 + random_sleep() 3.63 + 3.64 + 3.65 +def stress_get_domain_path(): 3.66 + xs_handle = xen.lowlevel.xs.xs() 3.67 + 3.68 + domid = 0 3.69 + while True: 3.70 + xs_handle.get_domain_path(domid) 3.71 + domid += 1 3.72 + 3.73 + random_sleep() 3.74 + 3.75 + 3.76 +def stress_get_domain_path_xsutil(): 3.77 + domid = 0 3.78 + while True: 3.79 + xsutil.GetDomainPath(domid) 3.80 + domid += 1 3.81 + 3.82 + random_sleep() 3.83 + 3.84 + 3.85 +def stress_open_close(): 3.86 + while True: 3.87 + xs_handle = xen.lowlevel.xs.xs() 3.88 + 3.89 + try: 3.90 + try: 3.91 + trans = xs_handle.transaction_start() 3.92 + val = int(xs_handle.read(trans, PATH + '/key')) 3.93 + xs_handle.write(trans, PATH + '/key', str(val + 1)) 3.94 + xs_handle.transaction_end(trans, False) 3.95 + except: 3.96 + xs_handle.transaction_end(trans, True) 3.97 + 3.98 + random_sleep() 3.99 + finally: 3.100 + del xs_handle 3.101 + 3.102 + 3.103 +def watch_callback(path): 3.104 + random_sleep() 3.105 + return True 3.106 + 3.107 + 3.108 +def random_sleep(): 3.109 + d = random.randint(-50000, 500) 3.110 + if d > 0: 3.111 + time.sleep(d / 1000.0) 3.112 + 3.113 + 3.114 +def main(argv = None): 3.115 + if argv is None: 3.116 + argv = sys.argv 3.117 + 3.118 + stress() 3.119 + 3.120 + return 0 3.121 + 3.122 + 3.123 +if __name__ == "__main__": 3.124 + sys.exit(main())