Skip to content

Commit

Permalink
[android] Use ReadFile w/ root permissions for gtest xml file handling.
Browse files Browse the repository at this point in the history
BUG=646677

Review-Url: https://codereview.chromium.org/2453993002
Cr-Commit-Position: refs/heads/master@{#427911}
  • Loading branch information
jbudorick authored and Commit bot committed Oct 27, 2016
1 parent cc8baf7 commit 4d5bf29
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions build/android/pylib/local/device/local_device_gtest_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import logging
import os
import posixpath
import tempfile

from devil.android import device_errors
from devil.android import device_temp_file
Expand Down Expand Up @@ -348,40 +347,38 @@ def _RunTest(self, device, test):
# Run the test.
timeout = (self._test_instance.shard_timeout
* self.GetTool(device).GetTimeoutScale())
with tempfile.NamedTemporaryFile(suffix='.xml') as host_tmp_results_file:
with device_temp_file.DeviceTempFile(
adb=device.adb,
dir=self._delegate.ResultsDirectory(device),
suffix='.xml') as device_tmp_results_file:

flags = self._test_instance.test_arguments or ''
if self._test_instance.enable_xml_result_parsing:
flags += ' --gtest_output=xml:%s' % device_tmp_results_file.name

output = self._delegate.Run(
test, device, flags=flags,
timeout=timeout, retries=0)

if self._test_instance.enable_xml_result_parsing:
device.PullFile(
device_tmp_results_file.name,
host_tmp_results_file.name)

for s in self._servers[str(device)]:
s.Reset()
if self._test_instance.app_files:
self._delegate.PullAppFiles(device, self._test_instance.app_files,
self._test_instance.app_file_dir)
if not self._env.skip_clear_data:
self._delegate.Clear(device)

# Parse the output.
# TODO(jbudorick): Transition test scripts away from parsing stdout.
with device_temp_file.DeviceTempFile(
adb=device.adb,
dir=self._delegate.ResultsDirectory(device),
suffix='.xml') as device_tmp_results_file:

flags = self._test_instance.test_arguments or ''
if self._test_instance.enable_xml_result_parsing:
with open(host_tmp_results_file.name) as xml_results_file:
results = gtest_test_instance.ParseGTestXML(xml_results_file.read())
else:
results = gtest_test_instance.ParseGTestOutput(output)
flags += ' --gtest_output=xml:%s' % device_tmp_results_file.name

output = self._delegate.Run(
test, device, flags=flags,
timeout=timeout, retries=0)

if self._test_instance.enable_xml_result_parsing:
gtest_xml = device.ReadFile(
device_tmp_results_file.name,
as_root=True)

for s in self._servers[str(device)]:
s.Reset()
if self._test_instance.app_files:
self._delegate.PullAppFiles(device, self._test_instance.app_files,
self._test_instance.app_file_dir)
if not self._env.skip_clear_data:
self._delegate.Clear(device)

# Parse the output.
# TODO(jbudorick): Transition test scripts away from parsing stdout.
if self._test_instance.enable_xml_result_parsing:
results = gtest_test_instance.ParseGTestXML(gtest_xml)
else:
results = gtest_test_instance.ParseGTestOutput(output)

# Check whether there are any crashed testcases.
self._crashes.update(r.GetName() for r in results
Expand Down

0 comments on commit 4d5bf29

Please sign in to comment.