Commit dc56228a authored by Zhaoyang Li's avatar Zhaoyang Li Committed by Commit Bot

[iOS][test runner] Add shard info to test result json.

This is useful for developers to locate a shard from a test name, when
there are multiple shards for a suite.

Bug: 1047704
Change-Id: Ie107d145036e85ca60fe44305fc33ddb17d30ef1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495792Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Commit-Queue: Zhaoyang Li <zhaoyangli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821346}
parent 4b2a80b1
......@@ -4,6 +4,7 @@
import logging
from collections import OrderedDict
import os
import result_sink_util
......@@ -20,6 +21,7 @@ class StdJson():
self.tests = OrderedDict()
self.result_sink = result_sink_util.ResultSinkClient()
self._shard_index = os.getenv('GTEST_SHARD_INDEX', 0)
if 'passed' in kwargs:
self.mark_all_passed(kwargs['passed'])
......@@ -28,6 +30,18 @@ class StdJson():
if 'flaked' in kwargs:
self.mark_all_passed(kwargs['flaked'], flaky=True)
def _init_test(self, expected, actual, is_unexpected=False):
"""Returns a dict of test result info used as values in self.tests dict."""
test = {
'expected': expected,
'actual': actual,
'shard': self._shard_index,
}
if is_unexpected:
test['is_unexpected'] = True
return test
def mark_passed(self, test, flaky=False):
"""Sets test as passed
......@@ -48,7 +62,7 @@ class StdJson():
if test in self.tests:
self.tests[test]['actual'] = self.tests[test]['actual'] + " PASS"
else:
self.tests[test] = {'expected': 'PASS', 'actual': 'PASS'}
self.tests[test] = self._init_test('PASS', 'PASS')
if flaky or 'FAIL' in self.tests[test]['actual']:
self.tests[test]['is_flaky'] = True
......@@ -79,11 +93,7 @@ class StdJson():
self.tests[test]['actual'] = self.tests[test]['actual'] + " FAIL"
self.tests[test]['is_unexpected'] = True
else:
self.tests[test] = {
'expected': 'PASS',
'actual': 'FAIL',
'is_unexpected': True
}
self.tests[test] = self._init_test('PASS', 'FAIL', True)
def mark_all_failed(self, tests):
"""Marks all tests as FAIL"""
......@@ -104,7 +114,7 @@ class StdJson():
test, 'SKIP', True, tags=[('disabled_test', 'true')])
self.result_sink.post(result_sink_test_result)
self.tests[test] = {'expected': 'SKIP', 'actual': 'SKIP'}
self.tests[test] = self._init_test('SKIP', 'SKIP')
def mark_all_skipped(self, tests):
for test in tests:
......@@ -135,8 +145,4 @@ class StdJson():
self.tests[test]['actual'] = self.tests[test]['actual'] + " TIMEOUT"
self.tests[test]['is_unexpected'] = True
else:
self.tests[test] = {
'expected': 'PASS',
'actual': 'TIMEOUT',
'is_unexpected': True
}
self.tests[test] = self._init_test('PASS', 'TIMEOUT', True)
......@@ -4,6 +4,7 @@
"""Unittests for standard_json_util.py."""
import collections
import os
import unittest
import standard_json_util as sju
......@@ -105,6 +106,14 @@ class UnitTest(unittest.TestCase):
self.assertTrue(output.tests['e']['actual'], 'FAIL TIMEOUT')
self.assertTrue(output.tests['e']['is_unexpected'], True)
def test_shard(self):
"""Test shard into is written to test result."""
test = 'f'
output = sju.StdJson()
output.mark_passed(test)
self.assertEqual(output.tests['f']['shard'],
os.getenv('GTEST_SHARD_INDEX', 0))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment