jadmanski | a9894d0 | 2009-08-21 16:49:48 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
Aviv Keshet | 39164ca | 2013-03-27 15:08:33 -0700 | [diff] [blame] | 2 | #pylint: disable-msg=C0111 |
mbligh | 234a84f | 2008-11-20 19:57:43 +0000 | [diff] [blame] | 3 | """Unit Tests for autotest.client.common_lib.test""" |
| 4 | |
| 5 | __author__ = 'gps@google.com (Gregory P. Smith)' |
| 6 | |
Keith Haddow | d804bc8 | 2016-03-15 17:16:03 -0700 | [diff] [blame^] | 7 | import json |
| 8 | import tempfile |
mbligh | 234a84f | 2008-11-20 19:57:43 +0000 | [diff] [blame] | 9 | import unittest |
mbligh | 234a84f | 2008-11-20 19:57:43 +0000 | [diff] [blame] | 10 | import common |
Scott Zawalski | 91493c8 | 2013-01-25 16:15:20 -0500 | [diff] [blame] | 11 | from autotest_lib.client.common_lib import test |
mbligh | 234a84f | 2008-11-20 19:57:43 +0000 | [diff] [blame] | 12 | from autotest_lib.client.common_lib.test_utils import mock |
Aviv Keshet | 39164ca | 2013-03-27 15:08:33 -0700 | [diff] [blame] | 13 | from autotest_lib.client.common_lib import error as common_lib_error |
mbligh | 234a84f | 2008-11-20 19:57:43 +0000 | [diff] [blame] | 14 | |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 15 | class TestTestCase(unittest.TestCase): |
mbligh | 234a84f | 2008-11-20 19:57:43 +0000 | [diff] [blame] | 16 | class _neutered_base_test(test.base_test): |
| 17 | """A child class of base_test to avoid calling the constructor.""" |
| 18 | def __init__(self, *args, **kwargs): |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 19 | class MockJob(object): |
| 20 | pass |
| 21 | class MockProfilerManager(object): |
| 22 | def active(self): |
| 23 | return False |
mbligh | c6bf601 | 2009-10-02 00:02:15 +0000 | [diff] [blame] | 24 | def present(self): |
| 25 | return True |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 26 | self.job = MockJob() |
showard | a6082ef | 2009-10-12 20:25:44 +0000 | [diff] [blame] | 27 | self.job.default_profile_only = False |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 28 | self.job.profilers = MockProfilerManager() |
Scott Zawalski | 91493c8 | 2013-01-25 16:15:20 -0500 | [diff] [blame] | 29 | self.job.test_retry = 0 |
jadmanski | a93fbca | 2009-08-21 15:34:04 +0000 | [diff] [blame] | 30 | self._new_keyval = False |
mbligh | 5e703a2 | 2009-06-15 22:00:12 +0000 | [diff] [blame] | 31 | self.iteration = 0 |
mbligh | 742ae42 | 2009-05-13 20:46:41 +0000 | [diff] [blame] | 32 | self.before_iteration_hooks = [] |
| 33 | self.after_iteration_hooks = [] |
| 34 | |
mbligh | 234a84f | 2008-11-20 19:57:43 +0000 | [diff] [blame] | 35 | |
| 36 | def setUp(self): |
| 37 | self.god = mock.mock_god() |
| 38 | self.test = self._neutered_base_test() |
mbligh | 234a84f | 2008-11-20 19:57:43 +0000 | [diff] [blame] | 39 | |
| 40 | |
| 41 | def tearDown(self): |
| 42 | self.god.unstub_all() |
| 43 | |
| 44 | |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 45 | |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 46 | class Test_base_test_execute(TestTestCase): |
| 47 | # Test the various behaviors of the base_test.execute() method. |
| 48 | def setUp(self): |
| 49 | TestTestCase.setUp(self) |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 50 | self.god.stub_function(self.test, 'run_once_profiling') |
| 51 | self.god.stub_function(self.test, 'postprocess') |
mbligh | 32cb5b4 | 2009-05-01 23:05:09 +0000 | [diff] [blame] | 52 | self.god.stub_function(self.test, 'process_failed_constraints') |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 53 | |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 54 | |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 55 | def test_call_run_once(self): |
| 56 | # setup |
| 57 | self.god.stub_function(self.test, 'drop_caches_between_iterations') |
| 58 | self.god.stub_function(self.test, 'run_once') |
| 59 | self.god.stub_function(self.test, 'postprocess_iteration') |
mbligh | 7af0997 | 2009-04-17 22:17:08 +0000 | [diff] [blame] | 60 | self.god.stub_function(self.test, 'analyze_perf_constraints') |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 61 | before_hook = self.god.create_mock_function('before_hook') |
| 62 | after_hook = self.god.create_mock_function('after_hook') |
mbligh | 742ae42 | 2009-05-13 20:46:41 +0000 | [diff] [blame] | 63 | self.test.register_before_iteration_hook(before_hook) |
| 64 | self.test.register_after_iteration_hook(after_hook) |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 65 | |
| 66 | # tests the test._call_run_once implementation |
| 67 | self.test.drop_caches_between_iterations.expect_call() |
showard | d4ead17 | 2009-05-01 00:08:56 +0000 | [diff] [blame] | 68 | before_hook.expect_call(self.test) |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 69 | self.test.run_once.expect_call(1, 2, arg='val') |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 70 | self.test.postprocess_iteration.expect_call() |
mbligh | 7af0997 | 2009-04-17 22:17:08 +0000 | [diff] [blame] | 71 | self.test.analyze_perf_constraints.expect_call([]) |
Eric Li | daf6ff0 | 2011-03-01 15:31:31 -0800 | [diff] [blame] | 72 | after_hook.expect_call(self.test) |
jadmanski | a93fbca | 2009-08-21 15:34:04 +0000 | [diff] [blame] | 73 | self.test._call_run_once([], False, None, (1, 2), {'arg': 'val'}) |
showard | d4ead17 | 2009-05-01 00:08:56 +0000 | [diff] [blame] | 74 | self.god.check_playback() |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 75 | |
| 76 | |
Eric Li | daf6ff0 | 2011-03-01 15:31:31 -0800 | [diff] [blame] | 77 | def test_call_run_once_with_exception(self): |
| 78 | # setup |
| 79 | self.god.stub_function(self.test, 'drop_caches_between_iterations') |
| 80 | self.god.stub_function(self.test, 'run_once') |
| 81 | before_hook = self.god.create_mock_function('before_hook') |
| 82 | after_hook = self.god.create_mock_function('after_hook') |
| 83 | self.test.register_before_iteration_hook(before_hook) |
| 84 | self.test.register_after_iteration_hook(after_hook) |
| 85 | error = Exception('fail') |
| 86 | |
| 87 | # tests the test._call_run_once implementation |
| 88 | self.test.drop_caches_between_iterations.expect_call() |
| 89 | before_hook.expect_call(self.test) |
| 90 | self.test.run_once.expect_call(1, 2, arg='val').and_raises(error) |
| 91 | after_hook.expect_call(self.test) |
| 92 | try: |
| 93 | self.test._call_run_once([], False, None, (1, 2), {'arg': 'val'}) |
| 94 | except: |
| 95 | pass |
| 96 | self.god.check_playback() |
| 97 | |
| 98 | |
Scott Zawalski | 91493c8 | 2013-01-25 16:15:20 -0500 | [diff] [blame] | 99 | def _setup_failed_test_calls(self, fail_count, error): |
| 100 | """ |
| 101 | Set up failed test calls for use with call_run_once_with_retry. |
| 102 | |
| 103 | @param fail_count: The amount of times to mock a failure. |
| 104 | @param error: The error to raise while failing. |
| 105 | """ |
| 106 | self.god.stub_function(self.test.job, 'record') |
| 107 | self.god.stub_function(self.test, '_call_run_once') |
| 108 | # tests the test._call_run_once implementation |
| 109 | for run in xrange(0, fail_count): |
| 110 | self.test._call_run_once.expect_call([], False, None, (1, 2), |
| 111 | {'arg': 'val'}).and_raises( |
| 112 | error) |
| 113 | info_str = 'Run %s failed with %s' % (run, error) |
| 114 | # On the final run we do not emit this message. |
Aviv Keshet | 39164ca | 2013-03-27 15:08:33 -0700 | [diff] [blame] | 115 | if run != self.test.job.test_retry and isinstance(error, |
| 116 | common_lib_error.TestFailRetry): |
Scott Zawalski | 91493c8 | 2013-01-25 16:15:20 -0500 | [diff] [blame] | 117 | self.test.job.record.expect_call('INFO', None, None, info_str) |
| 118 | |
| 119 | |
| 120 | def test_call_run_once_with_retry_exception(self): |
| 121 | """ |
| 122 | Test call_run_once_with_retry duplicating a test that will always fail. |
| 123 | """ |
| 124 | self.test.job.test_retry = 5 |
| 125 | self.god.stub_function(self.test, 'drop_caches_between_iterations') |
| 126 | self.god.stub_function(self.test, 'run_once') |
| 127 | before_hook = self.god.create_mock_function('before_hook') |
| 128 | after_hook = self.god.create_mock_function('after_hook') |
| 129 | self.test.register_before_iteration_hook(before_hook) |
| 130 | self.test.register_after_iteration_hook(after_hook) |
Aviv Keshet | 39164ca | 2013-03-27 15:08:33 -0700 | [diff] [blame] | 131 | error = common_lib_error.TestFailRetry('fail') |
Scott Zawalski | 91493c8 | 2013-01-25 16:15:20 -0500 | [diff] [blame] | 132 | self._setup_failed_test_calls(self.test.job.test_retry+1, error) |
| 133 | try: |
| 134 | self.test._call_run_once_with_retry([], False, None, (1, 2), |
| 135 | {'arg': 'val'}) |
| 136 | except Exception as err: |
| 137 | if err != error: |
| 138 | raise |
| 139 | self.god.check_playback() |
| 140 | |
| 141 | |
Aviv Keshet | 39164ca | 2013-03-27 15:08:33 -0700 | [diff] [blame] | 142 | def test_call_run_once_with_retry_exception_unretryable(self): |
| 143 | """ |
| 144 | Test call_run_once_with_retry duplicating a test that will always fail |
| 145 | with a non-retryable exception. |
| 146 | """ |
| 147 | self.test.job.test_retry = 5 |
| 148 | self.god.stub_function(self.test, 'drop_caches_between_iterations') |
| 149 | self.god.stub_function(self.test, 'run_once') |
| 150 | before_hook = self.god.create_mock_function('before_hook') |
| 151 | after_hook = self.god.create_mock_function('after_hook') |
| 152 | self.test.register_before_iteration_hook(before_hook) |
| 153 | self.test.register_after_iteration_hook(after_hook) |
| 154 | error = common_lib_error.TestFail('fail') |
| 155 | self._setup_failed_test_calls(1, error) |
| 156 | try: |
| 157 | self.test._call_run_once_with_retry([], False, None, (1, 2), |
| 158 | {'arg': 'val'}) |
| 159 | except Exception as err: |
| 160 | if err != error: |
| 161 | raise |
| 162 | self.god.check_playback() |
| 163 | |
| 164 | |
Scott Zawalski | 91493c8 | 2013-01-25 16:15:20 -0500 | [diff] [blame] | 165 | def test_call_run_once_with_retry_exception_and_pass(self): |
| 166 | """ |
| 167 | Test call_run_once_with_retry duplicating a test that fails at first |
| 168 | and later passes. |
| 169 | """ |
| 170 | # Stubbed out for the write_keyval call. |
| 171 | self.test.outputdir = '/tmp' |
| 172 | self.test.job._tap = None |
| 173 | |
| 174 | num_to_fail = 2 |
| 175 | self.test.job.test_retry = 5 |
| 176 | self.god.stub_function(self.test, 'drop_caches_between_iterations') |
| 177 | self.god.stub_function(self.test, 'run_once') |
| 178 | before_hook = self.god.create_mock_function('before_hook') |
| 179 | after_hook = self.god.create_mock_function('after_hook') |
| 180 | self.god.stub_function(self.test, '_call_run_once') |
| 181 | self.test.register_before_iteration_hook(before_hook) |
| 182 | self.test.register_after_iteration_hook(after_hook) |
| 183 | self.god.stub_function(self.test.job, 'record') |
| 184 | # tests the test._call_run_once implementation |
Aviv Keshet | 39164ca | 2013-03-27 15:08:33 -0700 | [diff] [blame] | 185 | error = common_lib_error.TestFailRetry('fail') |
Scott Zawalski | 91493c8 | 2013-01-25 16:15:20 -0500 | [diff] [blame] | 186 | self._setup_failed_test_calls(num_to_fail, error) |
| 187 | # Passing call |
| 188 | self.test._call_run_once.expect_call([], False, None, (1, 2), |
| 189 | {'arg': 'val'}) |
| 190 | self.test._call_run_once_with_retry([], False, None, (1, 2), |
| 191 | {'arg': 'val'}) |
| 192 | self.god.check_playback() |
| 193 | |
| 194 | |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 195 | def _expect_call_run_once(self): |
jadmanski | a93fbca | 2009-08-21 15:34:04 +0000 | [diff] [blame] | 196 | self.test._call_run_once.expect_call((), False, None, (), {}) |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 197 | |
| 198 | |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 199 | def test_execute_test_length(self): |
| 200 | # test that test_length overrides iterations and works. |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 201 | self.god.stub_function(self.test, '_call_run_once') |
| 202 | |
| 203 | self._expect_call_run_once() |
| 204 | self._expect_call_run_once() |
| 205 | self._expect_call_run_once() |
mbligh | a49c5cb | 2009-02-26 01:01:09 +0000 | [diff] [blame] | 206 | self.test.run_once_profiling.expect_call(None) |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 207 | self.test.postprocess.expect_call() |
mbligh | 32cb5b4 | 2009-05-01 23:05:09 +0000 | [diff] [blame] | 208 | self.test.process_failed_constraints.expect_call() |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 209 | |
| 210 | fake_time = iter(xrange(4)).next |
| 211 | self.test.execute(iterations=1, test_length=3, _get_time=fake_time) |
| 212 | self.god.check_playback() |
| 213 | |
| 214 | |
| 215 | def test_execute_iterations(self): |
| 216 | # test that iterations works. |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 217 | self.god.stub_function(self.test, '_call_run_once') |
| 218 | |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 219 | iterations = 2 |
| 220 | for _ in range(iterations): |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 221 | self._expect_call_run_once() |
mbligh | a49c5cb | 2009-02-26 01:01:09 +0000 | [diff] [blame] | 222 | self.test.run_once_profiling.expect_call(None) |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 223 | self.test.postprocess.expect_call() |
mbligh | 32cb5b4 | 2009-05-01 23:05:09 +0000 | [diff] [blame] | 224 | self.test.process_failed_constraints.expect_call() |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 225 | |
| 226 | self.test.execute(iterations=iterations) |
| 227 | self.god.check_playback() |
| 228 | |
| 229 | |
| 230 | def _mock_calls_for_execute_no_iterations(self): |
mbligh | a49c5cb | 2009-02-26 01:01:09 +0000 | [diff] [blame] | 231 | self.test.run_once_profiling.expect_call(None) |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 232 | self.test.postprocess.expect_call() |
mbligh | 32cb5b4 | 2009-05-01 23:05:09 +0000 | [diff] [blame] | 233 | self.test.process_failed_constraints.expect_call() |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 234 | |
| 235 | |
| 236 | def test_execute_iteration_zero(self): |
| 237 | # test that iterations=0 works. |
| 238 | self._mock_calls_for_execute_no_iterations() |
| 239 | |
| 240 | self.test.execute(iterations=0) |
| 241 | self.god.check_playback() |
| 242 | |
| 243 | |
| 244 | def test_execute_profile_only(self): |
mbligh | c6bf601 | 2009-10-02 00:02:15 +0000 | [diff] [blame] | 245 | # test that profile_only=True works. |
jadmanski | a93fbca | 2009-08-21 15:34:04 +0000 | [diff] [blame] | 246 | self.god.stub_function(self.test, 'drop_caches_between_iterations') |
| 247 | self.test.drop_caches_between_iterations.expect_call() |
| 248 | self.test.run_once_profiling.expect_call(None) |
| 249 | self.test.drop_caches_between_iterations.expect_call() |
| 250 | self.test.run_once_profiling.expect_call(None) |
| 251 | self.test.postprocess.expect_call() |
| 252 | self.test.process_failed_constraints.expect_call() |
mbligh | 4b835b8 | 2009-02-11 01:26:13 +0000 | [diff] [blame] | 253 | self.test.execute(profile_only=True, iterations=2) |
| 254 | self.god.check_playback() |
| 255 | |
| 256 | |
showard | a6082ef | 2009-10-12 20:25:44 +0000 | [diff] [blame] | 257 | def test_execute_default_profile_only(self): |
| 258 | # test that profile_only=True works. |
| 259 | self.god.stub_function(self.test, 'drop_caches_between_iterations') |
| 260 | for _ in xrange(3): |
| 261 | self.test.drop_caches_between_iterations.expect_call() |
| 262 | self.test.run_once_profiling.expect_call(None) |
| 263 | self.test.postprocess.expect_call() |
| 264 | self.test.process_failed_constraints.expect_call() |
| 265 | self.test.job.default_profile_only = True |
| 266 | self.test.execute(iterations=3) |
| 267 | self.god.check_playback() |
| 268 | |
| 269 | |
mbligh | a49c5cb | 2009-02-26 01:01:09 +0000 | [diff] [blame] | 270 | def test_execute_postprocess_profiled_false(self): |
| 271 | # test that postprocess_profiled_run=False works |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 272 | self.god.stub_function(self.test, '_call_run_once') |
| 273 | |
jadmanski | a93fbca | 2009-08-21 15:34:04 +0000 | [diff] [blame] | 274 | self.test._call_run_once.expect_call((), False, False, (), {}) |
mbligh | a49c5cb | 2009-02-26 01:01:09 +0000 | [diff] [blame] | 275 | self.test.run_once_profiling.expect_call(False) |
| 276 | self.test.postprocess.expect_call() |
mbligh | 32cb5b4 | 2009-05-01 23:05:09 +0000 | [diff] [blame] | 277 | self.test.process_failed_constraints.expect_call() |
mbligh | a49c5cb | 2009-02-26 01:01:09 +0000 | [diff] [blame] | 278 | |
| 279 | self.test.execute(postprocess_profiled_run=False, iterations=1) |
| 280 | self.god.check_playback() |
| 281 | |
| 282 | |
| 283 | def test_execute_postprocess_profiled_true(self): |
| 284 | # test that postprocess_profiled_run=True works |
mbligh | 4395bbd | 2009-03-25 19:34:17 +0000 | [diff] [blame] | 285 | self.god.stub_function(self.test, '_call_run_once') |
| 286 | |
jadmanski | a93fbca | 2009-08-21 15:34:04 +0000 | [diff] [blame] | 287 | self.test._call_run_once.expect_call((), False, True, (), {}) |
mbligh | a49c5cb | 2009-02-26 01:01:09 +0000 | [diff] [blame] | 288 | self.test.run_once_profiling.expect_call(True) |
| 289 | self.test.postprocess.expect_call() |
mbligh | 32cb5b4 | 2009-05-01 23:05:09 +0000 | [diff] [blame] | 290 | self.test.process_failed_constraints.expect_call() |
mbligh | a49c5cb | 2009-02-26 01:01:09 +0000 | [diff] [blame] | 291 | |
| 292 | self.test.execute(postprocess_profiled_run=True, iterations=1) |
| 293 | self.god.check_playback() |
| 294 | |
| 295 | |
Keith Haddow | d804bc8 | 2016-03-15 17:16:03 -0700 | [diff] [blame^] | 296 | def test_output_single_perf_value(self): |
| 297 | self.test.resultsdir = tempfile.mkdtemp() |
| 298 | |
| 299 | self.test.output_perf_value("Test", 1, units="ms", higher_is_better=True) |
| 300 | |
| 301 | f = open(self.test.resultsdir + "/results-chart.json") |
| 302 | expected_result = {"Test": {"summary": {"units": "ms", "type": "scalar", |
| 303 | "value": 1, "improvement_direction": "up"}}} |
| 304 | self.assertDictEqual(expected_result, json.loads(f.read())) |
| 305 | |
| 306 | |
| 307 | def test_output_single_perf_value_twice(self): |
| 308 | self.test.resultsdir = tempfile.mkdtemp() |
| 309 | |
| 310 | self.test.output_perf_value("Test", 1, units="ms", higher_is_better=True) |
| 311 | self.test.output_perf_value("Test", 2, units="ms", higher_is_better=True) |
| 312 | |
| 313 | f = open(self.test.resultsdir + "/results-chart.json") |
| 314 | expected_result = {"Test": {"summary": {"units": "ms", "type": "list_of_scalar_values", |
| 315 | "values": [1, 2], "improvement_direction": "up"}}} |
| 316 | self.assertDictEqual(expected_result, json.loads(f.read())) |
| 317 | |
| 318 | |
| 319 | def test_output_single_perf_value_three_times(self): |
| 320 | self.test.resultsdir = tempfile.mkdtemp() |
| 321 | |
| 322 | self.test.output_perf_value("Test", 1, units="ms", higher_is_better=True) |
| 323 | self.test.output_perf_value("Test", 2, units="ms", higher_is_better=True) |
| 324 | self.test.output_perf_value("Test", 3, units="ms", higher_is_better=True) |
| 325 | |
| 326 | f = open(self.test.resultsdir + "/results-chart.json") |
| 327 | expected_result = {"Test": {"summary": {"units": "ms", "type": "list_of_scalar_values", |
| 328 | "values": [1, 2, 3], "improvement_direction": "up"}}} |
| 329 | self.assertDictEqual(expected_result, json.loads(f.read())) |
| 330 | |
| 331 | |
| 332 | def test_output_list_perf_value(self): |
| 333 | self.test.resultsdir = tempfile.mkdtemp() |
| 334 | |
| 335 | self.test.output_perf_value("Test", [1, 2, 3], units="ms", higher_is_better=False) |
| 336 | |
| 337 | f = open(self.test.resultsdir + "/results-chart.json") |
| 338 | expected_result = {"Test": {"summary": {"units": "ms", "type": "list_of_scalar_values", |
| 339 | "values": [1, 2, 3], "improvement_direction": "down"}}} |
| 340 | self.assertDictEqual(expected_result, json.loads(f.read())) |
| 341 | |
| 342 | |
| 343 | def test_output_single_then_list_perf_value(self): |
| 344 | self.test.resultsdir = tempfile.mkdtemp() |
| 345 | self.test.output_perf_value("Test", 1, units="ms", higher_is_better=False) |
| 346 | self.test.output_perf_value("Test", [4, 3, 2], units="ms", higher_is_better=False) |
| 347 | f = open(self.test.resultsdir + "/results-chart.json") |
| 348 | expected_result = {"Test": {"summary": {"units": "ms", "type": "list_of_scalar_values", |
| 349 | "values": [1, 4, 3, 2], "improvement_direction": "down"}}} |
| 350 | self.assertDictEqual(expected_result, json.loads(f.read())) |
| 351 | |
| 352 | |
| 353 | def test_output_list_then_list_perf_value(self): |
| 354 | self.test.resultsdir = tempfile.mkdtemp() |
| 355 | self.test.output_perf_value("Test", [1, 2, 3], units="ms", higher_is_better=False) |
| 356 | self.test.output_perf_value("Test", [4, 3, 2], units="ms", higher_is_better=False) |
| 357 | f = open(self.test.resultsdir + "/results-chart.json") |
| 358 | expected_result = {"Test": {"summary": {"units": "ms", "type": "list_of_scalar_values", |
| 359 | "values": [1, 2, 3, 4, 3, 2], "improvement_direction": "down"}}} |
| 360 | self.assertDictEqual(expected_result, json.loads(f.read())) |
| 361 | |
| 362 | |
mbligh | 234a84f | 2008-11-20 19:57:43 +0000 | [diff] [blame] | 363 | if __name__ == '__main__': |
| 364 | unittest.main() |