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__)
19 class Lmbench(base.Scenario):
20 """Execute lmbench memory read latency benchmark in a host
23 stride - number of locations in memory between starts of array elements
27 stop_size - maximum array size to test (minimum value is 0.000512)
32 Results are accurate to the ~2-5 nanosecond range.
34 __scenario_type__ = "Lmbench"
36 TARGET_SCRIPT = "lmbench_benchmark.bash"
38 def __init__(self, context):
39 self.context = context
40 self.setup_done = False
44 self.target_script = pkg_resources.resource_filename(
45 "yardstick.benchmark.scenarios.compute",
46 Lmbench.TARGET_SCRIPT)
47 user = self.context.get("user", "ubuntu")
48 host = self.context.get("host", None)
49 key_filename = self.context.get('key_filename', "~/.ssh/id_rsa")
51 LOG.info("user:%s, host:%s", user, host)
52 self.client = ssh.SSH(user, host, key_filename=key_filename)
53 self.client.wait(timeout=600)
56 self.client.run("cat > ~/lmbench.sh",
57 stdin=open(self.target_script, 'rb'))
59 self.setup_done = True
62 """execute the benchmark"""
64 if not self.setup_done:
67 options = args['options']
68 stride = options.get('stride', 128)
69 stop_size = options.get('stop_size', 16)
71 cmd = "sudo bash lmbench.sh %d %d" % (stop_size, stride)
72 LOG.debug("Executing command: %s", cmd)
73 status, stdout, stderr = self.client.execute(cmd)
76 raise RuntimeError(stderr)
78 data = json.loads(stdout)
81 sla_max_latency = int(args['sla']['max_latency'])
83 latency = result['latency']
84 assert latency <= sla_max_latency, "latency %f > " \
85 "sla:max_latency(%f)" % (latency, sla_max_latency)
91 """internal test function"""
92 key_filename = pkg_resources.resource_filename('yardstick.resources',
93 'files/yardstick_key')
94 ctx = {'host': '172.16.0.137',
96 'key_filename': key_filename
99 logger = logging.getLogger('yardstick')
100 logger.setLevel(logging.DEBUG)
104 options = {'stride': 128, 'stop_size': 16}
106 args = {'options': options}
110 if __name__ == '__main__':