3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 # Unittest for yardstick.benchmark.scenarios.compute.memload.MEMLoad
14 from __future__ import absolute_import
19 from yardstick.benchmark.scenarios.compute import memload
22 @mock.patch('yardstick.benchmark.scenarios.compute.memload.ssh')
23 class MEMLoadTestCase(unittest.TestCase):
30 'key_filename': "mykey.key"
36 def test_memload_successful_setup(self, mock_ssh):
37 m = memload.MEMLoad({}, self.ctx)
38 mock_ssh.SSH().execute.return_value = (0, '', '')
41 self.assertIsNotNone(m.client)
42 self.assertTrue(m.setup_done)
44 def test_execute_command_success(self, mock_ssh):
45 m = memload.MEMLoad({}, self.ctx)
46 mock_ssh.SSH().execute.return_value = (0, '', '')
49 expected_result = 'abcdefg'
50 mock_ssh.SSH().execute.return_value = (0, expected_result, '')
51 result = m._execute_command("foo")
52 self.assertEqual(result, expected_result)
54 def test_execute_command_failed(self, mock_ssh):
55 m = memload.MEMLoad({}, self.ctx)
56 mock_ssh.SSH().execute.return_value = (0, '', '')
59 mock_ssh.SSH().execute.return_value = (127, '', 'Failed executing \
61 self.assertRaises(RuntimeError, m._execute_command,
64 def test_get_mem_usage_successful(self, mock_ssh):
69 args = {"options": options}
70 m = memload.MEMLoad(args, self.ctx)
71 mock_ssh.SSH().execute.return_value = (0, '', '')
74 output = self._read_file("memload_sample_output.txt")
75 mock_ssh.SSH().execute.return_value = (0, output, '')
76 result = m._get_mem_usage()
95 "buff/cache": "853528",
99 "available": "67252400"
104 self.assertEqual(result, expected_result)
106 def _read_file(self, filename):
107 curr_path = os.path.dirname(os.path.abspath(__file__))
108 output = os.path.join(curr_path, filename)
109 with open(output) as f:
110 sample_output = f.read()
118 if __name__ == '__main__':