1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 import yardstick.ssh as ssh
14 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
17 LOG.setLevel(logging.DEBUG)
20 class Lmbench(base.Scenario):
21 """Execute lmbench memory read latency benchmark in a host
24 stride - number of locations in memory between starts of array elements
28 stop_size - maximum array size to test (minimum value is 0.000512)
33 Results are accurate to the ~2-5 nanosecond range.
35 __scenario_type__ = "Lmbench"
37 TARGET_SCRIPT = "lmbench_benchmark.bash"
39 def __init__(self, context):
40 self.context = context
41 self.setup_done = False
45 self.target_script = pkg_resources.resource_filename(
46 "yardstick.benchmark.scenarios.compute",
47 Lmbench.TARGET_SCRIPT)
48 user = self.context.get("user", "ubuntu")
49 host = self.context.get("host", None)
50 key_filename = self.context.get('key_filename', "~/.ssh/id_rsa")
52 LOG.debug("user:%s, host:%s", user, host)
53 self.client = ssh.SSH(user, host, key_filename=key_filename)
54 self.client.wait(timeout=600)
57 self.client.run("cat > ~/lmbench.sh",
58 stdin=open(self.target_script, 'rb'))
60 self.setup_done = True
63 """execute the benchmark"""
65 if not self.setup_done:
68 options = args['options']
69 stride = options.get('stride', 128)
70 stop_size = options.get('stop_size', 16)
72 cmd = "sudo bash lmbench.sh %d %d" % (stop_size, stride)
73 LOG.debug("Executing command: %s", cmd)
74 status, stdout, stderr = self.client.execute(cmd)
77 raise RuntimeError(stderr)
79 data = json.loads(stdout)
82 sla_max_latency = int(args['sla']['max_latency'])
84 latency = result['latency']
85 assert latency <= sla_max_latency, "latency %f > " \
86 "sla:max_latency(%f)" % (latency, sla_max_latency)
92 """internal test function"""
93 key_filename = pkg_resources.resource_filename('yardstick.resources',
94 'files/yardstick_key')
95 ctx = {'host': '172.16.0.137',
97 'key_filename': key_filename
100 logger = logging.getLogger('yardstick')
101 logger.setLevel(logging.DEBUG)
105 options = {'stride': 128, 'stop_size': 16}
107 args = {'options': options}
111 if __name__ == '__main__':