| OLD | NEW |
| (Empty) |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import json | |
| 6 import os | |
| 7 import StringIO | |
| 8 import unittest | |
| 9 | |
| 10 from telemetry import benchmark | |
| 11 from telemetry import story | |
| 12 from telemetry.internal.results import chart_json_output_formatter | |
| 13 from telemetry.internal.results import page_test_results | |
| 14 from telemetry import page as page_module | |
| 15 from telemetry.value import improvement_direction | |
| 16 from telemetry.value import list_of_scalar_values | |
| 17 from telemetry.value import scalar | |
| 18 | |
| 19 | |
| 20 def _MakeStorySet(): | |
| 21 ps = story.StorySet(base_dir=os.path.dirname(__file__)) | |
| 22 ps.AddStory(page_module.Page('http://www.foo.com/', ps, ps.base_dir)) | |
| 23 ps.AddStory(page_module.Page('http://www.bar.com/', ps, ps.base_dir)) | |
| 24 return ps | |
| 25 | |
| 26 class ChartJsonTest(unittest.TestCase): | |
| 27 def setUp(self): | |
| 28 self._output = StringIO.StringIO() | |
| 29 self._story_set = _MakeStorySet() | |
| 30 self._benchmark_metadata = benchmark.BenchmarkMetadata( | |
| 31 'benchmark_name', 'benchmark_description') | |
| 32 self._formatter = chart_json_output_formatter.ChartJsonOutputFormatter( | |
| 33 self._output, self._benchmark_metadata) | |
| 34 | |
| 35 def testOutputAndParse(self): | |
| 36 results = page_test_results.PageTestResults() | |
| 37 | |
| 38 self._output.truncate(0) | |
| 39 | |
| 40 results.WillRunPage(self._story_set[0]) | |
| 41 v0 = scalar.ScalarValue(results.current_page, 'foo', 'seconds', 3, | |
| 42 improvement_direction=improvement_direction.DOWN) | |
| 43 results.AddValue(v0) | |
| 44 results.DidRunPage(self._story_set[0]) | |
| 45 | |
| 46 self._formatter.Format(results) | |
| 47 d = json.loads(self._output.getvalue()) | |
| 48 self.assertIn('foo', d['charts']) | |
| 49 | |
| 50 def testAsChartDictSerializable(self): | |
| 51 v0 = scalar.ScalarValue(self._story_set[0], 'foo', 'seconds', 3, | |
| 52 improvement_direction=improvement_direction.DOWN) | |
| 53 page_specific_values = [v0] | |
| 54 summary_values = [] | |
| 55 | |
| 56 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 57 self._benchmark_metadata, | |
| 58 page_specific_values, | |
| 59 summary_values) | |
| 60 json.dumps(d) | |
| 61 | |
| 62 def testAsChartDictBaseKeys(self): | |
| 63 page_specific_values = [] | |
| 64 summary_values = [] | |
| 65 | |
| 66 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 67 self._benchmark_metadata, | |
| 68 page_specific_values, | |
| 69 summary_values) | |
| 70 | |
| 71 self.assertEquals(d['format_version'], '0.1') | |
| 72 self.assertEquals(d['next_version'], '0.2') | |
| 73 self.assertEquals(d['benchmark_metadata']['name'], 'benchmark_name') | |
| 74 self.assertEquals(d['benchmark_metadata']['description'], | |
| 75 'benchmark_description') | |
| 76 self.assertEquals(d['benchmark_metadata']['type'], 'telemetry_benchmark') | |
| 77 | |
| 78 def testAsChartDictNoDescription(self): | |
| 79 page_specific_values = [] | |
| 80 summary_values = [] | |
| 81 | |
| 82 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 83 benchmark.BenchmarkMetadata('benchmark_name', ''), | |
| 84 page_specific_values, | |
| 85 summary_values) | |
| 86 | |
| 87 self.assertEquals('', d['benchmark_metadata']['description']) | |
| 88 | |
| 89 def testAsChartDictPageSpecificValuesSamePageWithInteractionRecord(self): | |
| 90 v0 = scalar.ScalarValue(self._story_set[0], 'foo', 'seconds', 3, | |
| 91 improvement_direction=improvement_direction.DOWN, | |
| 92 tir_label='MyIR') | |
| 93 v1 = scalar.ScalarValue(self._story_set[0], 'foo', 'seconds', 4, | |
| 94 improvement_direction=improvement_direction.DOWN, | |
| 95 tir_label='MyIR') | |
| 96 page_specific_values = [v0, v1] | |
| 97 summary_values = [] | |
| 98 | |
| 99 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 100 self._benchmark_metadata, | |
| 101 page_specific_values, | |
| 102 summary_values) | |
| 103 | |
| 104 self.assertTrue('MyIR@@foo' in d['charts']) | |
| 105 self.assertTrue('http://www.foo.com/' in d['charts']['MyIR@@foo']) | |
| 106 | |
| 107 def testAsChartDictPageSpecificValuesSamePageWithoutInteractionRecord(self): | |
| 108 v0 = scalar.ScalarValue(self._story_set[0], 'foo', 'seconds', 3, | |
| 109 improvement_direction=improvement_direction.DOWN) | |
| 110 v1 = scalar.ScalarValue(self._story_set[0], 'foo', 'seconds', 4, | |
| 111 improvement_direction=improvement_direction.DOWN) | |
| 112 page_specific_values = [v0, v1] | |
| 113 summary_values = [] | |
| 114 | |
| 115 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 116 self._benchmark_metadata, | |
| 117 page_specific_values, | |
| 118 summary_values) | |
| 119 | |
| 120 self.assertTrue('foo' in d['charts']) | |
| 121 self.assertTrue('http://www.foo.com/' in d['charts']['foo']) | |
| 122 | |
| 123 def testAsChartDictPageSpecificValuesAndComputedSummaryWithTraceName(self): | |
| 124 v0 = scalar.ScalarValue(self._story_set[0], 'foo.bar', 'seconds', 3, | |
| 125 improvement_direction=improvement_direction.DOWN) | |
| 126 v1 = scalar.ScalarValue(self._story_set[1], 'foo.bar', 'seconds', 4, | |
| 127 improvement_direction=improvement_direction.DOWN) | |
| 128 page_specific_values = [v0, v1] | |
| 129 summary_values = [] | |
| 130 | |
| 131 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 132 self._benchmark_metadata, | |
| 133 page_specific_values, | |
| 134 summary_values) | |
| 135 | |
| 136 self.assertTrue('foo' in d['charts']) | |
| 137 self.assertTrue('http://www.foo.com/' in d['charts']['foo']) | |
| 138 self.assertTrue('http://www.bar.com/' in d['charts']['foo']) | |
| 139 self.assertTrue('bar' in d['charts']['foo']) | |
| 140 | |
| 141 def testAsChartDictPageSpecificValuesAndComputedSummaryWithoutTraceName(self): | |
| 142 v0 = scalar.ScalarValue(self._story_set[0], 'foo', 'seconds', 3, | |
| 143 improvement_direction=improvement_direction.DOWN) | |
| 144 v1 = scalar.ScalarValue(self._story_set[1], 'foo', 'seconds', 4, | |
| 145 improvement_direction=improvement_direction.DOWN) | |
| 146 page_specific_values = [v0, v1] | |
| 147 summary_values = [] | |
| 148 | |
| 149 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 150 self._benchmark_metadata, | |
| 151 page_specific_values, | |
| 152 summary_values) | |
| 153 | |
| 154 self.assertTrue('foo' in d['charts']) | |
| 155 self.assertTrue('http://www.foo.com/' in d['charts']['foo']) | |
| 156 self.assertTrue('http://www.bar.com/' in d['charts']['foo']) | |
| 157 self.assertTrue('summary' in d['charts']['foo']) | |
| 158 | |
| 159 def testAsChartDictSummaryValueWithTraceName(self): | |
| 160 v0 = list_of_scalar_values.ListOfScalarValues( | |
| 161 None, 'foo.bar', 'seconds', [3, 4], | |
| 162 improvement_direction=improvement_direction.DOWN) | |
| 163 page_specific_values = [] | |
| 164 summary_values = [v0] | |
| 165 | |
| 166 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 167 self._benchmark_metadata, | |
| 168 page_specific_values, | |
| 169 summary_values) | |
| 170 | |
| 171 self.assertTrue('bar' in d['charts']['foo']) | |
| 172 | |
| 173 def testAsChartDictSummaryValueWithoutTraceName(self): | |
| 174 v0 = list_of_scalar_values.ListOfScalarValues( | |
| 175 None, 'foo', 'seconds', [3, 4], | |
| 176 improvement_direction=improvement_direction.DOWN) | |
| 177 page_specific_values = [] | |
| 178 summary_values = [v0] | |
| 179 | |
| 180 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 181 self._benchmark_metadata, | |
| 182 page_specific_values, | |
| 183 summary_values) | |
| 184 | |
| 185 self.assertTrue('summary' in d['charts']['foo']) | |
| 186 | |
| 187 def testAsChartDictValueSmokeTest(self): | |
| 188 v0 = list_of_scalar_values.ListOfScalarValues( | |
| 189 None, 'foo.bar', 'seconds', [3, 4], | |
| 190 improvement_direction=improvement_direction.DOWN) | |
| 191 page_specific_values = [] | |
| 192 summary_values = [v0] | |
| 193 | |
| 194 d = chart_json_output_formatter.ResultsAsChartDict( | |
| 195 self._benchmark_metadata, | |
| 196 page_specific_values, | |
| 197 summary_values) | |
| 198 | |
| 199 self.assertEquals(d['charts']['foo']['bar']['values'], [3, 4]) | |
| OLD | NEW |