Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import json | |
| 6 import os | |
| 7 import tempfile | |
| 8 | |
| 9 from devil.utils import cmd_helper | |
| 10 from pylib import constants | |
| 11 from pylib.base import base_test_result | |
| 12 from pylib.base import test_run | |
| 13 from pylib.results import json_results | |
| 14 | |
| 15 | |
| 16 class LocalMachineJunitTestRun( | |
| 17 test_run.TestRun): | |
|
jbudorick
2016/11/11 22:29:38
nit: this shouldn't be on its own line.
mikecase (-- gone --)
2016/11/11 22:51:35
Done
| |
| 18 def __init__(self, env, test_instance): | |
| 19 super(LocalMachineJunitTestRun, self).__init__(env, test_instance) | |
| 20 | |
| 21 #override | |
| 22 def TestPackage(self): | |
| 23 return self._test_instance.suite | |
| 24 | |
| 25 #override | |
| 26 def SetUp(self): | |
| 27 pass | |
| 28 | |
| 29 #override | |
| 30 def RunTests(self): | |
| 31 with tempfile.NamedTemporaryFile() as json_file: | |
| 32 java_script = os.path.join( | |
| 33 constants.GetOutDirectory(), 'bin', 'helper', | |
| 34 self._test_instance.suite) | |
| 35 command = [java_script] | |
| 36 | |
| 37 # Add Jar arguments. | |
| 38 jar_args = ['-test-jars', self._test_instance.suite + '.jar', | |
| 39 '-json-results-file', json_file.name] | |
| 40 if self._test_instance.test_filter: | |
| 41 jar_args.extend(['-gtest-filter', self._test_instance.test_filter]) | |
| 42 if self._test_instance.package_filter: | |
| 43 jar_args.extend(['-package-filter', | |
| 44 self._test_instance.package_filter]) | |
| 45 if self._test_instance.runner_filter: | |
| 46 jar_args.extend(['-runner-filter', self._test_instance.runner_filter]) | |
| 47 command.extend(['--jar-args', '"%s"' % ' '.join(jar_args)]) | |
| 48 | |
| 49 # Add JVM arguments. | |
| 50 jvm_args = [] | |
| 51 # TODO(mikecase): Add a --robolectric-dep-dir arg to test runner. | |
| 52 # Have this arg set by GN in the generated test runner scripts. | |
| 53 jvm_args += [ | |
| 54 '-Drobolectric.dependency.dir=%s' % | |
| 55 os.path.join(constants.GetOutDirectory(), | |
| 56 'lib.java', 'third_party', 'robolectric')] | |
| 57 if self._test_instance.coverage_dir: | |
| 58 if not os.path.exists(self._test_instance.coverage_dir): | |
| 59 os.makedirs(self._test_instance.coverage_dir) | |
| 60 elif not os.path.isdir(self._test_instance.coverage_dir): | |
| 61 raise Exception('--coverage-dir takes a directory, not file path.') | |
| 62 jvm_args.append('-Demma.coverage.out.file=%s' % os.path.join( | |
| 63 self._test_instance.coverage_dir, | |
| 64 '%s.ec' % self._test_instance.suite)) | |
| 65 if jvm_args: | |
| 66 command.extend(['--jvm-args', '"%s"' % ' '.join(jvm_args)]) | |
| 67 | |
| 68 cmd_helper.RunCmd(command) | |
| 69 results_list = json_results.ParseResultsFromJson( | |
| 70 json.loads(json_file.read())) | |
| 71 | |
| 72 test_run_results = base_test_result.TestRunResults() | |
| 73 test_run_results.AddResults(results_list) | |
| 74 | |
| 75 return [test_run_results] | |
| 76 | |
| 77 #override | |
| 78 def TearDown(self): | |
| 79 pass | |
| OLD | NEW |