Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Runs each test cases as a single shard, single process execution. | 6 """Runs each test cases as a single shard, single process execution. |
| 7 | 7 |
| 8 Similar to sharding_supervisor.py but finer grained. Runs multiple instances in | 8 Similar to sharding_supervisor.py but finer grained. Runs multiple instances in |
| 9 parallel. | 9 parallel. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 import fnmatch | 12 import fnmatch |
| 13 import json | 13 import json |
| 14 import logging | 14 import logging |
| 15 import optparse | 15 import optparse |
| 16 import os | 16 import os |
| 17 import Queue | 17 import Queue |
| 18 import subprocess | 18 import subprocess |
| 19 import stat | |
| 19 import sys | 20 import sys |
| 20 import threading | 21 import threading |
| 21 import time | 22 import time |
| 22 | 23 |
| 23 | 24 |
| 24 # These are known to influence the way the output is generated. | 25 # These are known to influence the way the output is generated. |
| 25 KNOWN_GTEST_ENV_VARS = [ | 26 KNOWN_GTEST_ENV_VARS = [ |
| 26 'GTEST_ALSO_RUN_DISABLED_TESTS', | 27 'GTEST_ALSO_RUN_DISABLED_TESTS', |
| 27 'GTEST_BREAK_ON_FAILURE', | 28 'GTEST_BREAK_ON_FAILURE', |
| 28 'GTEST_CATCH_EXCEPTIONS', | 29 'GTEST_CATCH_EXCEPTIONS', |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 49 # TODO(maruel): Handle. | 50 # TODO(maruel): Handle. |
| 50 'GTEST_RANDOM_SEED', | 51 'GTEST_RANDOM_SEED', |
| 51 # TODO(maruel): Handle. | 52 # TODO(maruel): Handle. |
| 52 'GTEST_REPEAT', | 53 'GTEST_REPEAT', |
| 53 'GTEST_SHARD_INDEX', | 54 'GTEST_SHARD_INDEX', |
| 54 # TODO(maruel): Handle. | 55 # TODO(maruel): Handle. |
| 55 'GTEST_SHUFFLE', | 56 'GTEST_SHUFFLE', |
| 56 'GTEST_TOTAL_SHARDS', | 57 'GTEST_TOTAL_SHARDS', |
| 57 ] | 58 ] |
| 58 | 59 |
| 60 CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX' | |
| 61 CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox' | |
| 62 | |
| 63 | |
| 64 def should_enable_sandbox(sandbox_path): | |
| 65 """Return a boolean indicating that the current slave is capable of using the | |
| 66 sandbox and should enable it. This should return True iff the slave is a | |
| 67 Linux host with the sandbox file present and configured correctly.""" | |
| 68 if not (sys.platform.startswith('linux') and | |
| 69 os.path.exists(sandbox_path)): | |
| 70 return False | |
| 71 sandbox_stat = os.stat(sandbox_path) | |
| 72 if ((sandbox_stat.st_mode & stat.S_ISUID) and | |
| 73 (sandbox_stat.st_mode & stat.S_IRUSR) and | |
| 74 (sandbox_stat.st_mode & stat.S_IXUSR) and | |
| 75 (sandbox_stat.st_uid == 0)): | |
| 76 return True | |
| 77 return False | |
| 59 | 78 |
| 60 def num_processors(): | 79 def num_processors(): |
| 61 """Returns the number of processors. | 80 """Returns the number of processors. |
| 62 | 81 |
| 63 Python on OSX 10.6 raises a NotImplementedError exception. | 82 Python on OSX 10.6 raises a NotImplementedError exception. |
| 64 """ | 83 """ |
| 65 try: | 84 try: |
| 66 # Multiprocessing | 85 # Multiprocessing |
| 67 import multiprocessing | 86 import multiprocessing |
| 68 return multiprocessing.cpu_count() | 87 return multiprocessing.cpu_count() |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 self.executable = executable | 573 self.executable = executable |
| 555 self.cwd_dir = cwd_dir | 574 self.cwd_dir = cwd_dir |
| 556 self.timeout = timeout | 575 self.timeout = timeout |
| 557 self.progress = progress | 576 self.progress = progress |
| 558 self.retry_count = retry_count | 577 self.retry_count = retry_count |
| 559 # It is important to remove the shard environment variables since it could | 578 # It is important to remove the shard environment variables since it could |
| 560 # conflict with --gtest_filter. | 579 # conflict with --gtest_filter. |
| 561 self.env = setup_gtest_env() | 580 self.env = setup_gtest_env() |
| 562 self.decider = decider | 581 self.decider = decider |
| 563 | 582 |
| 583 # Setup the chrome sandbox, using the default path if no path is specified. | |
|
M-A Ruel
2012/08/30 18:47:37
This code doesn't belong here, run_test_cases.py i
| |
| 584 if CHROME_SANDBOX_ENV in self.env: | |
| 585 chrome_sandbox_path = self.env[CHROME_SANDBOX_ENV] | |
| 586 else: | |
| 587 chrome_sandbox_path = CHROME_SANDBOX_PATH | |
| 588 | |
| 589 if should_enable_sandbox(chrome_sandbox_path): | |
| 590 print 'Enabling sandbox. Setting environment variable:' | |
| 591 print ' %s="%s"' % (CHROME_SANDBOX_ENV, chrome_sandbox_path) | |
| 592 self.env[CHROME_SANDBOX_ENV] = chrome_sandbox_path | |
| 593 else: | |
| 594 print 'Disabling sandbox. Setting environment variable:' | |
| 595 print ' %s=""' % CHROME_SANDBOX_ENV | |
| 596 self.env[CHROME_SANDBOX_ENV] = '' | |
| 597 | |
| 564 def map(self, test_case): | 598 def map(self, test_case): |
| 565 """Traces a single test case and returns its output.""" | 599 """Traces a single test case and returns its output.""" |
| 566 cmd = [self.executable, '--gtest_filter=%s' % test_case] | 600 cmd = [self.executable, '--gtest_filter=%s' % test_case] |
| 567 cmd = fix_python_path(cmd) | 601 cmd = fix_python_path(cmd) |
| 568 out = [] | 602 out = [] |
| 569 for retry in range(self.retry_count): | 603 for retry in range(self.retry_count): |
| 570 if self.decider.should_stop(): | 604 if self.decider.should_stop(): |
| 571 break | 605 break |
| 572 | 606 |
| 573 start = time.time() | 607 start = time.time() |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 executable, | 899 executable, |
| 866 test_cases, | 900 test_cases, |
| 867 options.jobs, | 901 options.jobs, |
| 868 options.timeout, | 902 options.timeout, |
| 869 options.run_all, | 903 options.run_all, |
| 870 result_file) | 904 result_file) |
| 871 | 905 |
| 872 | 906 |
| 873 if __name__ == '__main__': | 907 if __name__ == '__main__': |
| 874 sys.exit(main(sys.argv[1:])) | 908 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |