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

Side by Side Diff: telemetry/telemetry/internal/story_runner_unittest.py

Issue 2777673003: Revert of Track telemetry benchmark cycle time (Closed)
Patch Set: Created 3 years, 8 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
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 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 import json
6 import math 5 import math
7 import os 6 import os
8 import shutil
9 import StringIO 7 import StringIO
10 import sys 8 import sys
11 import tempfile
12 import unittest 9 import unittest
13 10
14 from py_utils import cloud_storage # pylint: disable=import-error 11 from py_utils import cloud_storage # pylint: disable=import-error
15 12
16 from telemetry import benchmark 13 from telemetry import benchmark
17 from telemetry.core import exceptions 14 from telemetry.core import exceptions
18 from telemetry.core import util 15 from telemetry.core import util
19 from telemetry import decorators 16 from telemetry import decorators
20 from telemetry.internal.actions import page_action 17 from telemetry.internal.actions import page_action
21 from telemetry.internal.results import page_test_results 18 from telemetry.internal.results import page_test_results
22 from telemetry.internal.results import results_options 19 from telemetry.internal.results import results_options
23 from telemetry.internal import story_runner 20 from telemetry.internal import story_runner
24 from telemetry.internal.util import exception_formatter as ex_formatter_module 21 from telemetry.internal.util import exception_formatter as ex_formatter_module
25 from telemetry.page import page as page_module 22 from telemetry.page import page as page_module
26 from telemetry.page import legacy_page_test 23 from telemetry.page import legacy_page_test
27 from telemetry import story as story_module 24 from telemetry import story as story_module
28 from telemetry.testing import fakes
29 from telemetry.testing import options_for_unittests 25 from telemetry.testing import options_for_unittests
30 from telemetry.testing import system_stub 26 from telemetry.testing import system_stub
31 import mock 27 import mock
32 from telemetry.value import failure 28 from telemetry.value import failure
33 from telemetry.value import improvement_direction 29 from telemetry.value import improvement_direction
34 from telemetry.value import list_of_scalar_values 30 from telemetry.value import list_of_scalar_values
35 from telemetry.value import scalar 31 from telemetry.value import scalar
36 from telemetry.value import skip 32 from telemetry.value import skip
37 from telemetry.value import summary as summary_module 33 from telemetry.value import summary as summary_module
38 from telemetry.web_perf import story_test 34 from telemetry.web_perf import story_test
39 from telemetry.web_perf import timeline_based_measurement 35 from telemetry.web_perf import timeline_based_measurement
40 from telemetry.wpr import archive_info 36 from telemetry.wpr import archive_info
41 37
42 # This linter complains if we define classes nested inside functions. 38 # This linter complains if we define classes nested inside functions.
43 # pylint: disable=bad-super-call 39 # pylint: disable=bad-super-call
44 40
45 # pylint: disable=too-many-lines 41 # pylint: disable=too-many-lines
46 42
43
47 class FakePlatform(object): 44 class FakePlatform(object):
48 def CanMonitorThermalThrottling(self): 45 def CanMonitorThermalThrottling(self):
49 return False 46 return False
50 47
51 def GetOSName(self): 48 def GetOSName(self):
52 pass 49 pass
53 50
54 def WaitForTemperature(self, _): 51 def WaitForTemperature(self, _):
55 pass 52 pass
56 53
57 def GetDeviceTypeName(self): 54 def GetDeviceTypeName(self):
58 return "GetDeviceTypeName" 55 return "GetDeviceTypeName"
59 56
57
60 class TestSharedState(story_module.SharedState): 58 class TestSharedState(story_module.SharedState):
61 59
62 _platform = FakePlatform() 60 _platform = FakePlatform()
63 61
64 @classmethod 62 @classmethod
65 def SetTestPlatform(cls, platform): 63 def SetTestPlatform(cls, platform):
66 cls._platform = platform 64 cls._platform = platform
67 65
68 def __init__(self, test, options, story_set): 66 def __init__(self, test, options, story_set):
69 super(TestSharedState, self).__init__( 67 super(TestSharedState, self).__init__(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 def SetupStorySet(allow_multiple_story_states, story_state_list): 144 def SetupStorySet(allow_multiple_story_states, story_state_list):
147 if allow_multiple_story_states: 145 if allow_multiple_story_states:
148 story_set = MixedStateStorySet() 146 story_set = MixedStateStorySet()
149 else: 147 else:
150 story_set = story_module.StorySet() 148 story_set = story_module.StorySet()
151 for i, story_state in enumerate(story_state_list): 149 for i, story_state in enumerate(story_state_list):
152 story_set.AddStory(DummyLocalStory(story_state, 150 story_set.AddStory(DummyLocalStory(story_state,
153 name='story%d' % i)) 151 name='story%d' % i))
154 return story_set 152 return story_set
155 153
156 class FakeBenchmark(benchmark.Benchmark):
157 @classmethod
158 def Name(cls):
159 return 'fake'
160
161 test = DummyTest
162
163 def page_set(self):
164 return story_module.StorySet()
165
166 154
167 def _GetOptionForUnittest(): 155 def _GetOptionForUnittest():
168 options = options_for_unittests.GetCopy() 156 options = options_for_unittests.GetCopy()
169 options.output_formats = ['none'] 157 options.output_formats = ['none']
170 options.suppress_gtest_report = False 158 options.suppress_gtest_report = False
171 parser = options.CreateParser() 159 parser = options.CreateParser()
172 story_runner.AddCommandLineArgs(parser) 160 story_runner.AddCommandLineArgs(parser)
173 options.MergeDefaultValues(parser.get_default_values()) 161 options.MergeDefaultValues(parser.get_default_values())
174 story_runner.ProcessCommandLineArgs(parser, options) 162 story_runner.ProcessCommandLineArgs(parser, options)
175 return options 163 return options
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 mock.call.test.WillRunStory(root_mock.state.platform), 1029 mock.call.test.WillRunStory(root_mock.state.platform),
1042 mock.call.state.WillRunStory(root_mock.story), 1030 mock.call.state.WillRunStory(root_mock.story),
1043 mock.call.state.CanRunStory(root_mock.story), 1031 mock.call.state.CanRunStory(root_mock.story),
1044 mock.call.state.RunStory(root_mock.results), 1032 mock.call.state.RunStory(root_mock.results),
1045 mock.call.test.Measure(root_mock.state.platform, root_mock.results), 1033 mock.call.test.Measure(root_mock.state.platform, root_mock.results),
1046 mock.call.state.DumpStateUponFailure(root_mock.story, root_mock.results), 1034 mock.call.state.DumpStateUponFailure(root_mock.story, root_mock.results),
1047 mock.call.results.AddValue(FailureValueMatcher('foo')), 1035 mock.call.results.AddValue(FailureValueMatcher('foo')),
1048 mock.call.state.DidRunStory(root_mock.results), 1036 mock.call.state.DidRunStory(root_mock.results),
1049 mock.call.test.DidRunStory(root_mock.state.platform) 1037 mock.call.test.DidRunStory(root_mock.state.platform)
1050 ]) 1038 ])
1051
1052 def testRunBenchmarkTimeDuration(self):
1053 fake_benchmark = FakeBenchmark()
1054 options = fakes.CreateBrowserFinderOptions()
1055 options.upload_results = None
1056 options.suppress_gtest_report = False
1057 options.results_label = None
1058 options.use_live_sites = False
1059 options.max_failures = 100
1060 options.pageset_repeat = 1
1061 options.output_formats = ['chartjson']
1062
1063 with mock.patch('telemetry.internal.story_runner.time.time') as time_patch:
1064 # 3, because telemetry code asks for the time at some point
1065 time_patch.side_effect = [1, 0, 61]
1066 tmp_path = tempfile.mkdtemp()
1067
1068 try:
1069 options.output_dir = tmp_path
1070 story_runner.RunBenchmark(fake_benchmark, options)
1071 with open(os.path.join(tmp_path, 'results-chart.json')) as f:
1072 data = json.load(f)
1073
1074 self.assertEqual(len(data['charts']), 1)
1075 charts = data['charts']
1076 self.assertIn('BenchmarkDuration', charts)
1077 duration = charts['BenchmarkDuration']
1078 self.assertIn("summary", duration)
1079 summary = duration['summary']
1080 duration = summary['value']
1081 self.assertAlmostEqual(duration, 1)
1082 finally:
1083 shutil.rmtree(tmp_path)
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/story_runner.py ('k') | telemetry/telemetry/testing/fakes/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698