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

Side by Side Diff: telemetry/telemetry/internal/results/csv_output_formatter_unittest.py

Issue 3003163002: Add CsvOutputFormatter to Telemetry. (Closed)
Patch Set: Created 3 years, 4 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
OLDNEW
(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 os
6 import StringIO
7 import unittest
8
9 import mock
10
11 from telemetry import story
12 from telemetry import benchmark
13 from telemetry.internal.results import csv_output_formatter
14 from telemetry.internal.results import page_test_results
15 from telemetry import page as page_module
16 from telemetry.value import improvement_direction
17 from telemetry.value import scalar
18 from telemetry.value import trace
19 from tracing.trace_data import trace_data
20
21
22 def _MakeStorySet():
23 story_set = story.StorySet(base_dir=os.path.dirname(__file__))
24 story_set.AddStory(page_module.Page(
25 'http://www.foo.com/', story_set, story_set.base_dir,
26 name='http://www.foo.com/'))
27 story_set.AddStory(page_module.Page(
28 'http://www.bar.com/', story_set, story_set.base_dir,
29 name='http://www.bar.com/'))
30 return story_set
31
32
33 class CsvOutputFormatterTest(unittest.TestCase):
34
35 def setUp(self):
36 self._output = StringIO.StringIO()
37 self._story_set = _MakeStorySet()
38 self._results = page_test_results.PageTestResults()
39 self._formatter = None
40 self.MakeFormatter()
41
42 def MakeFormatter(self):
43 self._formatter = csv_output_formatter.CsvOutputFormatter(self._output)
44
45 def SimulateBenchmarkRun(self, list_of_page_and_values):
46 """Simulate one run of a benchmark, using the supplied values.
47
48 Args:
49 list_of_pages_and_values: a list of tuple (page, list of values)
50 """
51 for page, values in list_of_page_and_values:
52 self._results.WillRunPage(page)
53 for v in values:
54 v.page = page
55 self._results.AddValue(v)
56 self._results.DidRunPage(page)
57
58 def Format(self):
59 self._results.telemetry_info.benchmark_start_epoch = 15e8
60 self._results.PopulateHistogramSet(benchmark.BenchmarkMetadata('benchmark'))
61 self._formatter.Format(self._results)
62 return self._output.getvalue()
63
64 def testSimple(self):
65 # Test a simple benchmark with only one value:
66 self.SimulateBenchmarkRun([
67 (self._story_set[0], [scalar.ScalarValue(
68 None, 'foo', 'seconds', 3,
69 improvement_direction=improvement_direction.DOWN)])])
70 expected = '\r\n'.join([
71 'name,unit,avg,count,max,min,std,sum,architectures,benchmarks,' +
72 'benchmarkStart,bots,builds,displayLabel,masters,memoryAmounts,' +
73 'osNames,osVersions,productVersions,stories,storysetRepeats,traceStart',
74 'foo,ms,3000,1,3000,3000,0,3000,,benchmark,2017-07-14 02:40:00,,,' +
75 'benchmark 2017-07-14 02:40:00,,,,,,http://www.foo.com/,,',
76 ''])
77
78 self.assertEqual(expected, self.Format())
79
80 @mock.patch('py_utils.cloud_storage.Insert')
81 def testMultiplePagesAndValues(self, cs_insert_mock):
82 cs_insert_mock.return_value = 'https://cloud_storage_url/foo'
83 trace_value = trace.TraceValue(
84 None, trace_data.CreateTraceDataFromRawData('{"traceEvents": []}'))
85 trace_value.UploadToCloud(bucket='foo')
86 self.SimulateBenchmarkRun([
87 (self._story_set[0], [
88 scalar.ScalarValue(
89 None, 'foo', 'seconds', 4,
90 improvement_direction=improvement_direction.DOWN)]),
91 (self._story_set[1], [
92 scalar.ScalarValue(
93 None, 'foo', 'seconds', 3.4,
94 improvement_direction=improvement_direction.DOWN),
95 trace_value,
96 scalar.ScalarValue(
97 None, 'bar', 'km', 10,
98 improvement_direction=improvement_direction.DOWN),
99 scalar.ScalarValue(
100 None, 'baz', 'count', 5,
101 improvement_direction=improvement_direction.DOWN)])])
102
103 # Parse CSV output into list of lists.
104 csv_string = self.Format()
105 lines = csv_string.split('\r\n')
106 values = [s.split(',') for s in lines[1:-1]]
107 values.sort()
108
109 self.assertEquals(len(values), 4)
110 self.assertEquals(len(set((v[1] for v in values))), 2) # 2 pages.
111 self.assertEquals(len(set((v[2] for v in values))), 4) # 4 value names.
112 self.assertEquals(values[2], [
113 'foo', 'ms', '3400', '1', '3400', '3400', '0', '3400', '', 'benchmark',
114 '2017-07-14 02:40:00', '', '', 'benchmark 2017-07-14 02:40:00', '', '',
115 '', '', '', 'http://www.bar.com/', '', ''])
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/results/csv_output_formatter.py ('k') | telemetry/telemetry/internal/results/results_options.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698