| OLD | NEW |
| 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 logging | 5 import logging |
| 6 import json | 6 import json |
| 7 import StringIO | 7 import StringIO |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 import mock | 10 import mock |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 command = trybot_command.Trybot() | 314 command = trybot_command.Trybot() |
| 315 options = argparse.Namespace(trybot='android-nexus4', benchmark_name='foo') | 315 options = argparse.Namespace(trybot='android-nexus4', benchmark_name='foo') |
| 316 command.Run(options, []) | 316 command.Run(options, []) |
| 317 self.assertEquals( | 317 self.assertEquals( |
| 318 ('Error creating branch telemetry-tryjob. ' | 318 ('Error creating branch telemetry-tryjob. ' |
| 319 'Please delete it if it exists.\n' | 319 'Please delete it if it exists.\n' |
| 320 'fatal: A branch named \'telemetry-try\' already exists.\n'), | 320 'fatal: A branch named \'telemetry-try\' already exists.\n'), |
| 321 self.log_output.getvalue()) | 321 self.log_output.getvalue()) |
| 322 | 322 |
| 323 def _GetConfigForTrybot(self, name, platform, branch, cfg_filename, | 323 def _GetConfigForTrybot(self, name, platform, branch, cfg_filename, |
| 324 is_blink=False): | 324 is_blink=False, extra_benchmark_args=None): |
| 325 bot = '%s_perf_bisect' % name.replace('', '').replace('-', '_') | 325 bot = '%s_perf_bisect' % name.replace('', '').replace('-', '_') |
| 326 self._MockTryserverJson({bot: 'stuff'}) | 326 self._MockTryserverJson({bot: 'stuff'}) |
| 327 first_processes = () | 327 first_processes = () |
| 328 if is_blink: | 328 if is_blink: |
| 329 first_processes = ( | 329 first_processes = ( |
| 330 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'], (0, 'br', None)), | 330 (['git', 'rev-parse', '--abbrev-ref', 'HEAD'], (0, 'br', None)), |
| 331 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)), | 331 (['git', 'update-index', '--refresh', '-q'], (0, None, None,)), |
| 332 (['git', 'diff-index', 'HEAD'], (0, '', None)), | 332 (['git', 'diff-index', 'HEAD'], (0, '', None)), |
| 333 (['git', 'log', 'origin/master..HEAD'], (0, '', None)) | 333 (['git', 'log', 'origin/master..HEAD'], (0, '', None)) |
| 334 ) | 334 ) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 348 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', bot], | 348 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', bot], |
| 349 (0, None, None)), | 349 (0, None, None)), |
| 350 (['git', 'checkout', branch], (0, None, None)), | 350 (['git', 'checkout', branch], (0, None, None)), |
| 351 (['git', 'branch', '-D', 'telemetry-tryjob'], (0, None, None)) | 351 (['git', 'branch', '-D', 'telemetry-tryjob'], (0, None, None)) |
| 352 )) | 352 )) |
| 353 cfg = StringIO.StringIO() | 353 cfg = StringIO.StringIO() |
| 354 self._stubs.open.files = {cfg_filename: cfg} | 354 self._stubs.open.files = {cfg_filename: cfg} |
| 355 | 355 |
| 356 options = argparse.Namespace(trybot=name, benchmark_name='sunspider') | 356 options = argparse.Namespace(trybot=name, benchmark_name='sunspider') |
| 357 command = trybot_command.Trybot() | 357 command = trybot_command.Trybot() |
| 358 command.Run(options, []) | 358 extra_benchmark_args = extra_benchmark_args or [] |
| 359 command.Run(options, extra_benchmark_args) |
| 359 return cfg.getvalue() | 360 return cfg.getvalue() |
| 360 | 361 |
| 361 def testConfigAndroid(self): | 362 def testConfigAndroid(self): |
| 362 config = self._GetConfigForTrybot( | 363 config = self._GetConfigForTrybot( |
| 363 'android-nexus4', 'android', 'somebranch', | 364 'android-nexus4', 'android', 'somebranch', |
| 364 'tools/run-perf-test.cfg') | 365 'tools/run-perf-test.cfg') |
| 365 self.assertEquals( | 366 self.assertEquals( |
| 366 ('config = {\n' | 367 ('config = {\n' |
| 367 ' "command": "./tools/perf/run_benchmark ' | 368 ' "command": "./tools/perf/run_benchmark ' |
| 368 '--browser=android-chromium sunspider",\n' | 369 '--browser=android-chromium sunspider --verbose",\n' |
| 369 ' "max_time_minutes": "120",\n' | 370 ' "max_time_minutes": "120",\n' |
| 370 ' "repeat_count": "1",\n' | 371 ' "repeat_count": "1",\n' |
| 371 ' "target_arch": "ia32",\n' | 372 ' "target_arch": "ia32",\n' |
| 372 ' "truncate_percent": "0"\n' | 373 ' "truncate_percent": "0"\n' |
| 373 '}'), config) | 374 '}'), config) |
| 374 | 375 |
| 375 def testConfigMac(self): | 376 def testConfigMac(self): |
| 376 config = self._GetConfigForTrybot( | 377 config = self._GetConfigForTrybot( |
| 377 'mac-10-9', 'mac', 'currentwork', 'tools/run-perf-test.cfg') | 378 'mac-10-9', 'mac', 'currentwork', 'tools/run-perf-test.cfg') |
| 378 self.assertEquals( | 379 self.assertEquals( |
| 379 ('config = {\n' | 380 ('config = {\n' |
| 380 ' "command": "./tools/perf/run_benchmark ' | 381 ' "command": "./tools/perf/run_benchmark ' |
| 381 '--browser=release sunspider",\n' | 382 '--browser=release sunspider --verbose",\n' |
| 382 ' "max_time_minutes": "120",\n' | 383 ' "max_time_minutes": "120",\n' |
| 383 ' "repeat_count": "1",\n' | 384 ' "repeat_count": "1",\n' |
| 384 ' "target_arch": "ia32",\n' | 385 ' "target_arch": "ia32",\n' |
| 385 ' "truncate_percent": "0"\n' | 386 ' "truncate_percent": "0"\n' |
| 386 '}'), config) | 387 '}'), config) |
| 387 | 388 |
| 388 def testConfigWinX64(self): | 389 def testConfigWinX64(self): |
| 389 config = self._GetConfigForTrybot( | 390 config = self._GetConfigForTrybot( |
| 390 'win-x64', 'win-x64', 'currentwork', 'tools/run-perf-test.cfg') | 391 'win-x64', 'win-x64', 'currentwork', 'tools/run-perf-test.cfg') |
| 391 self.assertEquals( | 392 self.assertEquals( |
| 392 ('config = {\n' | 393 ('config = {\n' |
| 393 ' "command": "python tools\\\\perf\\\\run_benchmark ' | 394 ' "command": "python tools\\\\perf\\\\run_benchmark ' |
| 394 '--browser=release_x64 sunspider",\n' | 395 '--browser=release_x64 sunspider --verbose",\n' |
| 395 ' "max_time_minutes": "120",\n' | 396 ' "max_time_minutes": "120",\n' |
| 396 ' "repeat_count": "1",\n' | 397 ' "repeat_count": "1",\n' |
| 397 ' "target_arch": "x64",\n' | 398 ' "target_arch": "x64",\n' |
| 399 ' "truncate_percent": "0"\n' |
| 400 '}'), config) |
| 401 |
| 402 def testVerboseOptionIsNotAddedTwice(self): |
| 403 config = self._GetConfigForTrybot( |
| 404 'win-x64', 'win-x64', 'currentwork', 'tools/run-perf-test.cfg', |
| 405 extra_benchmark_args=['-v']) |
| 406 self.assertEquals( |
| 407 ('config = {\n' |
| 408 ' "command": "python tools\\\\perf\\\\run_benchmark ' |
| 409 '--browser=release_x64 sunspider -v",\n' |
| 410 ' "max_time_minutes": "120",\n' |
| 411 ' "repeat_count": "1",\n' |
| 412 ' "target_arch": "x64",\n' |
| 398 ' "truncate_percent": "0"\n' | 413 ' "truncate_percent": "0"\n' |
| 399 '}'), config) | 414 '}'), config) |
| 400 | 415 |
| 401 def testConfigWinX64WithNoHyphen(self): | 416 def testConfigWinX64WithNoHyphen(self): |
| 402 config = self._GetConfigForTrybot( | 417 config = self._GetConfigForTrybot( |
| 403 'winx64nvidia', 'win-x64', 'currentwork', 'tools/run-perf-test.cfg') | 418 'winx64nvidia', 'win-x64', 'currentwork', 'tools/run-perf-test.cfg') |
| 404 self.assertEquals( | 419 self.assertEquals( |
| 405 ('config = {\n' | 420 ('config = {\n' |
| 406 ' "command": "python tools\\\\perf\\\\run_benchmark ' | 421 ' "command": "python tools\\\\perf\\\\run_benchmark ' |
| 407 '--browser=release_x64 sunspider",\n' | 422 '--browser=release_x64 sunspider --verbose",\n' |
| 408 ' "max_time_minutes": "120",\n' | 423 ' "max_time_minutes": "120",\n' |
| 409 ' "repeat_count": "1",\n' | 424 ' "repeat_count": "1",\n' |
| 410 ' "target_arch": "x64",\n' | 425 ' "target_arch": "x64",\n' |
| 411 ' "truncate_percent": "0"\n' | 426 ' "truncate_percent": "0"\n' |
| 412 '}'), config) | 427 '}'), config) |
| 413 | 428 |
| 414 def testUnsupportedTrybot(self): | 429 def testUnsupportedTrybot(self): |
| 415 self.assertRaises( | 430 self.assertRaises( |
| 416 trybot_command.TrybotError, | 431 trybot_command.TrybotError, |
| 417 trybot_command._GetBuilderNames, | 432 trybot_command._GetBuilderNames, |
| 418 'arms-nvidia', | 433 'arms-nvidia', |
| 419 {'win_perf_bisect': 'stuff'} | 434 {'win_perf_bisect': 'stuff'} |
| 420 ) | 435 ) |
| 421 | 436 |
| 422 def testConfigBlink(self): | 437 def testConfigBlink(self): |
| 423 config = self._GetConfigForTrybot( | 438 config = self._GetConfigForTrybot( |
| 424 'mac-10-9', 'mac', 'blinkbranch', | 439 'mac-10-9', 'mac', 'blinkbranch', |
| 425 'Tools/run-perf-test.cfg', True) | 440 'Tools/run-perf-test.cfg', True) |
| 426 self.assertEquals( | 441 self.assertEquals( |
| 427 ('config = {\n' | 442 ('config = {\n' |
| 428 ' "command": "./tools/perf/run_benchmark ' | 443 ' "command": "./tools/perf/run_benchmark ' |
| 429 '--browser=release sunspider",\n' | 444 '--browser=release sunspider --verbose",\n' |
| 430 ' "max_time_minutes": "120",\n' | 445 ' "max_time_minutes": "120",\n' |
| 431 ' "repeat_count": "1",\n' | 446 ' "repeat_count": "1",\n' |
| 432 ' "target_arch": "ia32",\n' | 447 ' "target_arch": "ia32",\n' |
| 433 ' "truncate_percent": "0"\n' | 448 ' "truncate_percent": "0"\n' |
| 434 '}'), config) | 449 '}'), config) |
| 435 | 450 |
| 436 def testUpdateConfigGitCommitTrybotError(self): | 451 def testUpdateConfigGitCommitTrybotError(self): |
| 437 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) | 452 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) |
| 438 command = trybot_command.Trybot() | 453 command = trybot_command.Trybot() |
| 439 command._InitializeBuilderNames('android-nexus4') | 454 command._InitializeBuilderNames('android-nexus4') |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 self.assertRaises( | 504 self.assertRaises( |
| 490 trybot_command.TrybotError, command._UpdateConfigAndRunTryjob, | 505 trybot_command.TrybotError, command._UpdateConfigAndRunTryjob, |
| 491 'android', cfg_filename, []) | 506 'android', cfg_filename, []) |
| 492 | 507 |
| 493 def testUpdateConfigSkipTryjob(self): | 508 def testUpdateConfigSkipTryjob(self): |
| 494 self._MockTryserverJson({'win_perf_bisect': 'stuff'}) | 509 self._MockTryserverJson({'win_perf_bisect': 'stuff'}) |
| 495 command = trybot_command.Trybot() | 510 command = trybot_command.Trybot() |
| 496 command._InitializeBuilderNames('win-x64') | 511 command._InitializeBuilderNames('win-x64') |
| 497 self._ExpectProcesses(()) | 512 self._ExpectProcesses(()) |
| 498 cfg_filename = 'tools/run-perf-test.cfg' | 513 cfg_filename = 'tools/run-perf-test.cfg' |
| 499 cfg_data = '''config = { | 514 cfg_data = ('''config = { |
| 500 "command": "python tools\\\\perf\\\\run_benchmark --browser=release_x64", | 515 "command": "python tools\\\\perf\\\\run_benchmark --browser=release_x64''' |
| 516 ''' --verbose", |
| 501 "max_time_minutes": "120", | 517 "max_time_minutes": "120", |
| 502 "repeat_count": "1", | 518 "repeat_count": "1", |
| 503 "target_arch": "x64", | 519 "target_arch": "x64", |
| 504 "truncate_percent": "0" | 520 "truncate_percent": "0" |
| 505 }''' | 521 }''') |
| 506 self._stubs.open.files = {cfg_filename: cfg_data} | 522 self._stubs.open.files = {cfg_filename: cfg_data} |
| 507 self.assertEquals((trybot_command.NO_CHANGES, ''), | 523 self.assertEquals((trybot_command.NO_CHANGES, ''), |
| 508 command._UpdateConfigAndRunTryjob( | 524 command._UpdateConfigAndRunTryjob( |
| 509 'win-x64', cfg_filename, [])) | 525 'win-x64', cfg_filename, [])) |
| 510 | 526 |
| 511 def testUpdateConfigGitTry(self): | 527 def testUpdateConfigGitTry(self): |
| 512 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) | 528 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) |
| 513 command = trybot_command.Trybot() | 529 command = trybot_command.Trybot() |
| 514 command._InitializeBuilderNames('android-nexus4') | 530 command._InitializeBuilderNames('android-nexus4') |
| 515 self._ExpectProcesses(( | 531 self._ExpectProcesses(( |
| 516 (['git', 'commit', '-a', '-m', 'bisect config: android'], | 532 (['git', 'commit', '-a', '-m', 'bisect config: android'], |
| 517 (0, 'None', None)), | 533 (0, 'None', None)), |
| 518 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m', | 534 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m', |
| 519 'CL for perf tryjob on android'], | 535 'CL for perf tryjob on android'], |
| 520 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)), | 536 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)), |
| 521 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', | 537 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', |
| 522 'android_nexus4_perf_bisect'], (0, None, None)))) | 538 'android_nexus4_perf_bisect'], (0, None, None)))) |
| 523 cfg_filename = 'tools/run-perf-test.cfg' | 539 cfg_filename = 'tools/run-perf-test.cfg' |
| 524 cfg = StringIO.StringIO() | 540 cfg = StringIO.StringIO() |
| 525 self._stubs.open.files = {cfg_filename: cfg} | 541 self._stubs.open.files = {cfg_filename: cfg} |
| 526 self.assertEquals((0, 'https://codereview.chromium.org/12345'), | 542 self.assertEquals((0, 'https://codereview.chromium.org/12345'), |
| 527 command._UpdateConfigAndRunTryjob( | 543 command._UpdateConfigAndRunTryjob( |
| 528 'android', cfg_filename, [])) | 544 'android', cfg_filename, [])) |
| 529 cfg.seek(0) | 545 cfg.seek(0) |
| 530 config = '''config = { | 546 config = '''config = { |
| 531 "command": "./tools/perf/run_benchmark --browser=android-chromium", | 547 "command": "./tools/perf/run_benchmark --browser=android-chromium --verbose", |
| 532 "max_time_minutes": "120", | 548 "max_time_minutes": "120", |
| 533 "repeat_count": "1", | 549 "repeat_count": "1", |
| 534 "target_arch": "ia32", | 550 "target_arch": "ia32", |
| 535 "truncate_percent": "0" | 551 "truncate_percent": "0" |
| 536 }''' | 552 }''' |
| 537 self.assertEquals(cfg.read(), config) | 553 self.assertEquals(cfg.read(), config) |
| 538 | 554 |
| 539 def testUpdateConfigGitTryAll(self): | 555 def testUpdateConfigGitTryAll(self): |
| 540 self._MockTryserverJson({ | 556 self._MockTryserverJson({ |
| 541 'android_nexus4_perf_bisect': 'stuff', | 557 'android_nexus4_perf_bisect': 'stuff', |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 cfg_filename = 'tools/run-perf-test.cfg' | 594 cfg_filename = 'tools/run-perf-test.cfg' |
| 579 cfg = StringIO.StringIO() | 595 cfg = StringIO.StringIO() |
| 580 self._stubs.open.files = {cfg_filename: cfg} | 596 self._stubs.open.files = {cfg_filename: cfg} |
| 581 self.assertEquals(0, command._AttemptTryjob(cfg_filename, [])) | 597 self.assertEquals(0, command._AttemptTryjob(cfg_filename, [])) |
| 582 cfg.seek(0) | 598 cfg.seek(0) |
| 583 | 599 |
| 584 # The config contains both config for browser release & android-chromium, | 600 # The config contains both config for browser release & android-chromium, |
| 585 # but that's because the stub testing does not reset the StringIO. In | 601 # but that's because the stub testing does not reset the StringIO. In |
| 586 # reality, the cfg_filename should be overwritten with the new data. | 602 # reality, the cfg_filename should be overwritten with the new data. |
| 587 config = ('''config = { | 603 config = ('''config = { |
| 588 "command": "python tools\\\\perf\\\\run_benchmark --browser=release", | 604 "command": "python tools\\\\perf\\\\run_benchmark --browser=release ''' |
| 605 '''--verbose", |
| 589 "max_time_minutes": "120", | 606 "max_time_minutes": "120", |
| 590 "repeat_count": "1", | 607 "repeat_count": "1", |
| 591 "target_arch": "ia32", | 608 "target_arch": "ia32", |
| 592 "truncate_percent": "0" | 609 "truncate_percent": "0" |
| 593 }''''''config = { | 610 }''''''config = { |
| 594 "command": "./tools/perf/run_benchmark --browser=android-chromium", | 611 "command": "./tools/perf/run_benchmark --browser=android-chromium --verbose", |
| 595 "max_time_minutes": "120", | 612 "max_time_minutes": "120", |
| 596 "repeat_count": "1", | 613 "repeat_count": "1", |
| 597 "target_arch": "ia32", | 614 "target_arch": "ia32", |
| 598 "truncate_percent": "0" | 615 "truncate_percent": "0" |
| 599 }''') | 616 }''') |
| 600 self.assertEquals(cfg.read(), config) | 617 self.assertEquals(cfg.read(), config) |
| OLD | NEW |