xref: /aosp_15_r20/tools/asuite/atest/atest_execution_info_unittest.py (revision c2e18aaa1096c836b086f94603d04f4eb9cf37f5)
1*c2e18aaaSAndroid Build Coastguard Worker#!/usr/bin/env python3
2*c2e18aaaSAndroid Build Coastguard Worker#
3*c2e18aaaSAndroid Build Coastguard Worker# Copyright 2019, The Android Open Source Project
4*c2e18aaaSAndroid Build Coastguard Worker#
5*c2e18aaaSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*c2e18aaaSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*c2e18aaaSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*c2e18aaaSAndroid Build Coastguard Worker#
9*c2e18aaaSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
10*c2e18aaaSAndroid Build Coastguard Worker#
11*c2e18aaaSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*c2e18aaaSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*c2e18aaaSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*c2e18aaaSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*c2e18aaaSAndroid Build Coastguard Worker# limitations under the License.
16*c2e18aaaSAndroid Build Coastguard Worker
17*c2e18aaaSAndroid Build Coastguard Worker"""Unittest for atest_execution_info."""
18*c2e18aaaSAndroid Build Coastguard Worker
19*c2e18aaaSAndroid Build Coastguard Worker
20*c2e18aaaSAndroid Build Coastguard Workerimport os
21*c2e18aaaSAndroid Build Coastguard Workerimport pathlib
22*c2e18aaaSAndroid Build Coastguard Workerimport time
23*c2e18aaaSAndroid Build Coastguard Workerimport unittest
24*c2e18aaaSAndroid Build Coastguard Workerfrom unittest.mock import patch
25*c2e18aaaSAndroid Build Coastguard Workerfrom atest import arg_parser
26*c2e18aaaSAndroid Build Coastguard Workerfrom atest import atest_execution_info as aei
27*c2e18aaaSAndroid Build Coastguard Workerfrom atest import constants
28*c2e18aaaSAndroid Build Coastguard Workerfrom atest import result_reporter
29*c2e18aaaSAndroid Build Coastguard Workerfrom atest.metrics import metrics
30*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_runners import test_runner_base
31*c2e18aaaSAndroid Build Coastguard Workerfrom pyfakefs import fake_filesystem_unittest
32*c2e18aaaSAndroid Build Coastguard Worker
33*c2e18aaaSAndroid Build Coastguard WorkerRESULT_TEST_TEMPLATE = test_runner_base.TestResult(
34*c2e18aaaSAndroid Build Coastguard Worker    runner_name='someRunner',
35*c2e18aaaSAndroid Build Coastguard Worker    group_name='someModule',
36*c2e18aaaSAndroid Build Coastguard Worker    test_name='someClassName#sostName',
37*c2e18aaaSAndroid Build Coastguard Worker    status=test_runner_base.PASSED_STATUS,
38*c2e18aaaSAndroid Build Coastguard Worker    details=None,
39*c2e18aaaSAndroid Build Coastguard Worker    test_count=1,
40*c2e18aaaSAndroid Build Coastguard Worker    test_time='(10ms)',
41*c2e18aaaSAndroid Build Coastguard Worker    runner_total=None,
42*c2e18aaaSAndroid Build Coastguard Worker    group_total=2,
43*c2e18aaaSAndroid Build Coastguard Worker    additional_info={},
44*c2e18aaaSAndroid Build Coastguard Worker    test_run_name='com.android.UnitTests',
45*c2e18aaaSAndroid Build Coastguard Worker)
46*c2e18aaaSAndroid Build Coastguard Worker
47*c2e18aaaSAndroid Build Coastguard Worker
48*c2e18aaaSAndroid Build Coastguard Workerclass CopyBuildTraceToLogsTests(fake_filesystem_unittest.TestCase):
49*c2e18aaaSAndroid Build Coastguard Worker
50*c2e18aaaSAndroid Build Coastguard Worker  def setUp(self):
51*c2e18aaaSAndroid Build Coastguard Worker    super().setUp()
52*c2e18aaaSAndroid Build Coastguard Worker    self.setUpPyfakefs()
53*c2e18aaaSAndroid Build Coastguard Worker    self.fs.create_dir(constants.ATEST_RESULT_ROOT)
54*c2e18aaaSAndroid Build Coastguard Worker
55*c2e18aaaSAndroid Build Coastguard Worker  def test_copy_build_artifacts_to_log_dir_new_trace_copy(self):
56*c2e18aaaSAndroid Build Coastguard Worker    start_time = 10
57*c2e18aaaSAndroid Build Coastguard Worker    log_path = pathlib.Path('/logs')
58*c2e18aaaSAndroid Build Coastguard Worker    self.fs.create_dir(log_path)
59*c2e18aaaSAndroid Build Coastguard Worker    out_path = pathlib.Path('/out')
60*c2e18aaaSAndroid Build Coastguard Worker    build_trace_path = out_path / 'build.trace'
61*c2e18aaaSAndroid Build Coastguard Worker    self.fs.create_file(build_trace_path)
62*c2e18aaaSAndroid Build Coastguard Worker    # Set the trace file's mtime greater than start time
63*c2e18aaaSAndroid Build Coastguard Worker    os.utime(build_trace_path, (20, 20))
64*c2e18aaaSAndroid Build Coastguard Worker    end_time = 30
65*c2e18aaaSAndroid Build Coastguard Worker
66*c2e18aaaSAndroid Build Coastguard Worker    aei.AtestExecutionInfo._copy_build_artifacts_to_log_dir(
67*c2e18aaaSAndroid Build Coastguard Worker        start_time, end_time, out_path, log_path, 'build.trace'
68*c2e18aaaSAndroid Build Coastguard Worker    )
69*c2e18aaaSAndroid Build Coastguard Worker
70*c2e18aaaSAndroid Build Coastguard Worker    self.assertTrue(
71*c2e18aaaSAndroid Build Coastguard Worker        self._is_dir_contains_files_with_prefix(log_path, 'build.trace')
72*c2e18aaaSAndroid Build Coastguard Worker    )
73*c2e18aaaSAndroid Build Coastguard Worker
74*c2e18aaaSAndroid Build Coastguard Worker  def test_copy_build_artifacts_to_log_dir_old_trace_does_not_copy(self):
75*c2e18aaaSAndroid Build Coastguard Worker    start_time = 10
76*c2e18aaaSAndroid Build Coastguard Worker    log_path = pathlib.Path('/logs')
77*c2e18aaaSAndroid Build Coastguard Worker    self.fs.create_dir(log_path)
78*c2e18aaaSAndroid Build Coastguard Worker    out_path = pathlib.Path('/out')
79*c2e18aaaSAndroid Build Coastguard Worker    build_trace_path = out_path / 'build.trace'
80*c2e18aaaSAndroid Build Coastguard Worker    self.fs.create_file(build_trace_path)
81*c2e18aaaSAndroid Build Coastguard Worker    # Set the trace file's mtime smaller than start time
82*c2e18aaaSAndroid Build Coastguard Worker    os.utime(build_trace_path, (5, 5))
83*c2e18aaaSAndroid Build Coastguard Worker    end_time = 30
84*c2e18aaaSAndroid Build Coastguard Worker
85*c2e18aaaSAndroid Build Coastguard Worker    aei.AtestExecutionInfo._copy_build_artifacts_to_log_dir(
86*c2e18aaaSAndroid Build Coastguard Worker        start_time, end_time, out_path, log_path, 'build.trace'
87*c2e18aaaSAndroid Build Coastguard Worker    )
88*c2e18aaaSAndroid Build Coastguard Worker
89*c2e18aaaSAndroid Build Coastguard Worker    self.assertFalse(
90*c2e18aaaSAndroid Build Coastguard Worker        self._is_dir_contains_files_with_prefix(log_path, 'build.trace')
91*c2e18aaaSAndroid Build Coastguard Worker    )
92*c2e18aaaSAndroid Build Coastguard Worker
93*c2e18aaaSAndroid Build Coastguard Worker  def test_copy_multiple_build_trace_to_log_dir(self):
94*c2e18aaaSAndroid Build Coastguard Worker    start_time = 10
95*c2e18aaaSAndroid Build Coastguard Worker    log_path = pathlib.Path('/logs')
96*c2e18aaaSAndroid Build Coastguard Worker    self.fs.create_dir(log_path)
97*c2e18aaaSAndroid Build Coastguard Worker    out_path = pathlib.Path('/out')
98*c2e18aaaSAndroid Build Coastguard Worker    build_trace_path1 = out_path / 'build.trace.1.gz'
99*c2e18aaaSAndroid Build Coastguard Worker    build_trace_path2 = out_path / 'build.trace.2.gz'
100*c2e18aaaSAndroid Build Coastguard Worker    self.fs.create_file(build_trace_path1)
101*c2e18aaaSAndroid Build Coastguard Worker    self.fs.create_file(build_trace_path2)
102*c2e18aaaSAndroid Build Coastguard Worker    # Set the trace file's mtime greater than start time
103*c2e18aaaSAndroid Build Coastguard Worker    os.utime(build_trace_path1, (20, 20))
104*c2e18aaaSAndroid Build Coastguard Worker    os.utime(build_trace_path2, (20, 20))
105*c2e18aaaSAndroid Build Coastguard Worker    end_time = 30
106*c2e18aaaSAndroid Build Coastguard Worker
107*c2e18aaaSAndroid Build Coastguard Worker    aei.AtestExecutionInfo._copy_build_artifacts_to_log_dir(
108*c2e18aaaSAndroid Build Coastguard Worker        start_time, end_time, out_path, log_path, 'build.trace'
109*c2e18aaaSAndroid Build Coastguard Worker    )
110*c2e18aaaSAndroid Build Coastguard Worker
111*c2e18aaaSAndroid Build Coastguard Worker    self.assertTrue(
112*c2e18aaaSAndroid Build Coastguard Worker        self._is_dir_contains_files_with_prefix(log_path, 'build.trace.1.gz')
113*c2e18aaaSAndroid Build Coastguard Worker    )
114*c2e18aaaSAndroid Build Coastguard Worker    self.assertTrue(
115*c2e18aaaSAndroid Build Coastguard Worker        self._is_dir_contains_files_with_prefix(log_path, 'build.trace.2.gz')
116*c2e18aaaSAndroid Build Coastguard Worker    )
117*c2e18aaaSAndroid Build Coastguard Worker
118*c2e18aaaSAndroid Build Coastguard Worker  def _is_dir_contains_files_with_prefix(
119*c2e18aaaSAndroid Build Coastguard Worker      self, dir: pathlib.Path, prefix: str
120*c2e18aaaSAndroid Build Coastguard Worker  ) -> bool:
121*c2e18aaaSAndroid Build Coastguard Worker    for file in dir.iterdir():
122*c2e18aaaSAndroid Build Coastguard Worker      if file.is_file() and file.name.startswith(prefix):
123*c2e18aaaSAndroid Build Coastguard Worker        return True
124*c2e18aaaSAndroid Build Coastguard Worker    return False
125*c2e18aaaSAndroid Build Coastguard Worker
126*c2e18aaaSAndroid Build Coastguard Worker
127*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=protected-access
128*c2e18aaaSAndroid Build Coastguard Workerclass AtestExecutionInfoUnittests(unittest.TestCase):
129*c2e18aaaSAndroid Build Coastguard Worker  """Unit tests for atest_execution_info.py"""
130*c2e18aaaSAndroid Build Coastguard Worker
131*c2e18aaaSAndroid Build Coastguard Worker  @patch('atest.metrics.metrics.is_internal_user', return_value=False)
132*c2e18aaaSAndroid Build Coastguard Worker  def test_create_bug_report_url_is_external_user_return_empty(self, _):
133*c2e18aaaSAndroid Build Coastguard Worker    url = aei.AtestExecutionInfo._create_bug_report_url()
134*c2e18aaaSAndroid Build Coastguard Worker
135*c2e18aaaSAndroid Build Coastguard Worker    self.assertFalse(url)
136*c2e18aaaSAndroid Build Coastguard Worker
137*c2e18aaaSAndroid Build Coastguard Worker  @patch('atest.metrics.metrics.is_internal_user', return_value=True)
138*c2e18aaaSAndroid Build Coastguard Worker  def test_create_bug_report_url_is_internal_user_return_url(self, _):
139*c2e18aaaSAndroid Build Coastguard Worker    url = aei.AtestExecutionInfo._create_bug_report_url()
140*c2e18aaaSAndroid Build Coastguard Worker
141*c2e18aaaSAndroid Build Coastguard Worker    self.assertTrue(url)
142*c2e18aaaSAndroid Build Coastguard Worker
143*c2e18aaaSAndroid Build Coastguard Worker  @patch('atest.metrics.metrics.is_internal_user', return_value=True)
144*c2e18aaaSAndroid Build Coastguard Worker  @patch('atest.logstorage.log_uploader.is_uploading_logs', return_value=True)
145*c2e18aaaSAndroid Build Coastguard Worker  def test_create_bug_report_url_is_uploading_logs_use_contains_run_id(
146*c2e18aaaSAndroid Build Coastguard Worker      self, _, __
147*c2e18aaaSAndroid Build Coastguard Worker  ):
148*c2e18aaaSAndroid Build Coastguard Worker    url = aei.AtestExecutionInfo._create_bug_report_url()
149*c2e18aaaSAndroid Build Coastguard Worker
150*c2e18aaaSAndroid Build Coastguard Worker    self.assertIn(metrics.get_run_id(), url)
151*c2e18aaaSAndroid Build Coastguard Worker
152*c2e18aaaSAndroid Build Coastguard Worker  @patch('atest.metrics.metrics.is_internal_user', return_value=True)
153*c2e18aaaSAndroid Build Coastguard Worker  @patch('atest.logstorage.log_uploader.is_uploading_logs', return_value=False)
154*c2e18aaaSAndroid Build Coastguard Worker  def test_create_bug_report_url_is_not_uploading_logs_use_contains_run_id(
155*c2e18aaaSAndroid Build Coastguard Worker      self, _, __
156*c2e18aaaSAndroid Build Coastguard Worker  ):
157*c2e18aaaSAndroid Build Coastguard Worker    url = aei.AtestExecutionInfo._create_bug_report_url()
158*c2e18aaaSAndroid Build Coastguard Worker
159*c2e18aaaSAndroid Build Coastguard Worker    self.assertNotIn(metrics.get_run_id(), url)
160*c2e18aaaSAndroid Build Coastguard Worker
161*c2e18aaaSAndroid Build Coastguard Worker  def test_arrange_test_result_one_module(self):
162*c2e18aaaSAndroid Build Coastguard Worker    """Test _arrange_test_result method with only one module."""
163*c2e18aaaSAndroid Build Coastguard Worker    pass_1 = self._create_test_result(status=test_runner_base.PASSED_STATUS)
164*c2e18aaaSAndroid Build Coastguard Worker    pass_2 = self._create_test_result(status=test_runner_base.PASSED_STATUS)
165*c2e18aaaSAndroid Build Coastguard Worker    pass_3 = self._create_test_result(status=test_runner_base.PASSED_STATUS)
166*c2e18aaaSAndroid Build Coastguard Worker    fail_1 = self._create_test_result(status=test_runner_base.FAILED_STATUS)
167*c2e18aaaSAndroid Build Coastguard Worker    fail_2 = self._create_test_result(status=test_runner_base.FAILED_STATUS)
168*c2e18aaaSAndroid Build Coastguard Worker    ignore_1 = self._create_test_result(status=test_runner_base.IGNORED_STATUS)
169*c2e18aaaSAndroid Build Coastguard Worker    reporter_1 = result_reporter.ResultReporter()
170*c2e18aaaSAndroid Build Coastguard Worker    reporter_1.all_test_results.extend([pass_1, pass_2, pass_3])
171*c2e18aaaSAndroid Build Coastguard Worker    reporter_2 = result_reporter.ResultReporter()
172*c2e18aaaSAndroid Build Coastguard Worker    reporter_2.all_test_results.extend([fail_1, fail_2, ignore_1])
173*c2e18aaaSAndroid Build Coastguard Worker    info_dict = {}
174*c2e18aaaSAndroid Build Coastguard Worker    aei.AtestExecutionInfo._arrange_test_result(
175*c2e18aaaSAndroid Build Coastguard Worker        info_dict, [reporter_1, reporter_2]
176*c2e18aaaSAndroid Build Coastguard Worker    )
177*c2e18aaaSAndroid Build Coastguard Worker    expect_summary = {
178*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_IGNORED_KEY: 1,
179*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_FAILED_KEY: 2,
180*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_PASSED_KEY: 3,
181*c2e18aaaSAndroid Build Coastguard Worker    }
182*c2e18aaaSAndroid Build Coastguard Worker    self.assertEqual(expect_summary, info_dict[aei._TOTAL_SUMMARY_KEY])
183*c2e18aaaSAndroid Build Coastguard Worker
184*c2e18aaaSAndroid Build Coastguard Worker  def test_arrange_test_result_multi_module(self):
185*c2e18aaaSAndroid Build Coastguard Worker    """Test _arrange_test_result method with multi module."""
186*c2e18aaaSAndroid Build Coastguard Worker    group_a_pass_1 = self._create_test_result(
187*c2e18aaaSAndroid Build Coastguard Worker        group_name='grpup_a', status=test_runner_base.PASSED_STATUS
188*c2e18aaaSAndroid Build Coastguard Worker    )
189*c2e18aaaSAndroid Build Coastguard Worker    group_b_pass_1 = self._create_test_result(
190*c2e18aaaSAndroid Build Coastguard Worker        group_name='grpup_b', status=test_runner_base.PASSED_STATUS
191*c2e18aaaSAndroid Build Coastguard Worker    )
192*c2e18aaaSAndroid Build Coastguard Worker    group_c_pass_1 = self._create_test_result(
193*c2e18aaaSAndroid Build Coastguard Worker        group_name='grpup_c', status=test_runner_base.PASSED_STATUS
194*c2e18aaaSAndroid Build Coastguard Worker    )
195*c2e18aaaSAndroid Build Coastguard Worker    group_b_fail_1 = self._create_test_result(
196*c2e18aaaSAndroid Build Coastguard Worker        group_name='grpup_b', status=test_runner_base.FAILED_STATUS
197*c2e18aaaSAndroid Build Coastguard Worker    )
198*c2e18aaaSAndroid Build Coastguard Worker    group_c_fail_1 = self._create_test_result(
199*c2e18aaaSAndroid Build Coastguard Worker        group_name='grpup_c', status=test_runner_base.FAILED_STATUS
200*c2e18aaaSAndroid Build Coastguard Worker    )
201*c2e18aaaSAndroid Build Coastguard Worker    group_c_ignore_1 = self._create_test_result(
202*c2e18aaaSAndroid Build Coastguard Worker        group_name='grpup_c', status=test_runner_base.IGNORED_STATUS
203*c2e18aaaSAndroid Build Coastguard Worker    )
204*c2e18aaaSAndroid Build Coastguard Worker    reporter_1 = result_reporter.ResultReporter()
205*c2e18aaaSAndroid Build Coastguard Worker    reporter_1.all_test_results.extend(
206*c2e18aaaSAndroid Build Coastguard Worker        [group_a_pass_1, group_b_pass_1, group_c_pass_1]
207*c2e18aaaSAndroid Build Coastguard Worker    )
208*c2e18aaaSAndroid Build Coastguard Worker    reporter_2 = result_reporter.ResultReporter()
209*c2e18aaaSAndroid Build Coastguard Worker    reporter_2.all_test_results.extend(
210*c2e18aaaSAndroid Build Coastguard Worker        [group_b_fail_1, group_c_fail_1, group_c_ignore_1]
211*c2e18aaaSAndroid Build Coastguard Worker    )
212*c2e18aaaSAndroid Build Coastguard Worker
213*c2e18aaaSAndroid Build Coastguard Worker    info_dict = {}
214*c2e18aaaSAndroid Build Coastguard Worker    aei.AtestExecutionInfo._arrange_test_result(
215*c2e18aaaSAndroid Build Coastguard Worker        info_dict, [reporter_1, reporter_2]
216*c2e18aaaSAndroid Build Coastguard Worker    )
217*c2e18aaaSAndroid Build Coastguard Worker    expect_group_a_summary = {
218*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_IGNORED_KEY: 0,
219*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_FAILED_KEY: 0,
220*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_PASSED_KEY: 1,
221*c2e18aaaSAndroid Build Coastguard Worker    }
222*c2e18aaaSAndroid Build Coastguard Worker    self.assertEqual(
223*c2e18aaaSAndroid Build Coastguard Worker        expect_group_a_summary,
224*c2e18aaaSAndroid Build Coastguard Worker        info_dict[aei._TEST_RUNNER_KEY]['someRunner']['grpup_a'][
225*c2e18aaaSAndroid Build Coastguard Worker            aei._SUMMARY_KEY
226*c2e18aaaSAndroid Build Coastguard Worker        ],
227*c2e18aaaSAndroid Build Coastguard Worker    )
228*c2e18aaaSAndroid Build Coastguard Worker
229*c2e18aaaSAndroid Build Coastguard Worker    expect_group_b_summary = {
230*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_IGNORED_KEY: 0,
231*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_FAILED_KEY: 1,
232*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_PASSED_KEY: 1,
233*c2e18aaaSAndroid Build Coastguard Worker    }
234*c2e18aaaSAndroid Build Coastguard Worker    self.assertEqual(
235*c2e18aaaSAndroid Build Coastguard Worker        expect_group_b_summary,
236*c2e18aaaSAndroid Build Coastguard Worker        info_dict[aei._TEST_RUNNER_KEY]['someRunner']['grpup_b'][
237*c2e18aaaSAndroid Build Coastguard Worker            aei._SUMMARY_KEY
238*c2e18aaaSAndroid Build Coastguard Worker        ],
239*c2e18aaaSAndroid Build Coastguard Worker    )
240*c2e18aaaSAndroid Build Coastguard Worker
241*c2e18aaaSAndroid Build Coastguard Worker    expect_group_c_summary = {
242*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_IGNORED_KEY: 1,
243*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_FAILED_KEY: 1,
244*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_PASSED_KEY: 1,
245*c2e18aaaSAndroid Build Coastguard Worker    }
246*c2e18aaaSAndroid Build Coastguard Worker    self.assertEqual(
247*c2e18aaaSAndroid Build Coastguard Worker        expect_group_c_summary,
248*c2e18aaaSAndroid Build Coastguard Worker        info_dict[aei._TEST_RUNNER_KEY]['someRunner']['grpup_c'][
249*c2e18aaaSAndroid Build Coastguard Worker            aei._SUMMARY_KEY
250*c2e18aaaSAndroid Build Coastguard Worker        ],
251*c2e18aaaSAndroid Build Coastguard Worker    )
252*c2e18aaaSAndroid Build Coastguard Worker
253*c2e18aaaSAndroid Build Coastguard Worker    expect_total_summary = {
254*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_IGNORED_KEY: 1,
255*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_FAILED_KEY: 2,
256*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_PASSED_KEY: 3,
257*c2e18aaaSAndroid Build Coastguard Worker    }
258*c2e18aaaSAndroid Build Coastguard Worker    self.assertEqual(expect_total_summary, info_dict[aei._TOTAL_SUMMARY_KEY])
259*c2e18aaaSAndroid Build Coastguard Worker
260*c2e18aaaSAndroid Build Coastguard Worker  def test_preparation_time(self):
261*c2e18aaaSAndroid Build Coastguard Worker    """Test preparation_time method."""
262*c2e18aaaSAndroid Build Coastguard Worker    start_time = time.time()
263*c2e18aaaSAndroid Build Coastguard Worker    aei.PREPARE_END_TIME = None
264*c2e18aaaSAndroid Build Coastguard Worker    self.assertTrue(aei.preparation_time(start_time) is None)
265*c2e18aaaSAndroid Build Coastguard Worker    aei.PREPARE_END_TIME = time.time()
266*c2e18aaaSAndroid Build Coastguard Worker    self.assertFalse(aei.preparation_time(start_time) is None)
267*c2e18aaaSAndroid Build Coastguard Worker
268*c2e18aaaSAndroid Build Coastguard Worker  def test_arrange_test_result_multi_runner(self):
269*c2e18aaaSAndroid Build Coastguard Worker    """Test _arrange_test_result method with multi runner."""
270*c2e18aaaSAndroid Build Coastguard Worker    runner_a_pass_1 = self._create_test_result(
271*c2e18aaaSAndroid Build Coastguard Worker        runner_name='runner_a', status=test_runner_base.PASSED_STATUS
272*c2e18aaaSAndroid Build Coastguard Worker    )
273*c2e18aaaSAndroid Build Coastguard Worker    runner_a_pass_2 = self._create_test_result(
274*c2e18aaaSAndroid Build Coastguard Worker        runner_name='runner_a', status=test_runner_base.PASSED_STATUS
275*c2e18aaaSAndroid Build Coastguard Worker    )
276*c2e18aaaSAndroid Build Coastguard Worker    runner_a_pass_3 = self._create_test_result(
277*c2e18aaaSAndroid Build Coastguard Worker        runner_name='runner_a', status=test_runner_base.PASSED_STATUS
278*c2e18aaaSAndroid Build Coastguard Worker    )
279*c2e18aaaSAndroid Build Coastguard Worker    runner_b_fail_1 = self._create_test_result(
280*c2e18aaaSAndroid Build Coastguard Worker        runner_name='runner_b', status=test_runner_base.FAILED_STATUS
281*c2e18aaaSAndroid Build Coastguard Worker    )
282*c2e18aaaSAndroid Build Coastguard Worker    runner_b_fail_2 = self._create_test_result(
283*c2e18aaaSAndroid Build Coastguard Worker        runner_name='runner_b', status=test_runner_base.FAILED_STATUS
284*c2e18aaaSAndroid Build Coastguard Worker    )
285*c2e18aaaSAndroid Build Coastguard Worker    runner_b_ignore_1 = self._create_test_result(
286*c2e18aaaSAndroid Build Coastguard Worker        runner_name='runner_b', status=test_runner_base.IGNORED_STATUS
287*c2e18aaaSAndroid Build Coastguard Worker    )
288*c2e18aaaSAndroid Build Coastguard Worker
289*c2e18aaaSAndroid Build Coastguard Worker    reporter_1 = result_reporter.ResultReporter()
290*c2e18aaaSAndroid Build Coastguard Worker    reporter_1.all_test_results.extend(
291*c2e18aaaSAndroid Build Coastguard Worker        [runner_a_pass_1, runner_a_pass_2, runner_a_pass_3]
292*c2e18aaaSAndroid Build Coastguard Worker    )
293*c2e18aaaSAndroid Build Coastguard Worker    reporter_2 = result_reporter.ResultReporter()
294*c2e18aaaSAndroid Build Coastguard Worker    reporter_2.all_test_results.extend(
295*c2e18aaaSAndroid Build Coastguard Worker        [runner_b_fail_1, runner_b_fail_2, runner_b_ignore_1]
296*c2e18aaaSAndroid Build Coastguard Worker    )
297*c2e18aaaSAndroid Build Coastguard Worker    info_dict = {}
298*c2e18aaaSAndroid Build Coastguard Worker    aei.AtestExecutionInfo._arrange_test_result(
299*c2e18aaaSAndroid Build Coastguard Worker        info_dict, [reporter_1, reporter_2]
300*c2e18aaaSAndroid Build Coastguard Worker    )
301*c2e18aaaSAndroid Build Coastguard Worker    expect_group_a_summary = {
302*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_IGNORED_KEY: 0,
303*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_FAILED_KEY: 0,
304*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_PASSED_KEY: 3,
305*c2e18aaaSAndroid Build Coastguard Worker    }
306*c2e18aaaSAndroid Build Coastguard Worker    self.assertEqual(
307*c2e18aaaSAndroid Build Coastguard Worker        expect_group_a_summary,
308*c2e18aaaSAndroid Build Coastguard Worker        info_dict[aei._TEST_RUNNER_KEY]['runner_a']['someModule'][
309*c2e18aaaSAndroid Build Coastguard Worker            aei._SUMMARY_KEY
310*c2e18aaaSAndroid Build Coastguard Worker        ],
311*c2e18aaaSAndroid Build Coastguard Worker    )
312*c2e18aaaSAndroid Build Coastguard Worker
313*c2e18aaaSAndroid Build Coastguard Worker    expect_group_b_summary = {
314*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_IGNORED_KEY: 1,
315*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_FAILED_KEY: 2,
316*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_PASSED_KEY: 0,
317*c2e18aaaSAndroid Build Coastguard Worker    }
318*c2e18aaaSAndroid Build Coastguard Worker    self.assertEqual(
319*c2e18aaaSAndroid Build Coastguard Worker        expect_group_b_summary,
320*c2e18aaaSAndroid Build Coastguard Worker        info_dict[aei._TEST_RUNNER_KEY]['runner_b']['someModule'][
321*c2e18aaaSAndroid Build Coastguard Worker            aei._SUMMARY_KEY
322*c2e18aaaSAndroid Build Coastguard Worker        ],
323*c2e18aaaSAndroid Build Coastguard Worker    )
324*c2e18aaaSAndroid Build Coastguard Worker
325*c2e18aaaSAndroid Build Coastguard Worker    expect_total_summary = {
326*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_IGNORED_KEY: 1,
327*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_FAILED_KEY: 2,
328*c2e18aaaSAndroid Build Coastguard Worker        aei._STATUS_PASSED_KEY: 3,
329*c2e18aaaSAndroid Build Coastguard Worker    }
330*c2e18aaaSAndroid Build Coastguard Worker    self.assertEqual(expect_total_summary, info_dict[aei._TOTAL_SUMMARY_KEY])
331*c2e18aaaSAndroid Build Coastguard Worker
332*c2e18aaaSAndroid Build Coastguard Worker  def _create_test_result(self, **kwargs):
333*c2e18aaaSAndroid Build Coastguard Worker    """A Helper to create TestResult"""
334*c2e18aaaSAndroid Build Coastguard Worker    test_info = test_runner_base.TestResult(**RESULT_TEST_TEMPLATE._asdict())
335*c2e18aaaSAndroid Build Coastguard Worker    return test_info._replace(**kwargs)
336*c2e18aaaSAndroid Build Coastguard Worker
337*c2e18aaaSAndroid Build Coastguard Worker
338*c2e18aaaSAndroid Build Coastguard Workerif __name__ == '__main__':
339*c2e18aaaSAndroid Build Coastguard Worker  unittest.main()
340