| Index: build/android/pylib/junit/test_runner.py
|
| diff --git a/build/android/pylib/junit/test_runner.py b/build/android/pylib/junit/test_runner.py
|
| index 35ac666fae887bc82c257893872a730cf5567b2c..eda5d93cf2ff37dbdcbefcd26c282169ef6192dd 100644
|
| --- a/build/android/pylib/junit/test_runner.py
|
| +++ b/build/android/pylib/junit/test_runner.py
|
| @@ -2,10 +2,13 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| +import json
|
| import os
|
| +import tempfile
|
|
|
| from pylib import cmd_helper
|
| from pylib import constants
|
| +from pylib.base import base_test_result
|
|
|
| class JavaTestRunner(object):
|
| """Runs java tests on the host."""
|
| @@ -20,20 +23,43 @@ class JavaTestRunner(object):
|
| def SetUp(self):
|
| pass
|
|
|
| + def _ParseResultsFromJson(self, json_results):
|
| + results_list = []
|
| + testsuite_runs = json_results['per_iteration_data']
|
| + for testsuite_run in testsuite_runs:
|
| + for test in testsuite_run:
|
| + test_runs = testsuite_run[test]
|
| + for test_run in test_runs:
|
| + name = test
|
| + if test_run['status'] == 'SUCCESS':
|
| + test_type = base_test_result.ResultType.PASS
|
| + elif test_run['status'] == 'FAILURE':
|
| + test_type = base_test_result.ResultType.FAIL
|
| + else:
|
| + test_type = base_test_result.ResultType.UNKNOWN
|
| + duration_ms = test_run['elapsed_time_ms']
|
| + results_list.append(base_test_result.BaseTestResult(
|
| + name, test_type, duration=duration_ms))
|
| + return results_list
|
| +
|
| def RunTest(self, _test):
|
| """Runs junit tests from |self._test_suite|."""
|
| - command = ['java',
|
| - '-jar', os.path.join(constants.GetOutDirectory(), 'lib.java',
|
| - '%s.jar' % self._test_suite)]
|
| - if self._test_filter:
|
| - command.extend(['-gtest-filter', self._test_filter])
|
| - if self._package_filter:
|
| - command.extend(['-package-filter', self._package_filter])
|
| - if self._runner_filter:
|
| - command.extend(['-runner-filter', self._runner_filter])
|
| - if self._sdk_version:
|
| - command.extend(['-sdk-version', self._sdk_version])
|
| - return cmd_helper.RunCmd(command)
|
| + with tempfile.NamedTemporaryFile() as json_file:
|
| + command = ['java',
|
| + '-jar', os.path.join(constants.GetOutDirectory(), 'lib.java',
|
| + '%s.jar' % self._test_suite), '-json-results-file',
|
| + json_file.name]
|
| + if self._test_filter:
|
| + command.extend(['-gtest-filter', self._test_filter])
|
| + if self._package_filter:
|
| + command.extend(['-package-filter', self._package_filter])
|
| + if self._runner_filter:
|
| + command.extend(['-runner-filter', self._runner_filter])
|
| + if self._sdk_version:
|
| + command.extend(['-sdk-version', self._sdk_version])
|
| + return_code = cmd_helper.RunCmd(command)
|
| + results_list = self._ParseResultsFromJson(json.loads(json_file.read()))
|
| + return (results_list, return_code)
|
|
|
| def TearDown(self):
|
| pass
|
|
|