OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 json | 5 import json |
6 import os | 6 import os |
7 import tempfile | 7 import tempfile |
8 | 8 |
9 from devil.utils import cmd_helper | 9 from devil.utils import cmd_helper |
10 from pylib import constants | 10 from pylib import constants |
11 from pylib.results import json_results | 11 from pylib.results import json_results |
12 | 12 |
13 class JavaTestRunner(object): | 13 class JavaTestRunner(object): |
14 """Runs java tests on the host.""" | 14 """Runs java tests on the host.""" |
15 | 15 |
16 def __init__(self, args): | 16 def __init__(self, args): |
| 17 self._coverage_dir = args.coverage_dir |
17 self._package_filter = args.package_filter | 18 self._package_filter = args.package_filter |
18 self._runner_filter = args.runner_filter | 19 self._runner_filter = args.runner_filter |
19 self._sdk_version = args.sdk_version | 20 self._sdk_version = args.sdk_version |
20 self._test_filter = args.test_filter | 21 self._test_filter = args.test_filter |
21 self._test_suite = args.test_suite | 22 self._test_suite = args.test_suite |
22 | 23 |
23 def SetUp(self): | 24 def SetUp(self): |
24 pass | 25 pass |
25 | 26 |
26 def RunTest(self, _test): | 27 def RunTest(self, _test): |
27 """Runs junit tests from |self._test_suite|.""" | 28 """Runs junit tests from |self._test_suite|.""" |
28 with tempfile.NamedTemporaryFile() as json_file: | 29 with tempfile.NamedTemporaryFile() as json_file: |
29 java_script = os.path.join( | 30 java_script = os.path.join( |
30 constants.GetOutDirectory(), 'bin', 'helper', self._test_suite) | 31 constants.GetOutDirectory(), 'bin', 'helper', self._test_suite) |
31 command = [java_script, | 32 command = [java_script] |
32 '-test-jars', self._test_suite + '.jar', | 33 |
33 '-json-results-file', json_file.name] | 34 # Add Jar arguments. |
| 35 jar_args = ['-test-jars', self._test_suite + '.jar', |
| 36 '-json-results-file', json_file.name] |
34 if self._test_filter: | 37 if self._test_filter: |
35 command.extend(['-gtest-filter', self._test_filter]) | 38 jar_args.extend(['-gtest-filter', self._test_filter]) |
36 if self._package_filter: | 39 if self._package_filter: |
37 command.extend(['-package-filter', self._package_filter]) | 40 jar_args.extend(['-package-filter', self._package_filter]) |
38 if self._runner_filter: | 41 if self._runner_filter: |
39 command.extend(['-runner-filter', self._runner_filter]) | 42 jar_args.extend(['-runner-filter', self._runner_filter]) |
40 if self._sdk_version: | 43 if self._sdk_version: |
41 command.extend(['-sdk-version', self._sdk_version]) | 44 jar_args.extend(['-sdk-version', self._sdk_version]) |
| 45 command.extend(['--jar-args', '"%s"' % ' '.join(jar_args)]) |
| 46 |
| 47 # Add JVM arguments. |
| 48 jvm_args = [] |
| 49 if self._coverage_dir: |
| 50 jvm_args.append('-Demma.coverage.out.file=%s' % self._coverage_dir) |
| 51 if jvm_args: |
| 52 command.extend(['--jvm-args', '"%s"' % ' '.join(jvm_args)]) |
| 53 |
42 return_code = cmd_helper.RunCmd(command) | 54 return_code = cmd_helper.RunCmd(command) |
43 results_list = json_results.ParseResultsFromJson( | 55 results_list = json_results.ParseResultsFromJson( |
44 json.loads(json_file.read())) | 56 json.loads(json_file.read())) |
45 return (results_list, return_code) | 57 return (results_list, return_code) |
46 | 58 |
47 def TearDown(self): | 59 def TearDown(self): |
48 pass | 60 pass |
49 | 61 |
OLD | NEW |