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

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

Powered by Google App Engine
This is Rietveld 408576698