Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: tools/telemetry/telemetry/page_benchmark_results_unittest.py

Issue 12278015: [Telemetry] Reorganize everything. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-add shebangs. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 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 import os
5 import unittest
6
7 from telemetry.page_benchmark_results import PageBenchmarkResults
8 from telemetry.page_set import PageSet
9 from telemetry.perf_tests_helper import PrintPerfResult
10
11
12 def _MakePageSet():
13 return PageSet.FromDict({
14 "description": "hello",
15 "archive_path": "foo.wpr",
16 "pages": [
17 {"url": "http://www.foo.com/"},
18 {"url": "http://www.bar.com/"}
19 ]
20 }, os.path.dirname(__file__))
21
22 class NonPrintingPageBenchmarkResults(PageBenchmarkResults):
23 def __init__(self):
24 super(NonPrintingPageBenchmarkResults, self).__init__()
25
26 def _PrintPerfResult(self, *args):
27 pass
28
29 class SummarySavingPageBenchmarkResults(PageBenchmarkResults):
30 def __init__(self):
31 super(SummarySavingPageBenchmarkResults, self).__init__()
32 self.results = []
33
34 def _PrintPerfResult(self, *args):
35 res = PrintPerfResult(*args, print_to_stdout=False)
36 self.results.append(res)
37
38 class PageBenchmarkResultsTest(unittest.TestCase):
39 def test_basic(self):
40 page_set = _MakePageSet()
41
42 benchmark_results = NonPrintingPageBenchmarkResults()
43 benchmark_results.WillMeasurePage(page_set.pages[0])
44 benchmark_results.Add('a', 'seconds', 3)
45 benchmark_results.DidMeasurePage()
46
47 benchmark_results.WillMeasurePage(page_set.pages[1])
48 benchmark_results.Add('a', 'seconds', 3)
49 benchmark_results.DidMeasurePage()
50
51 benchmark_results.PrintSummary('trace_tag')
52
53 def test_url_is_invalid_value(self):
54 page_set = _MakePageSet()
55
56 benchmark_results = NonPrintingPageBenchmarkResults()
57 benchmark_results.WillMeasurePage(page_set.pages[0])
58 self.assertRaises(
59 AssertionError,
60 lambda: benchmark_results.Add('url', 'string', 'foo'))
61
62 def test_unit_change(self):
63 page_set = _MakePageSet()
64
65 benchmark_results = NonPrintingPageBenchmarkResults()
66 benchmark_results.WillMeasurePage(page_set.pages[0])
67 benchmark_results.Add('a', 'seconds', 3)
68 benchmark_results.DidMeasurePage()
69
70 benchmark_results.WillMeasurePage(page_set.pages[1])
71 self.assertRaises(
72 AssertionError,
73 lambda: benchmark_results.Add('a', 'foobgrobbers', 3))
74
75 def test_type_change(self):
76 page_set = _MakePageSet()
77
78 benchmark_results = NonPrintingPageBenchmarkResults()
79 benchmark_results.WillMeasurePage(page_set.pages[0])
80 benchmark_results.Add('a', 'seconds', 3)
81 benchmark_results.DidMeasurePage()
82
83 benchmark_results.WillMeasurePage(page_set.pages[1])
84 self.assertRaises(
85 AssertionError,
86 lambda: benchmark_results.Add('a', 'seconds', 3, data_type='histogram'))
87
88 def test_basic_summary(self):
89 page_set = _MakePageSet()
90
91 benchmark_results = SummarySavingPageBenchmarkResults()
92 benchmark_results.WillMeasurePage(page_set.pages[0])
93 benchmark_results.Add('a', 'seconds', 3)
94 benchmark_results.DidMeasurePage()
95
96 benchmark_results.WillMeasurePage(page_set.pages[1])
97 benchmark_results.Add('a', 'seconds', 7)
98 benchmark_results.DidMeasurePage()
99
100 benchmark_results.PrintSummary(None)
101 expected = ['RESULT a_by_url: http___www.foo.com_= 3 seconds',
102 'RESULT a_by_url: http___www.bar.com_= 7 seconds',
103 '*RESULT a: a= [3,7] seconds\nAvg a: 5.000000seconds\n' +
104 'Sd a: 2.828427seconds']
105 self.assertEquals(
106 benchmark_results.results,
107 expected)
108
109 def test_histogram(self):
110 page_set = _MakePageSet()
111
112 benchmark_results = SummarySavingPageBenchmarkResults()
113 benchmark_results.WillMeasurePage(page_set.pages[0])
114 benchmark_results.Add('a', '',
115 '{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
116 data_type='histogram')
117 benchmark_results.DidMeasurePage()
118
119 benchmark_results.WillMeasurePage(page_set.pages[1])
120 benchmark_results.Add('a', '',
121 '{"buckets": [{"low": 2, "high": 3, "count": 1}]}',
122 data_type='histogram')
123 benchmark_results.DidMeasurePage()
124
125 benchmark_results.PrintSummary(None)
126
127 expected = [
128 '*HISTOGRAM a_by_url.http___www.foo.com_: ' +
129 'a_by_url.http___www.foo.com_= ' +
130 '{"buckets": [{"low": 1, "high": 2, "count": 1}]}\n' +
131 'Avg a_by_url.http___www.foo.com_: 1.500000',
132 '*HISTOGRAM a_by_url.http___www.bar.com_: ' +
133 'a_by_url.http___www.bar.com_= ' +
134 '{"buckets": [{"low": 2, "high": 3, "count": 1}]}\n' +
135 'Avg a_by_url.http___www.bar.com_: 2.500000']
136 self.assertEquals(benchmark_results.results, expected)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/page_benchmark_results.py ('k') | tools/telemetry/telemetry/page_benchmark_value.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698