aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorliang gao <jean.gaoliang@huawei.com>2016-05-23 03:57:54 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-05-23 03:57:54 +0000
commit5c32b7daa67ea5696f49e168259116fc1d47e7e5 (patch)
treeb6a1505a936668047eae8a352c883c97b729e62d /tests/unit
parent379cbbefa8aebe63bb0a73a9d1439984ee6d7947 (diff)
parent54a393f4829e0de8b406dfc3e2d099b4394e5f38 (diff)
Merge "add support for RAMspeed"
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_ramspeed.py239
1 files changed, 239 insertions, 0 deletions
diff --git a/tests/unit/benchmark/scenarios/compute/test_ramspeed.py b/tests/unit/benchmark/scenarios/compute/test_ramspeed.py
new file mode 100644
index 000000000..3de84c74c
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/compute/test_ramspeed.py
@@ -0,0 +1,239 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.compute.ramspeed.Ramspeed
+
+import mock
+import unittest
+import json
+
+from yardstick.benchmark.scenarios.compute import ramspeed
+
+
+@mock.patch('yardstick.benchmark.scenarios.compute.ramspeed.ssh')
+class RamspeedTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ 'host': {
+ 'ip': '172.16.0.137',
+ 'user': 'root',
+ 'key_filename': "mykey.key"
+ }
+ }
+
+ self.result = {}
+
+ def test_ramspeed_successful_setup(self, mock_ssh):
+
+ r = ramspeed.Ramspeed({}, self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+
+ r.setup()
+ self.assertIsNotNone(r.client)
+ self.assertTrue(r.setup_done, True)
+
+ def test_ramspeed_successful__run_no_sla(self, mock_ssh):
+
+ options = {
+ "test_id": 1,
+ "load": 16,
+ "block_size": 32
+ }
+ args = {"options": options}
+ r = ramspeed.Ramspeed(args, self.ctx)
+
+ sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
+ 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
+ "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
+ 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
+ "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
+ 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
+ "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384, "Bandwidth(MBps)":\
+ 14128.94}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32768,\
+ "Bandwidth(MBps)": 8340.85}]}'
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+ r.run(self.result)
+ expected_result = json.loads(sample_output)
+ self.assertEqual(self.result, expected_result)
+
+ def test_ramspeed_successful_run_sla(self, mock_ssh):
+
+ options = {
+ "test_id": 1,
+ "load": 16,
+ "block_size": 32
+ }
+ args = {"options": options, "sla": {"min_bandwidth": 6000}}
+ r = ramspeed.Ramspeed(args, self.ctx)
+
+ sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
+ 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
+ "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
+ 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
+ "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
+ 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
+ "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384, "Bandwidth(MBps)":\
+ 14128.94}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32768,\
+ "Bandwidth(MBps)": 8340.85}]}'
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+ r.run(self.result)
+ expected_result = json.loads(sample_output)
+ self.assertEqual(self.result, expected_result)
+
+ def test_ramspeed_unsuccessful_run_sla(self, mock_ssh):
+ options = {
+ "test_id": 1,
+ "load": 8,
+ "block_size": 64
+ }
+ args = {"options": options, "sla": {"min_bandwidth": 100000}}
+ r = ramspeed.Ramspeed(args, self.ctx)
+
+ sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 1, "Bandwidth(MBps)": 5000.18}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 5000.89},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4,\
+ "Bandwidth(MBps)": 5000.56}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 8, "Bandwidth(MBps)": 19906.94}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32,\
+ "Bandwidth(MBps)": 19395.65}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 64, "Bandwidth(MBps)": 17623.14}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 128, "Bandwidth(MBps)": 17677.36},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 256, "Bandwidth(MBps)":\
+ 16113.49}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 512,\
+ "Bandwidth(MBps)": 14659.19}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 1024, "Bandwidth(MBps)": 14680.75}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 2048, "Bandwidth(MBps)": 14756.45},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4096, "Bandwidth(MBps)":\
+ 14604.44}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8192,\
+ "Bandwidth(MBps)": 14159.86}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 16384, "Bandwidth(MBps)": 14128.94}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+ self.assertRaises(AssertionError, r.run, self.result)
+
+ def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
+ options = {
+ "test_id": 1,
+ "load": 16,
+ "block_size": 32
+ }
+ args = {"options": options}
+ r = ramspeed.Ramspeed(args, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+ self.assertRaises(RuntimeError, r.run, self.result)
+
+ def test_ramspeed_mem_successful_run_no_sla(self, mock_ssh):
+ options = {
+ "test_id": 3,
+ "load": 16,
+ "block_size": 32,
+ "iteration": 1
+ }
+ args = {"options": options}
+ r = ramspeed.Ramspeed(args, self.ctx)
+
+ sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
+ "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
+ "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
+ "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
+ "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
+ "Bandwidth(MBps)": 9401.58}]}'
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+ r.run(self.result)
+ expected_result = json.loads(sample_output)
+ self.assertEqual(self.result, expected_result)
+
+ def test_ramspeed_mem_successful_run_sla(self, mock_ssh):
+ options = {
+ "test_id": 3,
+ "load": 16,
+ "block_size": 32,
+ "iteration": 1
+ }
+ args = {"options": options, "sla": {"min_bandwidth": 6000}}
+ r = ramspeed.Ramspeed(args, self.ctx)
+
+ sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
+ "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
+ "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
+ "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
+ "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
+ "Bandwidth(MBps)": 9401.58}]}'
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+ r.run(self.result)
+ expected_result = json.loads(sample_output)
+ self.assertEqual(self.result, expected_result)
+
+ def test_ramspeed_mem_unsuccessful_run_sla(self, mock_ssh):
+ options = {
+ "test_id": 3,
+ "load": 16,
+ "block_size": 32,
+ "iteration": 1
+ }
+ args = {"options": options, "sla": {"min_bandwidth": 86000}}
+ r = ramspeed.Ramspeed(args, self.ctx)
+
+ sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
+ "Bandwidth(MBps)": 4000.97}, {"Test_type": "INTEGER Scale:",\
+ "Bandwidth(MBps)": 4400.59}, {"Test_type": "INTEGER Add:",\
+ "Bandwidth(MBps)": 4300.48}, {"Test_type": "INTEGER Triad:",\
+ "Bandwidth(MBps)": 1300.27}, {"Test_type": "INTEGER AVERAGE:",\
+ "Bandwidth(MBps)": 2401.58}]}'
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+ self.assertRaises(AssertionError, r.run, self.result)
+
+ def test_ramspeed_unsuccessful_unknown_type_run(self, mock_ssh):
+ options = {
+ "test_id": 30,
+ "load": 16,
+ "block_size": 32
+ }
+ args = {'options': options}
+ r = ramspeed.Ramspeed(args, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (1, '', 'No such type_id: 30 for Ramspeed scenario')
+ self.assertRaises(RuntimeError, r.run, self.result)
+
+
+def main():
+ unittest.main()
+
+if __name__ == '__main__':
+ main()