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

Side by Side Diff: tools/perf/core/trybot_command_unittest.py

Issue 2287993004: Use git cl try --properties option to send test arguments instead of run-perf-test.cfg (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 3 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
« no previous file with comments | « tools/perf/core/trybot_command.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 argparse 4 import argparse
5 import json
5 import logging 6 import logging
6 import json 7 import os
7 import StringIO 8 import StringIO
9 import sys
8 import unittest 10 import unittest
9 11
12 from core import trybot_command
10 import mock 13 import mock
11
12 from telemetry import benchmark 14 from telemetry import benchmark
13 from telemetry.testing import system_stub
14
15 from core import trybot_command
16 15
17 16
18 class FakeProcess(object): 17 class FakeProcess(object):
19 18
20 def __init__(self, expected_responses): 19 def __init__(self, expected_responses):
21 self._communicate = expected_responses[1:] 20 self._communicate = expected_responses[1:]
22 self._poll = expected_responses[0] 21 self._poll = expected_responses[0]
23 22
24 def communicate(self): 23 def communicate(self):
25 return self._communicate 24 return self._communicate
26 25
27 def poll(self): 26 def poll(self):
28 return self._poll 27 return self._poll
29 28
30 29
31 class TrybotCommandTest(unittest.TestCase): 30 class TrybotCommandTest(unittest.TestCase):
32 31
33 # pylint: disable=protected-access 32 # pylint: disable=protected-access
34 33
35 def setUp(self): 34 def setUp(self):
36 self.log_output = StringIO.StringIO() 35 self.log_output = StringIO.StringIO()
37 self.stream_handler = logging.StreamHandler(self.log_output) 36 self.stream_handler = logging.StreamHandler(self.log_output)
38 logging.getLogger().addHandler(self.stream_handler) 37 logging.getLogger().addHandler(self.stream_handler)
39 self._subprocess_patcher = mock.patch('core.trybot_command.subprocess') 38 self._subprocess_patcher = mock.patch('core.trybot_command.subprocess')
40 self._mock_subprocess = self._subprocess_patcher.start() 39 self._mock_subprocess = self._subprocess_patcher.start()
41 self._urllib2_patcher = mock.patch('core.trybot_command.urllib2') 40 self._urllib2_patcher = mock.patch('core.trybot_command.urllib2')
42 self._urllib2_mock = self._urllib2_patcher.start() 41 self._urllib2_mock = self._urllib2_patcher.start()
43 self._stubs = system_stub.Override(trybot_command,
44 ['sys', 'open', 'os'])
45 # Always set git command to 'git' to simplify testing across platforms. 42 # Always set git command to 'git' to simplify testing across platforms.
46 self._original_git_cmd = trybot_command._GIT_CMD 43 self._original_git_cmd = trybot_command._GIT_CMD
47 trybot_command._GIT_CMD = 'git' 44 trybot_command._GIT_CMD = 'git'
48 45
49 def tearDown(self): 46 def tearDown(self):
50 logging.getLogger().removeHandler(self.stream_handler) 47 logging.getLogger().removeHandler(self.stream_handler)
51 self.log_output.close() 48 self.log_output.close()
52 self._stubs.Restore()
53 self._subprocess_patcher.stop() 49 self._subprocess_patcher.stop()
54 self._urllib2_patcher.stop() 50 self._urllib2_patcher.stop()
55 # Reset the cached builders in trybot_command 51 # Reset the cached builders in trybot_command
56 trybot_command.Trybot._builders = None 52 trybot_command.Trybot._builders = None
57 trybot_command._GIT_CMD = self._original_git_cmd 53 trybot_command._GIT_CMD = self._original_git_cmd
58 54
59 def _ExpectProcesses(self, expected_args_list): 55 def _ExpectProcesses(self, expected_args_list):
60 counter = [-1] 56 counter = [-1]
61
62 def side_effect(args, **kwargs): 57 def side_effect(args, **kwargs):
63 if not expected_args_list: 58 if not expected_args_list:
64 self.fail( 59 self.fail(
65 'Not expect any Popen() call but got a Popen call with %s\n' % args) 60 'Not expect any Popen() call but got a Popen call with %s\n' % args)
66 del kwargs # unused 61 del kwargs # unused
67 counter[0] += 1 62 counter[0] += 1
68 expected_args, expected_responses = expected_args_list[counter[0]] 63 expected_args, expected_responses = expected_args_list[counter[0]]
69 self.assertEquals( 64 self.assertEquals(
70 expected_args, args, 65 expected_args, args,
71 'Popen() is called with unexpected args.\n Actual: %s.\n' 66 'Popen() is called with unexpected args.\n Actual: %s.\n'
72 'Expecting (index %i): %s' % (args, counter[0], expected_args)) 67 'Expecting (index %i): %s' % (args, counter[0], expected_args))
73 return FakeProcess(expected_responses) 68 return FakeProcess(expected_responses)
74 self._mock_subprocess.Popen.side_effect = side_effect 69 self._mock_subprocess.Popen.side_effect = side_effect
75 70
76 def _MockBuilderList(self): 71 def _MockBuilderList(self):
77 ExcludedBots = trybot_command.EXCLUDED_BOTS 72 excluded_bots = trybot_command.EXCLUDED_BOTS
78 builders = [bot for bot in self._builder_list if bot not in ExcludedBots] 73 builders = [bot for bot in self._builder_list if bot not in excluded_bots]
79 return builders 74 return builders
80 75
81 def _MockTryserverJson(self, bots_dict): 76 def _MockTryserverJson(self, bots_dict):
82 data = mock.Mock() 77 data = mock.Mock()
83 data.read.return_value = json.dumps(bots_dict) 78 data.read.return_value = json.dumps(bots_dict)
84 self._urllib2_mock.urlopen.return_value = data 79 self._urllib2_mock.urlopen.return_value = data
85 80
81 def _AssertTryBotExceptions(self, message, func, *args):
82 with self.assertRaises(trybot_command.TrybotError) as e:
83 func(*args)
84 self.assertIn(message, e.exception.message)
85
86 def _SetupTrybotCommand(self, try_json_dict, trybot):
87 self._MockTryserverJson(try_json_dict)
88 command = trybot_command.Trybot()
89 command._InitializeBuilderNames(trybot)
90 return command
91
92 def _GetConfigForTrybot(self, name, platform, extra_benchmark_args=None):
93 bot = '%s_perf_bisect' % name.replace('', '').replace('-', '_')
94 command = self._SetupTrybotCommand({bot: 'stuff'}, name)
95 options = argparse.Namespace(trybot=name, benchmark_name='sunspider')
96 extra_benchmark_args = extra_benchmark_args or []
97 arguments = [options.benchmark_name] + extra_benchmark_args
98 cfg = command._GetPerfConfig(platform, arguments)
99
100 return cfg, command
101
102 def _ExpectedGitTryTestArgs(self, test_name, browser, target_arch='ia32'):
103 return ('perf_try_config={'
104 '"repeat_count": "1", "command": "src/tools/perf/run_benchmark '
105 '--browser=%s %s --verbose", "max_time_minutes": "120", '
106 '"target_arch": "%s", "truncate_percent": "0"}' % (
107 browser, test_name, target_arch))
108
86 def testFindAllBrowserTypesList(self): 109 def testFindAllBrowserTypesList(self):
87 self._MockTryserverJson({ 110 self._MockTryserverJson({
88 'android_nexus4_perf_bisect': 'stuff', 111 'android_nexus4_perf_bisect': 'stuff',
89 'mac_10_9_perf_bisect': 'otherstuff', 112 'mac_10_9_perf_bisect': 'otherstuff',
90 'win_perf_bisect_builder': 'not a trybot', 113 'win_perf_bisect_builder': 'not a trybot',
91 }) 114 })
92 expected_trybots_list = [ 115 expected_trybots_list = [
93 'all', 116 'all',
94 'all-android', 117 'all-android',
95 'all-linux', 118 'all-linux',
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 command = trybot_command.Trybot() 271 command = trybot_command.Trybot()
249 command._InitializeBuilderNames('all-linux') 272 command._InitializeBuilderNames('all-linux')
250 self.assertEquals( 273 self.assertEquals(
251 ['linux'], 274 ['linux'],
252 sorted(command._builder_names)) 275 sorted(command._builder_names))
253 self.assertEquals( 276 self.assertEquals(
254 ['linux_perf_bisect'], 277 ['linux_perf_bisect'],
255 sorted(command._builder_names.get('linux'))) 278 sorted(command._builder_names.get('linux')))
256 279
257 def testNoGit(self): 280 def testNoGit(self):
258 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) 281 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
259 command = trybot_command.Trybot()
260 command._InitializeBuilderNames('android-nexus4')
261 self._ExpectProcesses(( 282 self._ExpectProcesses((
262 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'], (128, None, None)), 283 (['git', 'rev-parse', '--abbrev-ref', '--show-toplevel', 'HEAD'],
284 (128, None, None)),
263 )) 285 ))
264 options = argparse.Namespace(trybot='android', benchmark_name='dromaeo') 286 self._AssertTryBotExceptions(
265 command.Run(options) 287 ('%s is not a git repository, must be in a git repository to send '
266 self.assertEquals( 288 'changes to trybots.' % os.getcwd()),
267 'Must be in a git repository to send changes to trybots.\n', 289 command._GetRepoAndBranchName,
268 self.log_output.getvalue()) 290 trybot_command.CHROMIUM_SRC_PATH
291 )
292
293 def testDettachedBranch(self):
294 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
295 self._ExpectProcesses((
296 (['git', 'rev-parse', '--abbrev-ref', '--show-toplevel', 'HEAD'],
297 (0, '/root/path_to/repo/src\nHEAD\n', None)),
298 ))
299 self._AssertTryBotExceptions(
300 'Not on a valid branch, looks like branch is dettached. [branch:HEAD]',
301 command._GetRepoAndBranchName,
302 trybot_command.CHROMIUM_SRC_PATH
303 )
269 304
270 def testDirtyTree(self): 305 def testDirtyTree(self):
271 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) 306 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
272 self._ExpectProcesses(( 307 self._ExpectProcesses((
273 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'], (0, 'br', None)), 308 (['git', 'rev-parse', '--abbrev-ref', '--show-toplevel', 'HEAD'],
309 (0, '/root/path_to/repo/src\nbr\n', None)),
274 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)), 310 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)),
275 (['git', 'diff-index', 'HEAD'], (0, 'dirty tree', None)), 311 (['git', 'diff-index', 'HEAD'], (0, 'dirty tree', None)),
276 )) 312 ))
277 options = argparse.Namespace(trybot='android-nexus4', benchmark_name='foo') 313 self._AssertTryBotExceptions(
278 command = trybot_command.Trybot() 314 'Cannot send a try job with a dirty tree.',
279 command.Run(options, []) 315 command._GetRepoAndBranchName,
280 self.assertEquals( 316 trybot_command.CHROMIUM_SRC_PATH
281 'Cannot send a try job with a dirty tree. Commit locally first.\n', 317 )
282 self.log_output.getvalue())
283 318
284 def testNoLocalCommits(self): 319 def testNoLocalCommits(self):
285 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) 320 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
286 command = trybot_command.Trybot()
287 command._InitializeBuilderNames('android-nexus4')
288 self._ExpectProcesses(( 321 self._ExpectProcesses((
289 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'], (0, 'br', None)), 322 (['git', 'rev-parse', '--abbrev-ref', '--show-toplevel', 'HEAD'],
323 (0, '/root/path_to/repo/src\nbr\n', None)),
290 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)), 324 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)),
291 (['git', 'diff-index', 'HEAD'], (0, '', None)), 325 (['git', 'diff-index', 'HEAD'], (0, '', None)),
292 (['git', 'log', 'origin/master..HEAD'], (0, '', None)), 326 (['git', 'footers', 'HEAD'], (0, 'CL footers', None)),
293 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'], (0, 'br', None)), 327 ))
328 self._AssertTryBotExceptions(
329 'No local changes found in %s repository.' %
330 trybot_command.CHROMIUM_SRC_PATH,
331 command._GetRepoAndBranchName,
332 trybot_command.CHROMIUM_SRC_PATH
333 )
334
335 def testGetRepoAndBranchName(self):
336 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
337 self._ExpectProcesses((
338 (['git', 'rev-parse', '--abbrev-ref', '--show-toplevel', 'HEAD'],
339 (0, '/root/path_to/repo/src\nbr\n', None)),
294 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)), 340 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)),
295 (['git', 'diff-index', 'HEAD'], (0, '', None)), 341 (['git', 'diff-index', 'HEAD'], (0, '', None)),
296 (['git', 'log', 'origin/master..HEAD'], (0, '', None)), 342 (['git', 'footers', 'HEAD'], (0, '', None)),
297 )) 343 ))
298
299 options = argparse.Namespace(trybot='android-nexus4', benchmark_name='foo')
300 command.Run(options)
301 self.assertEquals( 344 self.assertEquals(
302 ('No local changes found in chromium or blink trees. ' 345 command._GetRepoAndBranchName(
303 'browser=android-nexus4 argument sends local changes to the ' 346 trybot_command.CHROMIUM_SRC_PATH), ('src', 'br'))
304 'perf trybot(s): '
305 '[[\'android_nexus4_perf_bisect\']].\n'),
306 self.log_output.getvalue())
307 347
308 def testErrorOnBrowserArgSpecified(self): 348 def testErrorOnBrowserArgSpecified(self):
309 parser = trybot_command.Trybot.CreateParser() 349 parser = trybot_command.Trybot.CreateParser()
310 options, extra_args = parser.parse_known_args( 350 options, extra_args = parser.parse_known_args(
311 ['sunspider', '--trybot=android-all', '--browser=mac']) 351 ['sunspider', '--trybot=android-all', '--browser=mac'])
312 with self.assertRaises(SystemExit): 352 with self.assertRaises(SystemExit):
313 trybot_command.Trybot.ProcessCommandLineArgs( 353 trybot_command.Trybot.ProcessCommandLineArgs(
314 parser, options, extra_args, None) 354 parser, options, extra_args, None)
315 355
316 def testBranchCheckoutFails(self): 356 def testConfigAndroid(self):
317 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) 357 config, _ = self._GetConfigForTrybot('android-nexus4', 'android')
318 self._ExpectProcesses((
319 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'], (0, 'br', None)),
320 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)),
321 (['git', 'diff-index', 'HEAD'], (0, '', None)),
322 (['git', 'log', 'origin/master..HEAD'], (0, 'logs here', None)),
323 (['git', 'checkout', '-b', 'telemetry-tryjob'],
324 (1, None, 'fatal: A branch named \'telemetry-try\' already exists.')),
325 ))
326
327 command = trybot_command.Trybot()
328 options = argparse.Namespace(trybot='android-nexus4', benchmark_name='foo')
329 command.Run(options, [])
330 self.assertEquals( 358 self.assertEquals(
331 ('Error creating branch telemetry-tryjob. ' 359 {'command': ('src/tools/perf/run_benchmark '
332 'Please delete it if it exists.\n' 360 '--browser=android-chromium sunspider --verbose'),
333 'fatal: A branch named \'telemetry-try\' already exists.\n'), 361 'max_time_minutes': '120',
334 self.log_output.getvalue()) 362 'repeat_count': '1',
335 363 'target_arch': 'ia32',
336 def _GetConfigForTrybot(self, name, platform, branch, cfg_filename, 364 'truncate_percent': '0'
337 is_blink=False, extra_benchmark_args=None): 365 }, config)
338 bot = '%s_perf_bisect' % name.replace('', '').replace('-', '_')
339 self._MockTryserverJson({bot: 'stuff'})
340 first_processes = ()
341 if is_blink:
342 first_processes = (
343 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'], (0, 'br', None)),
344 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)),
345 (['git', 'diff-index', 'HEAD'], (0, '', None)),
346 (['git', 'log', 'origin/master..HEAD'], (0, '', None))
347 )
348 self._ExpectProcesses(first_processes + (
349 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'], (0, branch, None)),
350 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)),
351 (['git', 'diff-index', 'HEAD'], (0, '', None)),
352 (['git', 'log', 'origin/master..HEAD'], (0, 'logs here', None)),
353 (['git', 'checkout', '-b', 'telemetry-tryjob'], (0, None, None)),
354 (['git', 'branch', '--set-upstream-to', 'origin/master'],
355 (0, None, None)),
356 (['git', 'commit', '-a', '-m', 'bisect config: %s' % platform],
357 (0, None, None)),
358 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m',
359 'CL for perf tryjob on %s' % platform],
360 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)),
361 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', bot],
362 (0, None, None)),
363 (['git', 'checkout', branch], (0, None, None)),
364 (['git', 'branch', '-D', 'telemetry-tryjob'], (0, None, None))
365 ))
366 cfg = StringIO.StringIO()
367 self._stubs.open.files = {cfg_filename: cfg}
368
369 options = argparse.Namespace(trybot=name, benchmark_name='sunspider')
370 command = trybot_command.Trybot()
371 extra_benchmark_args = extra_benchmark_args or []
372 command.Run(options, extra_benchmark_args)
373 return cfg.getvalue()
374
375 def testConfigAndroid(self):
376 config = self._GetConfigForTrybot(
377 'android-nexus4', 'android', 'somebranch',
378 'tools/run-perf-test.cfg')
379 self.assertEquals(
380 ('config = {\n'
381 ' "command": "./tools/perf/run_benchmark '
382 '--browser=android-chromium sunspider --verbose",\n'
383 ' "max_time_minutes": "120",\n'
384 ' "repeat_count": "1",\n'
385 ' "target_arch": "ia32",\n'
386 ' "truncate_percent": "0"\n'
387 '}'), config)
388 366
389 def testConfigMac(self): 367 def testConfigMac(self):
390 config = self._GetConfigForTrybot( 368 config, _ = self._GetConfigForTrybot('mac-10-9', 'mac')
391 'mac-10-9', 'mac', 'currentwork', 'tools/run-perf-test.cfg')
392 self.assertEquals( 369 self.assertEquals(
393 ('config = {\n' 370 {'command': ('src/tools/perf/run_benchmark '
394 ' "command": "./tools/perf/run_benchmark ' 371 '--browser=release sunspider --verbose'),
395 '--browser=release sunspider --verbose",\n' 372 'max_time_minutes': '120',
396 ' "max_time_minutes": "120",\n' 373 'repeat_count': '1',
397 ' "repeat_count": "1",\n' 374 'target_arch': 'ia32',
398 ' "target_arch": "ia32",\n' 375 'truncate_percent': '0'
399 ' "truncate_percent": "0"\n' 376 }, config)
400 '}'), config)
401 377
402 def testConfigWinX64(self): 378 def testConfigWinX64(self):
403 config = self._GetConfigForTrybot( 379 config, _ = self._GetConfigForTrybot('win-x64', 'win-x64')
404 'win-x64', 'win-x64', 'currentwork', 'tools/run-perf-test.cfg') 380
405 self.assertEquals( 381 self.assertEquals(
406 ('config = {\n' 382 {'command': ('src/tools/perf/run_benchmark '
407 ' "command": "python tools\\\\perf\\\\run_benchmark ' 383 '--browser=release_x64 sunspider --verbose'),
408 '--browser=release_x64 sunspider --verbose",\n' 384 'max_time_minutes': '120',
409 ' "max_time_minutes": "120",\n' 385 'repeat_count': '1',
410 ' "repeat_count": "1",\n' 386 'target_arch': 'x64',
411 ' "target_arch": "x64",\n' 387 'truncate_percent': '0'
412 ' "truncate_percent": "0"\n' 388 }, config)
413 '}'), config)
414 389
415 def testVerboseOptionIsNotAddedTwice(self): 390 def testVerboseOptionIsNotAddedTwice(self):
416 config = self._GetConfigForTrybot( 391 config, _ = self._GetConfigForTrybot(
417 'win-x64', 'win-x64', 'currentwork', 'tools/run-perf-test.cfg', 392 'win-x64', 'win-x64', extra_benchmark_args=['-v'])
418 extra_benchmark_args=['-v'])
419 self.assertEquals( 393 self.assertEquals(
420 ('config = {\n' 394 {'command': ('src/tools/perf/run_benchmark '
421 ' "command": "python tools\\\\perf\\\\run_benchmark ' 395 '--browser=release_x64 sunspider -v'),
422 '--browser=release_x64 sunspider -v",\n' 396 'max_time_minutes': '120',
423 ' "max_time_minutes": "120",\n' 397 'repeat_count': '1',
424 ' "repeat_count": "1",\n' 398 'target_arch': 'x64',
425 ' "target_arch": "x64",\n' 399 'truncate_percent': '0'
426 ' "truncate_percent": "0"\n' 400 }, config)
427 '}'), config)
428 401
429 def testConfigWinX64WithNoHyphen(self): 402 def testConfigWinX64WithNoHyphen(self):
430 config = self._GetConfigForTrybot( 403 config, _ = self._GetConfigForTrybot('winx64nvidia', 'win-x64')
431 'winx64nvidia', 'win-x64', 'currentwork', 'tools/run-perf-test.cfg')
432 self.assertEquals( 404 self.assertEquals(
433 ('config = {\n' 405 {'command': ('src/tools/perf/run_benchmark '
434 ' "command": "python tools\\\\perf\\\\run_benchmark ' 406 '--browser=release_x64 sunspider --verbose'),
435 '--browser=release_x64 sunspider --verbose",\n' 407 'max_time_minutes': '120',
436 ' "max_time_minutes": "120",\n' 408 'repeat_count': '1',
437 ' "repeat_count": "1",\n' 409 'target_arch': 'x64',
438 ' "target_arch": "x64",\n' 410 'truncate_percent': '0'
439 ' "truncate_percent": "0"\n' 411 }, config)
440 '}'), config)
441 412
442 def testUnsupportedTrybot(self): 413 def testUnsupportedTrybot(self):
443 self.assertRaises( 414 self.assertRaises(
444 trybot_command.TrybotError, 415 trybot_command.TrybotError,
445 trybot_command._GetBuilderNames, 416 trybot_command._GetBuilderNames,
446 'arms-nvidia', 417 'arms-nvidia',
447 {'win_perf_bisect': 'stuff'} 418 {'win_perf_bisect': 'stuff'}
448 ) 419 )
449 420
450 def testConfigBlink(self): 421 def testUploadPatchToRietveldGitCommandFailed(self):
451 config = self._GetConfigForTrybot( 422 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
452 'mac-10-9', 'mac', 'blinkbranch', 423 options = argparse.Namespace(trybot='linux', benchmark_name='sunspider')
453 'Tools/run-perf-test.cfg', True) 424 self._ExpectProcesses((
454 self.assertEquals( 425 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m',
455 ('config = {\n' 426 ('CL for src perf tryjob to run sunspider benchmark on linux '
456 ' "command": "./tools/perf/run_benchmark ' 427 'platform(s)')],
457 '--browser=release sunspider --verbose",\n' 428 (128, None, None)),
458 ' "max_time_minutes": "120",\n' 429 ))
459 ' "repeat_count": "1",\n' 430 self._AssertTryBotExceptions(
460 ' "target_arch": "ia32",\n' 431 'Could not upload to rietveld for src',
461 ' "truncate_percent": "0"\n' 432 command._UploadPatchToRietveld,
462 '}'), config) 433 'src',
434 options
435 )
463 436
464 def testUpdateConfigGitCommitTrybotError(self): 437 def testUploadPatchToRietveldNoURLMatchFound(self):
465 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) 438 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
466 command = trybot_command.Trybot() 439 options = argparse.Namespace(trybot='linux', benchmark_name='sunspider')
467 command._InitializeBuilderNames('android-nexus4')
468 self._ExpectProcesses(( 440 self._ExpectProcesses((
469 (['git', 'commit', '-a', '-m', 'bisect config: android'],
470 (128, 'None', 'commit failed')),
471 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m', 441 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m',
472 'CL for perf tryjob on android'], 442 ('CL for src perf tryjob to run sunspider benchmark on linux '
443 'platform(s)')],
444 (0, 'stuff https://dummy.chromium.org/12345 stuff', None)),
445 ))
446 self._AssertTryBotExceptions(
447 'Could not upload CL to rietveld for src!',
448 command._UploadPatchToRietveld,
449 'src',
450 options
451 )
452
453 def testUploadPatchToRietveldOnSuccess(self):
454 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
455 options = argparse.Namespace(trybot='linux', benchmark_name='sunspider')
456 self._ExpectProcesses((
457 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m',
458 ('CL for src perf tryjob to run sunspider benchmark on linux '
459 'platform(s)')],
473 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)), 460 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)),
474 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', 461 ))
475 'android_nexus4_perf_bisect'], (0, None, None)))) 462 self.assertEquals(command._UploadPatchToRietveld('src', options),
476 cfg_filename = 'tools/run-perf-test.cfg' 463 'https://codereview.chromium.org/12345')
477 cfg = StringIO.StringIO()
478 self._stubs.open.files = {cfg_filename: cfg}
479 self.assertRaises(
480 trybot_command.TrybotError, command._UpdateConfigAndRunTryjob,
481 'android', cfg_filename, [])
482 464
483 def testUpdateConfigGitUploadTrybotError(self): 465 def testRunTryJobFailed(self):
484 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) 466 test_args = self._ExpectedGitTryTestArgs('sunspider', 'release')
485 command = trybot_command.Trybot() 467 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
486 command._InitializeBuilderNames('android-nexus4') 468 options = argparse.Namespace(trybot='linux', benchmark_name='sunspider')
469 arguments = [options.benchmark_name] + []
487 self._ExpectProcesses(( 470 self._ExpectProcesses((
488 (['git', 'commit', '-a', '-m', 'bisect config: android'], 471 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf',
489 (0, 'None', None)), 472 '-p', test_args,
473 '-b',
474 'linux_perf_bisect'], (128, None, None)),))
475 self._AssertTryBotExceptions(
476 'Could not try CL for linux',
477 command._RunTryJob, 'linux', arguments)
478
479 def testRunTryJobSuccess(self):
480 test_args = self._ExpectedGitTryTestArgs('sunspider', 'release')
481 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
482 options = argparse.Namespace(trybot='linux', benchmark_name='sunspider')
483 arguments = [options.benchmark_name] + []
484 self._ExpectProcesses((
485 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf',
486 '-p', test_args,
487 '-b',
488 'linux_perf_bisect'], (0, None, None)),))
489 command._RunTryJob('linux', arguments)
490 self.assertEquals('Perf Try job sent to rietveld for linux platform.',
491 sys.stdout.getvalue().strip())
492
493 def testAttemptTryjobForCrRepo(self):
494 test_args = self._ExpectedGitTryTestArgs('sunspider', 'release')
495 command = self._SetupTrybotCommand({'linux_perf_bisect': 'stuff'}, 'linux')
496 options = argparse.Namespace(trybot='linux', benchmark_name='sunspider')
497
498 self._ExpectProcesses((
499 (['git', 'rev-parse', '--abbrev-ref', '--show-toplevel', 'HEAD'],
500 (0, '/root/path_to/repo/src\nbr\n', None)),
501 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)),
502 (['git', 'diff-index', 'HEAD'], (0, '', None)),
503 (['git', 'footers', 'HEAD'], (0, '', None)),
490 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m', 504 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m',
491 'CL for perf tryjob on android'], 505 ('CL for src perf tryjob to run sunspider benchmark on linux '
492 (128, None, 'error')), 506 'platform(s)')],
493 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', 507 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)),
494 'android_nexus4_perf_bisect'], (0, None, None)))) 508 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf',
495 cfg_filename = 'tools/run-perf-test.cfg' 509 '-p', test_args, '-b', 'linux_perf_bisect'], (0, None, None))
496 cfg = StringIO.StringIO() 510 ))
497 self._stubs.open.files = {cfg_filename: cfg} 511 command._AttemptTryjob(trybot_command.CHROMIUM_SRC_PATH, options, [])
498 self.assertRaises(
499 trybot_command.TrybotError, command._UpdateConfigAndRunTryjob,
500 'android', cfg_filename, [])
501 512
502 def testUpdateConfigGitTryTrybotError(self): 513 output = ('Uploaded try job to rietveld.\n'
503 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) 514 'view progress here https://codereview.chromium.org/12345.\n'
504 command = trybot_command.Trybot() 515 '\tRepo Name: src\n'
505 command._InitializeBuilderNames('android-nexus4') 516 '\tPath: %s\n'
517 '\tBranch: br\n'
518 'Perf Try job sent to rietveld for linux platform.') % (
519 trybot_command.CHROMIUM_SRC_PATH)
520 self.assertEquals(output, sys.stdout.getvalue().strip())
521
522 def testAttemptTryjobAllForCrRepo(self):
523 default_config = self._ExpectedGitTryTestArgs('sunspider', 'release')
524 winx64_config = self._ExpectedGitTryTestArgs(
525 'sunspider', 'release_x64', 'x64')
526 android_config = self._ExpectedGitTryTestArgs(
527 'sunspider', 'android-chromium', 'ia32')
528
529 command = self._SetupTrybotCommand(
530 {'linux_perf_bisect': 'stuff',
531 'win_perf_bisect': 'stuff',
532 'winx64_perf_bisect': 'stuff',
533 'android_perf_bisect': 'stuff',
534 'mac_perf_bisect': 'stuff'}, 'all')
535 options = argparse.Namespace(trybot='all', benchmark_name='sunspider')
506 self._ExpectProcesses(( 536 self._ExpectProcesses((
507 (['git', 'commit', '-a', '-m', 'bisect config: android'], 537 (['git', 'rev-parse', '--abbrev-ref', '--show-toplevel', 'HEAD'],
508 (0, 'None', None)), 538 (0, '/root/path_to/repo/src\nbr\n', None)),
539 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)),
540 (['git', 'diff-index', 'HEAD'], (0, '', None)),
541 (['git', 'footers', 'HEAD'], (0, '', None)),
509 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m', 542 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m',
510 'CL for perf tryjob on android'], 543 ('CL for src perf tryjob to run sunspider benchmark on all '
544 'platform(s)')],
511 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)), 545 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)),
512 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', 546 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf',
513 'android_nexus4_perf_bisect'], (128, None, None)))) 547 '-p', default_config, '-b', 'win_perf_bisect'], (0, None, None)),
514 cfg_filename = 'tools/run-perf-test.cfg' 548 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf',
515 cfg = StringIO.StringIO() 549 '-p', android_config, '-b', 'android_perf_bisect'], (0, None, None)),
516 self._stubs.open.files = {cfg_filename: cfg} 550 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf',
517 self.assertRaises( 551 '-p', winx64_config, '-b', 'winx64_perf_bisect'], (0, None, None)),
518 trybot_command.TrybotError, command._UpdateConfigAndRunTryjob, 552 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf',
519 'android', cfg_filename, []) 553 '-p', default_config, '-b', 'mac_perf_bisect'], (0, None, None)),
520 554 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf',
521 def testUpdateConfigSkipTryjob(self): 555 '-p', default_config, '-b', 'linux_perf_bisect'], (0, None, None)),
522 self._MockTryserverJson({'win_perf_bisect': 'stuff'}) 556 ))
523 command = trybot_command.Trybot() 557 command._AttemptTryjob(trybot_command.CHROMIUM_SRC_PATH, options, [])
524 command._InitializeBuilderNames('win-x64') 558 output = ('Uploaded try job to rietveld.\n'
525 self._ExpectProcesses(()) 559 'view progress here https://codereview.chromium.org/12345.\n'
526 cfg_filename = 'tools/run-perf-test.cfg' 560 '\tRepo Name: src\n'
527 cfg_data = ('''config = { 561 '\tPath: %s\n'
528 "command": "python tools\\\\perf\\\\run_benchmark --browser=release_x64''' 562 '\tBranch: br\n'
529 ''' --verbose", 563 'Perf Try job sent to rietveld for win platform.\n'
530 "max_time_minutes": "120", 564 'Perf Try job sent to rietveld for android platform.\n'
531 "repeat_count": "1", 565 'Perf Try job sent to rietveld for win-x64 platform.\n'
532 "target_arch": "x64", 566 'Perf Try job sent to rietveld for mac platform.\n'
533 "truncate_percent": "0" 567 'Perf Try job sent to rietveld for linux platform.') % (
534 }''') 568 trybot_command.CHROMIUM_SRC_PATH)
535 self._stubs.open.files = {cfg_filename: cfg_data} 569 self.assertEquals(output, sys.stdout.getvalue().strip())
536 self.assertEquals((trybot_command.NO_CHANGES, ''),
537 command._UpdateConfigAndRunTryjob(
538 'win-x64', cfg_filename, []))
539
540 def testUpdateConfigGitTry(self):
541 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'})
542 command = trybot_command.Trybot()
543 command._InitializeBuilderNames('android-nexus4')
544 self._ExpectProcesses((
545 (['git', 'commit', '-a', '-m', 'bisect config: android'],
546 (0, 'None', None)),
547 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m',
548 'CL for perf tryjob on android'],
549 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)),
550 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b',
551 'android_nexus4_perf_bisect'], (0, None, None))))
552 cfg_filename = 'tools/run-perf-test.cfg'
553 cfg = StringIO.StringIO()
554 self._stubs.open.files = {cfg_filename: cfg}
555 self.assertEquals((0, 'https://codereview.chromium.org/12345'),
556 command._UpdateConfigAndRunTryjob(
557 'android', cfg_filename, []))
558 cfg.seek(0)
559 config = '''config = {
560 "command": "./tools/perf/run_benchmark --browser=android-chromium --verbose",
561 "max_time_minutes": "120",
562 "repeat_count": "1",
563 "target_arch": "ia32",
564 "truncate_percent": "0"
565 }'''
566 self.assertEquals(cfg.read(), config)
567
568 def testUpdateConfigGitTryAll(self):
569 self._MockTryserverJson({
570 'android_nexus4_perf_bisect': 'stuff',
571 'win_8_perf_bisect': 'stuff2'
572 })
573 command = trybot_command.Trybot()
574 command._InitializeBuilderNames('all')
575 self._ExpectProcesses((
576 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
577 (0, 'CURRENT-BRANCH', None)),
578 (['git', 'update-index', '--refresh', '-q'],
579 (0, '', None)),
580 (['git', 'diff-index', 'HEAD'],
581 (0, '', None)),
582 (['git', 'log', 'origin/master..HEAD'],
583 (0, 'abcdef', None)),
584 (['git', 'checkout', '-b', 'telemetry-tryjob'],
585 (0, '', None)),
586 (['git', 'branch', '--set-upstream-to', 'origin/master'],
587 (0, '', None)),
588 (['git', 'commit', '-a', '-m', 'bisect config: win'],
589 (0, 'None', None)),
590 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m',
591 'CL for perf tryjob on win'],
592 (0, 'stuff2 https://codereview.chromium.org/12345 stuff2', None)),
593 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b',
594 'win_8_perf_bisect'],
595 (0, None, None)),
596 (['git', 'commit', '-a', '-m', 'bisect config: android'],
597 (0, 'None', None)),
598 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m',
599 'CL for perf tryjob on android'],
600 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)),
601 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b',
602 'android_nexus4_perf_bisect'], (0, None, None)),
603 (['git', 'checkout', 'CURRENT-BRANCH'],
604 (0, '', None)),
605 (['git', 'branch', '-D', 'telemetry-tryjob'],
606 (0, '', None))))
607 cfg_filename = 'tools/run-perf-test.cfg'
608 cfg = StringIO.StringIO()
609 self._stubs.open.files = {cfg_filename: cfg}
610 self.assertEquals(0, command._AttemptTryjob(cfg_filename, []))
611 cfg.seek(0)
612
613 # The config contains both config for browser release & android-chromium,
614 # but that's because the stub testing does not reset the StringIO. In
615 # reality, the cfg_filename should be overwritten with the new data.
616 config = ('''config = {
617 "command": "python tools\\\\perf\\\\run_benchmark --browser=release '''
618 '''--verbose",
619 "max_time_minutes": "120",
620 "repeat_count": "1",
621 "target_arch": "ia32",
622 "truncate_percent": "0"
623 }''''''config = {
624 "command": "./tools/perf/run_benchmark --browser=android-chromium --verbose",
625 "max_time_minutes": "120",
626 "repeat_count": "1",
627 "target_arch": "ia32",
628 "truncate_percent": "0"
629 }''')
630 self.assertEquals(cfg.read(), config)
631
632 570
633 571
634 class IsBenchmarkDisabledOnTrybotPlatformTest(unittest.TestCase): 572 class IsBenchmarkDisabledOnTrybotPlatformTest(unittest.TestCase):
635 573
636 def IsBenchmarkDisabled(self, benchmark_class, trybot_name): 574 def IsBenchmarkDisabled(self, benchmark_class, trybot_name):
637 return trybot_command.Trybot.IsBenchmarkDisabledOnTrybotPlatform( 575 return trybot_command.Trybot.IsBenchmarkDisabledOnTrybotPlatform(
638 benchmark_class, trybot_name)[0] 576 benchmark_class, trybot_name)[0]
639 577
640 def testBenchmarkIsDisabledAll(self): 578 def testBenchmarkIsDisabledAll(self):
641 @benchmark.Disabled('all') 579 @benchmark.Disabled('all')
(...skipping 30 matching lines...) Expand all
672 @benchmark.Enabled('win', 'mac') 610 @benchmark.Enabled('win', 'mac')
673 class FooBenchmark(benchmark.Benchmark): 611 class FooBenchmark(benchmark.Benchmark):
674 pass 612 pass
675 self.assertFalse(self.IsBenchmarkDisabled(FooBenchmark, 'all')) 613 self.assertFalse(self.IsBenchmarkDisabled(FooBenchmark, 'all'))
676 self.assertFalse(self.IsBenchmarkDisabled(FooBenchmark, 'all-mac')) 614 self.assertFalse(self.IsBenchmarkDisabled(FooBenchmark, 'all-mac'))
677 self.assertFalse(self.IsBenchmarkDisabled(FooBenchmark, 'winx64ati')) 615 self.assertFalse(self.IsBenchmarkDisabled(FooBenchmark, 'winx64ati'))
678 616
679 self.assertTrue(self.IsBenchmarkDisabled(FooBenchmark, 'android-s5')) 617 self.assertTrue(self.IsBenchmarkDisabled(FooBenchmark, 'android-s5'))
680 self.assertTrue(self.IsBenchmarkDisabled(FooBenchmark, 'linux')) 618 self.assertTrue(self.IsBenchmarkDisabled(FooBenchmark, 'linux'))
681 self.assertTrue(self.IsBenchmarkDisabled(FooBenchmark, 'all-linux')) 619 self.assertTrue(self.IsBenchmarkDisabled(FooBenchmark, 'all-linux'))
OLDNEW
« no previous file with comments | « tools/perf/core/trybot_command.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698