OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Tests for the Chromium Performance Dashboard data format implementation.""" | 5 """Tests for the Chromium Performance Dashboard data format implementation.""" |
6 | 6 |
7 import imp | 7 import imp |
8 import json | 8 import json |
9 import os.path | 9 import os.path |
10 import sys | 10 import sys |
11 import unittest | 11 import unittest |
12 | 12 |
13 try: | 13 try: |
14 imp.find_module("devtoolslib") | 14 imp.find_module("devtoolslib") |
15 except ImportError: | 15 except ImportError: |
16 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 16 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
17 | 17 |
18 from devtoolslib.perf_dashboard import ChartDataRecorder | 18 from devtoolslib.perf_dashboard import ChartDataRecorder |
19 | 19 |
| 20 |
20 class ChartDataRecorderTest(unittest.TestCase): | 21 class ChartDataRecorderTest(unittest.TestCase): |
21 """Tests the chart data recorder.""" | 22 """Tests the chart data recorder.""" |
22 | 23 |
23 def test_empty(self): | 24 def test_empty(self): |
24 """Tests chart data with no charts.""" | 25 """Tests chart data with no charts.""" |
25 recorder = ChartDataRecorder() | 26 recorder = ChartDataRecorder('benchmark') |
26 result = json.loads(recorder.get_json()) | 27 result = json.loads(recorder.get_json()) |
27 self.assertEquals(0, len(result)) | 28 self.assertEquals({ |
| 29 'format_version': '1.0', |
| 30 'benchmark_name': 'benchmark', |
| 31 'charts': {}}, result) |
28 | 32 |
29 def test_one_chart(self): | 33 def test_one_chart(self): |
30 """Tests chart data with two samples in one chart.""" | 34 """Tests chart data with two samples in one chart.""" |
31 recorder = ChartDataRecorder() | 35 recorder = ChartDataRecorder('benchmark') |
32 recorder.record_scalar('chart', 'val1', 'ms', 1) | 36 recorder.record_scalar('chart', 'val1', 'ms', 1) |
33 recorder.record_scalar('chart', 'val2', 'ms', 2) | 37 recorder.record_scalar('chart', 'val2', 'ms', 2) |
34 | 38 |
35 result = json.loads(recorder.get_json()) | 39 result = json.loads(recorder.get_json()) |
36 self.assertEquals(1, len(result)) | 40 self.assertEquals('1.0', result['format_version']) |
37 self.assertEquals(2, len(result['chart'])) | 41 self.assertEquals('benchmark', result['benchmark_name']) |
| 42 |
| 43 charts = result['charts'] |
| 44 self.assertEquals(1, len(charts)) |
| 45 self.assertEquals(2, len(charts['chart'])) |
38 self.assertEquals({ | 46 self.assertEquals({ |
39 'type': 'scalar', | 47 'type': 'scalar', |
40 'name': 'val1', | 48 'name': 'val1', |
41 'units': 'ms', | 49 'units': 'ms', |
42 'value': 1}, result['chart'][0]) | 50 'value': 1}, charts['chart'][0]) |
43 self.assertEquals({ | 51 self.assertEquals({ |
44 'type': 'scalar', | 52 'type': 'scalar', |
45 'name': 'val2', | 53 'name': 'val2', |
46 'units': 'ms', | 54 'units': 'ms', |
47 'value': 2}, result['chart'][1]) | 55 'value': 2}, charts['chart'][1]) |
48 | 56 |
49 def test_two_charts(self): | 57 def test_two_charts(self): |
50 """Tests chart data with two samples over two charts.""" | 58 """Tests chart data with two samples over two charts.""" |
51 recorder = ChartDataRecorder() | 59 recorder = ChartDataRecorder('benchmark') |
52 recorder.record_scalar('chart1', 'val1', 'ms', 1) | 60 recorder.record_scalar('chart1', 'val1', 'ms', 1) |
53 recorder.record_scalar('chart2', 'val2', 'ms', 2) | 61 recorder.record_scalar('chart2', 'val2', 'ms', 2) |
54 | 62 |
55 result = json.loads(recorder.get_json()) | 63 result = json.loads(recorder.get_json()) |
56 self.assertEquals(2, len(result)) | 64 self.assertEquals('1.0', result['format_version']) |
57 self.assertEquals(1, len(result['chart1'])) | 65 self.assertEquals('benchmark', result['benchmark_name']) |
| 66 |
| 67 charts = result['charts'] |
| 68 self.assertEquals(2, len(charts)) |
| 69 self.assertEquals(1, len(charts['chart1'])) |
58 self.assertEquals({ | 70 self.assertEquals({ |
59 'type': 'scalar', | 71 'type': 'scalar', |
60 'name': 'val1', | 72 'name': 'val1', |
61 'units': 'ms', | 73 'units': 'ms', |
62 'value': 1}, result['chart1'][0]) | 74 'value': 1}, charts['chart1'][0]) |
63 self.assertEquals(1, len(result['chart2'])) | 75 self.assertEquals(1, len(charts['chart2'])) |
64 self.assertEquals({ | 76 self.assertEquals({ |
65 'type': 'scalar', | 77 'type': 'scalar', |
66 'name': 'val2', | 78 'name': 'val2', |
67 'units': 'ms', | 79 'units': 'ms', |
68 'value': 2}, result['chart2'][0]) | 80 'value': 2}, charts['chart2'][0]) |
OLD | NEW |