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

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

Issue 2777093004: Reland of Track telemetry benchmark cycle time (Closed)
Patch Set: Fix bad return Created 3 years, 9 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
5 import math 6 import math
6 import os 7 import os
8 import shutil
7 import StringIO 9 import StringIO
8 import sys 10 import sys
11 import tempfile
9 import unittest 12 import unittest
10 13
11 from py_utils import cloud_storage # pylint: disable=import-error 14 from py_utils import cloud_storage # pylint: disable=import-error
12 15
13 from telemetry import benchmark 16 from telemetry import benchmark
14 from telemetry.core import exceptions 17 from telemetry.core import exceptions
15 from telemetry.core import util 18 from telemetry.core import util
16 from telemetry import decorators 19 from telemetry import decorators
17 from telemetry.internal.actions import page_action 20 from telemetry.internal.actions import page_action
18 from telemetry.internal.results import page_test_results 21 from telemetry.internal.results import page_test_results
19 from telemetry.internal.results import results_options 22 from telemetry.internal.results import results_options
20 from telemetry.internal import story_runner 23 from telemetry.internal import story_runner
21 from telemetry.internal.util import exception_formatter as ex_formatter_module 24 from telemetry.internal.util import exception_formatter as ex_formatter_module
22 from telemetry.page import page as page_module 25 from telemetry.page import page as page_module
23 from telemetry.page import legacy_page_test 26 from telemetry.page import legacy_page_test
24 from telemetry import story as story_module 27 from telemetry import story as story_module
28 from telemetry.testing import fakes
25 from telemetry.testing import options_for_unittests 29 from telemetry.testing import options_for_unittests
26 from telemetry.testing import system_stub 30 from telemetry.testing import system_stub
27 import mock 31 import mock
28 from telemetry.value import failure 32 from telemetry.value import failure
29 from telemetry.value import improvement_direction 33 from telemetry.value import improvement_direction
30 from telemetry.value import list_of_scalar_values 34 from telemetry.value import list_of_scalar_values
31 from telemetry.value import scalar 35 from telemetry.value import scalar
32 from telemetry.value import skip 36 from telemetry.value import skip
33 from telemetry.value import summary as summary_module 37 from telemetry.value import summary as summary_module
34 from telemetry.web_perf import story_test 38 from telemetry.web_perf import story_test
35 from telemetry.web_perf import timeline_based_measurement 39 from telemetry.web_perf import timeline_based_measurement
36 from telemetry.wpr import archive_info 40 from telemetry.wpr import archive_info
37 41
38 # This linter complains if we define classes nested inside functions. 42 # This linter complains if we define classes nested inside functions.
39 # pylint: disable=bad-super-call 43 # pylint: disable=bad-super-call
40 44
41 # pylint: disable=too-many-lines 45 # pylint: disable=too-many-lines
42 46
43
44 class FakePlatform(object): 47 class FakePlatform(object):
45 def CanMonitorThermalThrottling(self): 48 def CanMonitorThermalThrottling(self):
46 return False 49 return False
47 50
48 def GetOSName(self): 51 def GetOSName(self):
49 pass 52 pass
50 53
51 def WaitForTemperature(self, _): 54 def WaitForTemperature(self, _):
52 pass 55 pass
53 56
54 def GetDeviceTypeName(self): 57 def GetDeviceTypeName(self):
55 return "GetDeviceTypeName" 58 return "GetDeviceTypeName"
56 59
57
58 class TestSharedState(story_module.SharedState): 60 class TestSharedState(story_module.SharedState):
59 61
60 _platform = FakePlatform() 62 _platform = FakePlatform()
61 63
62 @classmethod 64 @classmethod
63 def SetTestPlatform(cls, platform): 65 def SetTestPlatform(cls, platform):
64 cls._platform = platform 66 cls._platform = platform
65 67
66 def __init__(self, test, options, story_set): 68 def __init__(self, test, options, story_set):
67 super(TestSharedState, self).__init__( 69 super(TestSharedState, self).__init__(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 def SetupStorySet(allow_multiple_story_states, story_state_list): 146 def SetupStorySet(allow_multiple_story_states, story_state_list):
145 if allow_multiple_story_states: 147 if allow_multiple_story_states:
146 story_set = MixedStateStorySet() 148 story_set = MixedStateStorySet()
147 else: 149 else:
148 story_set = story_module.StorySet() 150 story_set = story_module.StorySet()
149 for i, story_state in enumerate(story_state_list): 151 for i, story_state in enumerate(story_state_list):
150 story_set.AddStory(DummyLocalStory(story_state, 152 story_set.AddStory(DummyLocalStory(story_state,
151 name='story%d' % i)) 153 name='story%d' % i))
152 return story_set 154 return story_set
153 155
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
154 166
155 def _GetOptionForUnittest(): 167 def _GetOptionForUnittest():
156 options = options_for_unittests.GetCopy() 168 options = options_for_unittests.GetCopy()
157 options.output_formats = ['none'] 169 options.output_formats = ['none']
158 options.suppress_gtest_report = False 170 options.suppress_gtest_report = False
159 parser = options.CreateParser() 171 parser = options.CreateParser()
160 story_runner.AddCommandLineArgs(parser) 172 story_runner.AddCommandLineArgs(parser)
161 options.MergeDefaultValues(parser.get_default_values()) 173 options.MergeDefaultValues(parser.get_default_values())
162 story_runner.ProcessCommandLineArgs(parser, options) 174 story_runner.ProcessCommandLineArgs(parser, options)
163 return options 175 return options
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 mock.call.test.WillRunStory(root_mock.state.platform), 1041 mock.call.test.WillRunStory(root_mock.state.platform),
1030 mock.call.state.WillRunStory(root_mock.story), 1042 mock.call.state.WillRunStory(root_mock.story),
1031 mock.call.state.CanRunStory(root_mock.story), 1043 mock.call.state.CanRunStory(root_mock.story),
1032 mock.call.state.RunStory(root_mock.results), 1044 mock.call.state.RunStory(root_mock.results),
1033 mock.call.test.Measure(root_mock.state.platform, root_mock.results), 1045 mock.call.test.Measure(root_mock.state.platform, root_mock.results),
1034 mock.call.state.DumpStateUponFailure(root_mock.story, root_mock.results), 1046 mock.call.state.DumpStateUponFailure(root_mock.story, root_mock.results),
1035 mock.call.results.AddValue(FailureValueMatcher('foo')), 1047 mock.call.results.AddValue(FailureValueMatcher('foo')),
1036 mock.call.state.DidRunStory(root_mock.results), 1048 mock.call.state.DidRunStory(root_mock.results),
1037 mock.call.test.DidRunStory(root_mock.state.platform) 1049 mock.call.test.DidRunStory(root_mock.state.platform)
1038 ]) 1050 ])
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