OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 glob | 5 import glob |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import sys | 8 import sys |
9 | 9 |
10 from pylib import android_commands | |
11 from pylib import cmd_helper | 10 from pylib import cmd_helper |
12 from pylib import constants | 11 from pylib import constants |
13 from pylib import perf_tests_helper | |
14 from pylib.android_commands import errors | |
15 from pylib.base import base_test_result | 12 from pylib.base import base_test_result |
16 from pylib.base import base_test_runner | 13 from pylib.base import base_test_runner |
17 from pylib.utils import run_tests_helper | 14 from pylib.utils import run_tests_helper |
18 | 15 |
19 import test_package_apk | 16 import test_package_apk |
20 import test_package_executable | 17 import test_package_executable |
21 | 18 |
22 sys.path.insert( | 19 sys.path.insert( |
23 0, os.path.join(constants.DIR_SOURCE_ROOT, 'tools', 'swarm_client')) | 20 0, os.path.join(constants.DIR_SOURCE_ROOT, 'tools', 'swarm_client')) |
24 import run_isolated | 21 import run_isolated |
25 | 22 |
26 | 23 |
27 _ISOLATE_FILE_PATHS = { | 24 _ISOLATE_FILE_PATHS = { |
28 'base_unittests': 'base/base_unittests.isolate', | 25 'base_unittests': 'base/base_unittests.isolate', |
frankf
2013/07/08 19:13:43
Let's not touch the style in this file. I have a p
gkanwar
2013/07/08 21:17:07
Done.
| |
29 #'net_unittests': 'net/net_unittests.isolate', | 26 #'net_unittests': 'net/net_unittests.isolate', |
30 #'unit_tests': 'chrome/unit_tests.isolate', | 27 #'unit_tests': 'chrome/unit_tests.isolate', |
31 #'content_browsertests': 'content/content_browsertests.isolate', | 28 #'content_browsertests': 'content/content_browsertests.isolate', |
32 #'content_unittests': 'content/content_unittests.isolate', | 29 #'content_unittests': 'content/content_unittests.isolate', |
33 } | 30 } |
34 _ISOLATE_SCRIPT = os.path.join( | 31 _ISOLATE_SCRIPT = os.path.join( |
35 constants.DIR_SOURCE_ROOT, 'tools', 'swarm_client', 'isolate.py') | 32 constants.DIR_SOURCE_ROOT, 'tools', 'swarm_client', 'isolate.py') |
36 | 33 |
37 | 34 |
38 def _GetDataFilesForTestSuite(product_dir, test_suite_basename): | 35 def _GetDataFilesForTestSuite(product_dir, test_suite_basename): |
39 """Returns a list of data files/dirs needed by the test suite. | 36 """Returns a list of data files/dirs needed by the test suite. |
40 | 37 |
41 Args: | 38 Args: |
42 product_dir: Absolute path to product directory (e.g. /../out/Debug). | 39 product_dir: Absolute path to product directory (e.g. /../out/Debug). |
43 test_suite_basename: The test suite basename (e.g. base_unittests). | 40 test_suite_basename: The test suite basename (e.g. base_unittests). |
44 | 41 |
45 Returns: | 42 Returns: |
46 A list of test file and directory paths. | 43 A list of test file and directory paths. |
47 """ | 44 """ |
48 # TODO(frankf): *.isolated should be generated by gyp using foo_tests_run | 45 # TODO(frankf): *.isolated should be generated by gyp using foo_tests_run |
49 # targets. This is a stop-gap solution as currently there are no such | 46 # targets. This is a stop-gap solution as currently there are no such |
50 # targets for content_unittests and content_browsertests. | 47 # targets for content_unittests and content_browsertests. |
51 isolate_rel_path = _ISOLATE_FILE_PATHS.get(test_suite_basename) | 48 isolate_rel_path = _ISOLATE_FILE_PATHS.get(test_suite_basename) |
52 if isolate_rel_path: | 49 if isolate_rel_path: |
53 isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path) | 50 isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path) |
54 isolated_abs_path = os.path.join( | 51 isolated_abs_path = os.path.join( |
55 product_dir, '%s.isolated' % test_suite_basename) | 52 product_dir, '%s.isolated' % test_suite_basename) |
56 assert os.path.exists(isolate_abs_path) | 53 assert os.path.exists(isolate_abs_path) |
57 isolate_cmd = [ | 54 isolate_cmd = [ |
58 'python', _ISOLATE_SCRIPT, | 55 'python', _ISOLATE_SCRIPT, |
59 'check', | 56 'check', |
60 '--isolate=%s' % isolate_abs_path, | 57 '--isolate=%s' % isolate_abs_path, |
61 '--isolated=%s' % isolated_abs_path, | 58 '--isolated=%s' % isolated_abs_path, |
62 '-V', 'PRODUCT_DIR=%s' % product_dir, | 59 '-V', 'PRODUCT_DIR=%s' % product_dir, |
63 '-V', 'OS=android', | 60 '-V', 'OS=android', |
64 '--outdir=%s' % product_dir, | 61 '--outdir=%s' % product_dir, |
65 ] | 62 ] |
66 assert not cmd_helper.RunCmd(isolate_cmd) | 63 assert not cmd_helper.RunCmd(isolate_cmd) |
67 with open(isolated_abs_path) as f: | 64 with open(isolated_abs_path) as f: |
68 isolated_content = run_isolated.load_isolated(f.read(), | 65 isolated_content = run_isolated.load_isolated(f.read(), |
69 os_flavor='android') | 66 os_flavor='android') |
70 assert isolated_content['os'] == 'android' | 67 assert isolated_content['os'] == 'android' |
71 return isolated_content['files'].keys() | 68 return isolated_content['files'].keys() |
72 | 69 |
73 logging.info('Did not find an isolate file for the test suite.') | 70 logging.info('Did not find an isolate file for the test suite.') |
74 # Ideally, we'd just push all test data. However, it has >100MB, and a lot | 71 # Ideally, we'd just push all test data. However, it has >100MB, and a lot |
75 # of the files are not relevant (some are used for browser_tests, others for | 72 # of the files are not relevant (some are used for browser_tests, others for |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 elif test_suite_basename == 'content_unittests': | 145 elif test_suite_basename == 'content_unittests': |
149 return [ | 146 return [ |
150 'content/test/data/gpu/webgl_conformance_test_expectations.txt', | 147 'content/test/data/gpu/webgl_conformance_test_expectations.txt', |
151 'content/test/data/page_state/', | 148 'content/test/data/page_state/', |
152 'net/data/ssl/certificates/', | 149 'net/data/ssl/certificates/', |
153 'third_party/hyphen/hyph_en_US.dic', | 150 'third_party/hyphen/hyph_en_US.dic', |
154 'webkit/data/dom_storage/webcore_test_database.localstorage', | 151 'webkit/data/dom_storage/webcore_test_database.localstorage', |
155 ] | 152 ] |
156 elif test_suite_basename == 'cc_perftests': | 153 elif test_suite_basename == 'cc_perftests': |
157 return [ | 154 return [ |
158 'cc/test/data', | 155 'cc/test/data', |
159 ] | 156 ] |
160 elif test_suite_basename == 'perf_tests': | 157 elif test_suite_basename == 'perf_tests': |
161 return [ | 158 return [ |
162 'base/test/data', | 159 'base/test/data', |
163 ] | 160 ] |
164 elif test_suite_basename == 'content_browsertests': | 161 elif test_suite_basename == 'content_browsertests': |
165 return [ | 162 return [ |
166 'content/test/data/content-disposition-inline.html', | 163 'content/test/data/content-disposition-inline.html', |
167 'content/test/data/title1.html', | 164 'content/test/data/title1.html', |
168 'content/test/data/post_message2.html', | 165 'content/test/data/post_message2.html', |
169 'content/test/data/content-sniffer-test0.html.mock-http-headers', | 166 'content/test/data/content-sniffer-test0.html.mock-http-headers', |
170 'content/test/data/content-sniffer-test1.html.mock-http-headers', | 167 'content/test/data/content-sniffer-test1.html.mock-http-headers', |
171 'content/test/data/speech', | 168 'content/test/data/speech', |
172 'content/test/data/page404.html.mock-http-headers', | 169 'content/test/data/page404.html.mock-http-headers', |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 """Returns a list of disabled tests. | 332 """Returns a list of disabled tests. |
336 | 333 |
337 Returns: | 334 Returns: |
338 A list of disabled tests obtained from 'filter' subdirectory. | 335 A list of disabled tests obtained from 'filter' subdirectory. |
339 """ | 336 """ |
340 gtest_filter_base_path = os.path.join( | 337 gtest_filter_base_path = os.path.join( |
341 os.path.abspath(os.path.dirname(__file__)), | 338 os.path.abspath(os.path.dirname(__file__)), |
342 'filter', | 339 'filter', |
343 self.test_package.test_suite_basename) | 340 self.test_package.test_suite_basename) |
344 disabled_tests = run_tests_helper.GetExpectations( | 341 disabled_tests = run_tests_helper.GetExpectations( |
345 gtest_filter_base_path + '_disabled') | 342 gtest_filter_base_path + '_disabled') |
346 if self._running_on_emulator: | 343 if self._running_on_emulator: |
347 # Append emulator's filter file. | 344 # Append emulator's filter file. |
348 disabled_tests.extend(run_tests_helper.GetExpectations( | 345 disabled_tests.extend(run_tests_helper.GetExpectations( |
349 gtest_filter_base_path + '_emulator_additional_disabled')) | 346 gtest_filter_base_path + '_emulator_additional_disabled')) |
350 return disabled_tests | 347 return disabled_tests |
351 | 348 |
352 #override | 349 #override |
353 def RunTest(self, test): | 350 def RunTest(self, test): |
354 test_results = base_test_result.TestRunResults() | 351 test_results = base_test_result.TestRunResults() |
355 if not test: | 352 if not test: |
356 return test_results, None | 353 return test_results, None |
357 | 354 |
358 try: | 355 try: |
359 self.test_package.ClearApplicationState() | 356 self.test_package.ClearApplicationState() |
360 self.test_package.CreateTestRunnerScript(test, self._test_arguments) | 357 self.test_package.CreateTestRunnerScript(test, self._test_arguments) |
361 test_results = self.test_package.RunTestsAndListResults() | 358 test_results = self.test_package.RunTestsAndListResults() |
362 except errors.DeviceUnresponsiveError as e: | |
363 # Make sure this device is not attached | |
364 logging.warning(e) | |
365 if android_commands.IsDeviceAttached(self.device): | |
366 raise | |
367 finally: | 359 finally: |
368 self.CleanupSpawningServerState() | 360 self.CleanupSpawningServerState() |
369 # Calculate unknown test results. | 361 # Calculate unknown test results. |
370 all_tests = set(test.split(':')) | 362 all_tests = set(test.split(':')) |
371 all_tests_ran = set([t.GetName() for t in test_results.GetAll()]) | 363 all_tests_ran = set([t.GetName() for t in test_results.GetAll()]) |
372 unknown_tests = all_tests - all_tests_ran | 364 unknown_tests = all_tests - all_tests_ran |
373 test_results.AddResults( | 365 test_results.AddResults( |
374 [base_test_result.BaseTestResult(t, base_test_result.ResultType.UNKNOWN) | 366 [base_test_result.BaseTestResult(t, base_test_result.ResultType.UNKNOWN) |
375 for t in unknown_tests]) | 367 for t in unknown_tests]) |
376 retry = ':'.join([t.GetName() for t in test_results.GetNotPass()]) | 368 retry = ':'.join([t.GetName() for t in test_results.GetNotPass()]) |
377 return test_results, retry | 369 return test_results, retry |
378 | 370 |
379 #override | 371 #override |
380 def SetUp(self): | 372 def SetUp(self): |
381 """Sets up necessary test enviroment for the test suite.""" | 373 """Sets up necessary test enviroment for the test suite.""" |
382 super(TestRunner, self).SetUp() | 374 super(TestRunner, self).SetUp() |
383 if _TestSuiteRequiresMockTestServer(self.test_package.test_suite_basename): | 375 if _TestSuiteRequiresMockTestServer(self.test_package.test_suite_basename): |
384 self.LaunchChromeTestServerSpawner() | 376 self.LaunchChromeTestServerSpawner() |
385 self.tool.SetupEnvironment() | 377 self.tool.SetupEnvironment() |
386 | 378 |
387 #override | 379 #override |
388 def TearDown(self): | 380 def TearDown(self): |
389 """Cleans up the test enviroment for the test suite.""" | 381 """Cleans up the test enviroment for the test suite.""" |
390 self.tool.CleanUpEnvironment() | 382 self.tool.CleanUpEnvironment() |
391 if self._cleanup_test_files: | 383 if self._cleanup_test_files: |
392 self.adb.RemovePushedFiles() | 384 self.adb.RemovePushedFiles() |
393 super(TestRunner, self).TearDown() | 385 super(TestRunner, self).TearDown() |
OLD | NEW |