From 4843ac7296f17725e4d58172f7d15a9eebeed68a Mon Sep 17 00:00:00 2001 From: John Budorick Date: Fri, 15 Sep 2017 21:23:28 +0000 Subject: [PATCH] [android] Handle non-existent gtest XML result file. Bug: 765673 Change-Id: Icb0dcc89e2898f7a03c6558aa4ff07eef9508ac6 Reviewed-on: https://chromium-review.googlesource.com/668796 Reviewed-by: Benjamin Pastene Commit-Queue: John Budorick Cr-Original-Commit-Position: refs/heads/master@{#502382} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 79cd156c0988e6bf20bf81e84912265ef467068b --- android/pylib/gtest/gtest_test_instance.py | 3 ++- android/pylib/gtest/gtest_test_instance_test.py | 4 ++++ .../pylib/local/device/local_device_gtest_run.py | 13 ++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/android/pylib/gtest/gtest_test_instance.py b/android/pylib/gtest/gtest_test_instance.py index 3b4d0ec04..9baa33804 100644 --- a/android/pylib/gtest/gtest_test_instance.py +++ b/android/pylib/gtest/gtest_test_instance.py @@ -207,10 +207,11 @@ def ParseGTestOutput(output, symbolizer, device_abi): def ParseGTestXML(xml_content): """Parse gtest XML result.""" results = [] + if not xml_content: + return results html = HTMLParser.HTMLParser() - # TODO(jbudorick): Unclear how this handles crashes. testsuites = xml.etree.ElementTree.fromstring(xml_content) for testsuite in testsuites: suite_name = testsuite.attrib['name'] diff --git a/android/pylib/gtest/gtest_test_instance_test.py b/android/pylib/gtest/gtest_test_instance_test.py index 95f9b0099..3466924a0 100755 --- a/android/pylib/gtest/gtest_test_instance_test.py +++ b/android/pylib/gtest/gtest_test_instance_test.py @@ -177,6 +177,10 @@ class GtestTestInstanceTests(unittest.TestCase): self.assertEquals(1, actual[0].GetDuration()) self.assertEquals(base_test_result.ResultType.PASS, actual[0].GetType()) + def testParseGTestXML_none(self): + actual = gtest_test_instance.ParseGTestXML(None) + self.assertEquals([], actual) + def testConvertTestFilterFile_commentsAndBlankLines(self): input_lines = [ 'positive1', diff --git a/android/pylib/local/device/local_device_gtest_run.py b/android/pylib/local/device/local_device_gtest_run.py index 5e701754d..3268f0ade 100644 --- a/android/pylib/local/device/local_device_gtest_run.py +++ b/android/pylib/local/device/local_device_gtest_run.py @@ -421,9 +421,16 @@ class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): timeout=timeout, retries=0) if self._test_instance.enable_xml_result_parsing: - gtest_xml = device.ReadFile( - device_tmp_results_file.name, - as_root=True) + try: + gtest_xml = device.ReadFile( + device_tmp_results_file.name, + as_root=True) + except device_errors.CommandFailedError as e: + logging.warning( + 'Failed to pull gtest results XML file %s: %s', + device_tmp_results_file.name, + str(e)) + gtest_xml = None for s in self._servers[str(device)]: s.Reset()