1*c2e18aaaSAndroid Build Coastguard Worker#!/usr/bin/env python3 2*c2e18aaaSAndroid Build Coastguard Worker# 3*c2e18aaaSAndroid Build Coastguard Worker# Copyright 2018, 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"""Unittests for result_reporter.""" 18*c2e18aaaSAndroid Build Coastguard Worker 19*c2e18aaaSAndroid Build Coastguard Worker 20*c2e18aaaSAndroid Build Coastguard Workerfrom io import StringIO 21*c2e18aaaSAndroid Build Coastguard Workerimport sys 22*c2e18aaaSAndroid Build Coastguard Workerimport unittest 23*c2e18aaaSAndroid Build Coastguard Workerfrom unittest import mock 24*c2e18aaaSAndroid Build Coastguard Workerfrom unittest.mock import patch 25*c2e18aaaSAndroid Build Coastguard Worker 26*c2e18aaaSAndroid Build Coastguard Workerfrom atest import arg_parser 27*c2e18aaaSAndroid Build Coastguard Workerfrom atest import atest_configs 28*c2e18aaaSAndroid Build Coastguard Workerfrom atest import result_reporter 29*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import test_info 30*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_runners import test_runner_base 31*c2e18aaaSAndroid Build Coastguard Worker 32*c2e18aaaSAndroid Build Coastguard Worker 33*c2e18aaaSAndroid Build Coastguard WorkerRESULT_PASSED_TEST = test_runner_base.TestResult( 34*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 35*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 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 WorkerRESULT_PASSED_TEST_MODULE_2 = test_runner_base.TestResult( 48*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 49*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule2', 50*c2e18aaaSAndroid Build Coastguard Worker test_name='someClassName#sostName', 51*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.PASSED_STATUS, 52*c2e18aaaSAndroid Build Coastguard Worker details=None, 53*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 54*c2e18aaaSAndroid Build Coastguard Worker test_time='(10ms)', 55*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 56*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 57*c2e18aaaSAndroid Build Coastguard Worker additional_info={}, 58*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 59*c2e18aaaSAndroid Build Coastguard Worker) 60*c2e18aaaSAndroid Build Coastguard Worker 61*c2e18aaaSAndroid Build Coastguard WorkerRESULT_PASSED_TEST_RUNNER_2_NO_MODULE = test_runner_base.TestResult( 62*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner2', 63*c2e18aaaSAndroid Build Coastguard Worker group_name=None, 64*c2e18aaaSAndroid Build Coastguard Worker test_name='someClassName#sostName', 65*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.PASSED_STATUS, 66*c2e18aaaSAndroid Build Coastguard Worker details=None, 67*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 68*c2e18aaaSAndroid Build Coastguard Worker test_time='(10ms)', 69*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 70*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 71*c2e18aaaSAndroid Build Coastguard Worker additional_info={}, 72*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 73*c2e18aaaSAndroid Build Coastguard Worker) 74*c2e18aaaSAndroid Build Coastguard Worker 75*c2e18aaaSAndroid Build Coastguard WorkerRESULT_FAILED_TEST = test_runner_base.TestResult( 76*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 77*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 78*c2e18aaaSAndroid Build Coastguard Worker test_name='someClassName2#sestName2', 79*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.FAILED_STATUS, 80*c2e18aaaSAndroid Build Coastguard Worker details='someTrace', 81*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 82*c2e18aaaSAndroid Build Coastguard Worker test_time='', 83*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 84*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 85*c2e18aaaSAndroid Build Coastguard Worker additional_info={}, 86*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 87*c2e18aaaSAndroid Build Coastguard Worker) 88*c2e18aaaSAndroid Build Coastguard Worker 89*c2e18aaaSAndroid Build Coastguard WorkerRESULT_RUN_FAILURE = test_runner_base.TestResult( 90*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 91*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 92*c2e18aaaSAndroid Build Coastguard Worker test_name='someClassName#sostName', 93*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.ERROR_STATUS, 94*c2e18aaaSAndroid Build Coastguard Worker details='someRunFailureReason', 95*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 96*c2e18aaaSAndroid Build Coastguard Worker test_time='', 97*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 98*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 99*c2e18aaaSAndroid Build Coastguard Worker additional_info={}, 100*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 101*c2e18aaaSAndroid Build Coastguard Worker) 102*c2e18aaaSAndroid Build Coastguard Worker 103*c2e18aaaSAndroid Build Coastguard WorkerRESULT_INVOCATION_FAILURE = test_runner_base.TestResult( 104*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 105*c2e18aaaSAndroid Build Coastguard Worker group_name=None, 106*c2e18aaaSAndroid Build Coastguard Worker test_name=None, 107*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.ERROR_STATUS, 108*c2e18aaaSAndroid Build Coastguard Worker details='someInvocationFailureReason', 109*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 110*c2e18aaaSAndroid Build Coastguard Worker test_time='', 111*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 112*c2e18aaaSAndroid Build Coastguard Worker group_total=None, 113*c2e18aaaSAndroid Build Coastguard Worker additional_info={}, 114*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 115*c2e18aaaSAndroid Build Coastguard Worker) 116*c2e18aaaSAndroid Build Coastguard Worker 117*c2e18aaaSAndroid Build Coastguard WorkerRESULT_IGNORED_TEST = test_runner_base.TestResult( 118*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 119*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 120*c2e18aaaSAndroid Build Coastguard Worker test_name='someClassName#sostName', 121*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.IGNORED_STATUS, 122*c2e18aaaSAndroid Build Coastguard Worker details=None, 123*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 124*c2e18aaaSAndroid Build Coastguard Worker test_time='(10ms)', 125*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 126*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 127*c2e18aaaSAndroid Build Coastguard Worker additional_info={}, 128*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 129*c2e18aaaSAndroid Build Coastguard Worker) 130*c2e18aaaSAndroid Build Coastguard Worker 131*c2e18aaaSAndroid Build Coastguard WorkerRESULT_ASSUMPTION_FAILED_TEST = test_runner_base.TestResult( 132*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 133*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 134*c2e18aaaSAndroid Build Coastguard Worker test_name='someClassName#sostName', 135*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.ASSUMPTION_FAILED, 136*c2e18aaaSAndroid Build Coastguard Worker details=None, 137*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 138*c2e18aaaSAndroid Build Coastguard Worker test_time='(10ms)', 139*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 140*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 141*c2e18aaaSAndroid Build Coastguard Worker additional_info={}, 142*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 143*c2e18aaaSAndroid Build Coastguard Worker) 144*c2e18aaaSAndroid Build Coastguard Worker 145*c2e18aaaSAndroid Build Coastguard WorkerADDITIONAL_INFO_PERF01_TEST01 = { 146*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 147*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': '10001.10001', 148*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName01', 149*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 150*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 151*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 152*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 153*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 154*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '1001', 155*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName01', 156*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '11001.11001', 157*c2e18aaaSAndroid Build Coastguard Worker} 158*c2e18aaaSAndroid Build Coastguard Worker 159*c2e18aaaSAndroid Build Coastguard WorkerRESULT_PERF01_TEST01 = test_runner_base.TestResult( 160*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 161*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 162*c2e18aaaSAndroid Build Coastguard Worker test_name='somePerfClass01#perfName01', 163*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.PASSED_STATUS, 164*c2e18aaaSAndroid Build Coastguard Worker details=None, 165*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 166*c2e18aaaSAndroid Build Coastguard Worker test_time='(10ms)', 167*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 168*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 169*c2e18aaaSAndroid Build Coastguard Worker additional_info=ADDITIONAL_INFO_PERF01_TEST01, 170*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 171*c2e18aaaSAndroid Build Coastguard Worker) 172*c2e18aaaSAndroid Build Coastguard Worker 173*c2e18aaaSAndroid Build Coastguard WorkerRESULT_PERF01_TEST02 = test_runner_base.TestResult( 174*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 175*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 176*c2e18aaaSAndroid Build Coastguard Worker test_name='somePerfClass01#perfName02', 177*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.PASSED_STATUS, 178*c2e18aaaSAndroid Build Coastguard Worker details=None, 179*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 180*c2e18aaaSAndroid Build Coastguard Worker test_time='(10ms)', 181*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 182*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 183*c2e18aaaSAndroid Build Coastguard Worker additional_info={ 184*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 185*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': '10002.10002', 186*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName02', 187*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 188*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 189*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 190*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 191*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 192*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '1002', 193*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName02', 194*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '11002.11002', 195*c2e18aaaSAndroid Build Coastguard Worker }, 196*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 197*c2e18aaaSAndroid Build Coastguard Worker) 198*c2e18aaaSAndroid Build Coastguard Worker 199*c2e18aaaSAndroid Build Coastguard WorkerRESULT_PERF01_TEST03_NO_CPU_TIME = test_runner_base.TestResult( 200*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 201*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 202*c2e18aaaSAndroid Build Coastguard Worker test_name='somePerfClass01#perfName03', 203*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.PASSED_STATUS, 204*c2e18aaaSAndroid Build Coastguard Worker details=None, 205*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 206*c2e18aaaSAndroid Build Coastguard Worker test_time='(10ms)', 207*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 208*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 209*c2e18aaaSAndroid Build Coastguard Worker additional_info={ 210*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 211*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName03', 212*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 213*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 214*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 215*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 216*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 217*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '1003', 218*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName03', 219*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '11003.11003', 220*c2e18aaaSAndroid Build Coastguard Worker }, 221*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 222*c2e18aaaSAndroid Build Coastguard Worker) 223*c2e18aaaSAndroid Build Coastguard Worker 224*c2e18aaaSAndroid Build Coastguard WorkerRESULT_PERF02_TEST01 = test_runner_base.TestResult( 225*c2e18aaaSAndroid Build Coastguard Worker runner_name='someTestRunner', 226*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 227*c2e18aaaSAndroid Build Coastguard Worker test_name='somePerfClass02#perfName11', 228*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.PASSED_STATUS, 229*c2e18aaaSAndroid Build Coastguard Worker details=None, 230*c2e18aaaSAndroid Build Coastguard Worker test_count=1, 231*c2e18aaaSAndroid Build Coastguard Worker test_time='(10ms)', 232*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 233*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 234*c2e18aaaSAndroid Build Coastguard Worker additional_info={ 235*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 236*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': '20001.20001', 237*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName11', 238*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 239*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 240*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 241*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 242*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 243*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '2001', 244*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName11', 245*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '21001.21001', 246*c2e18aaaSAndroid Build Coastguard Worker }, 247*c2e18aaaSAndroid Build Coastguard Worker test_run_name='com.android.UnitTests', 248*c2e18aaaSAndroid Build Coastguard Worker) 249*c2e18aaaSAndroid Build Coastguard Worker 250*c2e18aaaSAndroid Build Coastguard Worker 251*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=protected-access 252*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=invalid-name 253*c2e18aaaSAndroid Build Coastguard Workerclass ResultReporterUnittests(unittest.TestCase): 254*c2e18aaaSAndroid Build Coastguard Worker """Unit tests for result_reporter.py""" 255*c2e18aaaSAndroid Build Coastguard Worker 256*c2e18aaaSAndroid Build Coastguard Worker def setUp(self): 257*c2e18aaaSAndroid Build Coastguard Worker self.rr = result_reporter.ResultReporter() 258*c2e18aaaSAndroid Build Coastguard Worker 259*c2e18aaaSAndroid Build Coastguard Worker def tearDown(self): 260*c2e18aaaSAndroid Build Coastguard Worker mock.patch.stopall() 261*c2e18aaaSAndroid Build Coastguard Worker 262*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(result_reporter.ResultReporter, '_print_group_title') 263*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(result_reporter.ResultReporter, '_update_stats') 264*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(result_reporter.ResultReporter, '_print_result') 265*c2e18aaaSAndroid Build Coastguard Worker def test_process_test_result(self, mock_print, mock_update, mock_title): 266*c2e18aaaSAndroid Build Coastguard Worker """Test process_test_result method.""" 267*c2e18aaaSAndroid Build Coastguard Worker # Passed Test 268*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue('someTestRunner' not in self.rr.runners) 269*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_PASSED_TEST) 270*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue('someTestRunner' in self.rr.runners) 271*c2e18aaaSAndroid Build Coastguard Worker group = self.rr.runners['someTestRunner'].get('someTestModule') 272*c2e18aaaSAndroid Build Coastguard Worker self.assertIsNotNone(group) 273*c2e18aaaSAndroid Build Coastguard Worker mock_title.assert_called_with(RESULT_PASSED_TEST) 274*c2e18aaaSAndroid Build Coastguard Worker mock_update.assert_called_with(RESULT_PASSED_TEST, group) 275*c2e18aaaSAndroid Build Coastguard Worker mock_print.assert_called_with(RESULT_PASSED_TEST) 276*c2e18aaaSAndroid Build Coastguard Worker # Failed Test 277*c2e18aaaSAndroid Build Coastguard Worker mock_title.reset_mock() 278*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_FAILED_TEST) 279*c2e18aaaSAndroid Build Coastguard Worker mock_title.assert_not_called() 280*c2e18aaaSAndroid Build Coastguard Worker mock_update.assert_called_with(RESULT_FAILED_TEST, group) 281*c2e18aaaSAndroid Build Coastguard Worker mock_print.assert_called_with(RESULT_FAILED_TEST) 282*c2e18aaaSAndroid Build Coastguard Worker # Test with new Group 283*c2e18aaaSAndroid Build Coastguard Worker mock_title.reset_mock() 284*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_PASSED_TEST_MODULE_2) 285*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue('someTestModule2' in self.rr.runners['someTestRunner']) 286*c2e18aaaSAndroid Build Coastguard Worker mock_title.assert_called_with(RESULT_PASSED_TEST_MODULE_2) 287*c2e18aaaSAndroid Build Coastguard Worker # Test with new Runner 288*c2e18aaaSAndroid Build Coastguard Worker mock_title.reset_mock() 289*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_PASSED_TEST_RUNNER_2_NO_MODULE) 290*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue('someTestRunner2' in self.rr.runners) 291*c2e18aaaSAndroid Build Coastguard Worker mock_title.assert_called_with(RESULT_PASSED_TEST_RUNNER_2_NO_MODULE) 292*c2e18aaaSAndroid Build Coastguard Worker 293*c2e18aaaSAndroid Build Coastguard Worker def test_print_result_run_name(self): 294*c2e18aaaSAndroid Build Coastguard Worker """Test print run name function in print_result method.""" 295*c2e18aaaSAndroid Build Coastguard Worker try: 296*c2e18aaaSAndroid Build Coastguard Worker rr = result_reporter.ResultReporter() 297*c2e18aaaSAndroid Build Coastguard Worker capture_output = StringIO() 298*c2e18aaaSAndroid Build Coastguard Worker sys.stdout = capture_output 299*c2e18aaaSAndroid Build Coastguard Worker run_name = 'com.android.UnitTests' 300*c2e18aaaSAndroid Build Coastguard Worker rr._print_result( 301*c2e18aaaSAndroid Build Coastguard Worker test_runner_base.TestResult( 302*c2e18aaaSAndroid Build Coastguard Worker runner_name='runner_name', 303*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 304*c2e18aaaSAndroid Build Coastguard Worker test_name='someClassName#someTestName', 305*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.FAILED_STATUS, 306*c2e18aaaSAndroid Build Coastguard Worker details='someTrace', 307*c2e18aaaSAndroid Build Coastguard Worker test_count=2, 308*c2e18aaaSAndroid Build Coastguard Worker test_time='(2h44m36.402s)', 309*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 310*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 311*c2e18aaaSAndroid Build Coastguard Worker additional_info={}, 312*c2e18aaaSAndroid Build Coastguard Worker test_run_name=run_name, 313*c2e18aaaSAndroid Build Coastguard Worker ) 314*c2e18aaaSAndroid Build Coastguard Worker ) 315*c2e18aaaSAndroid Build Coastguard Worker # Make sure run name in the first line. 316*c2e18aaaSAndroid Build Coastguard Worker capture_output_str = capture_output.getvalue().strip() 317*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(run_name in capture_output_str.split('\n')[0]) 318*c2e18aaaSAndroid Build Coastguard Worker run_name2 = 'com.android.UnitTests2' 319*c2e18aaaSAndroid Build Coastguard Worker capture_output = StringIO() 320*c2e18aaaSAndroid Build Coastguard Worker sys.stdout = capture_output 321*c2e18aaaSAndroid Build Coastguard Worker rr._print_result( 322*c2e18aaaSAndroid Build Coastguard Worker test_runner_base.TestResult( 323*c2e18aaaSAndroid Build Coastguard Worker runner_name='runner_name', 324*c2e18aaaSAndroid Build Coastguard Worker group_name='someTestModule', 325*c2e18aaaSAndroid Build Coastguard Worker test_name='someClassName#someTestName', 326*c2e18aaaSAndroid Build Coastguard Worker status=test_runner_base.FAILED_STATUS, 327*c2e18aaaSAndroid Build Coastguard Worker details='someTrace', 328*c2e18aaaSAndroid Build Coastguard Worker test_count=2, 329*c2e18aaaSAndroid Build Coastguard Worker test_time='(2h43m36.402s)', 330*c2e18aaaSAndroid Build Coastguard Worker runner_total=None, 331*c2e18aaaSAndroid Build Coastguard Worker group_total=2, 332*c2e18aaaSAndroid Build Coastguard Worker additional_info={}, 333*c2e18aaaSAndroid Build Coastguard Worker test_run_name=run_name2, 334*c2e18aaaSAndroid Build Coastguard Worker ) 335*c2e18aaaSAndroid Build Coastguard Worker ) 336*c2e18aaaSAndroid Build Coastguard Worker # Make sure run name in the first line. 337*c2e18aaaSAndroid Build Coastguard Worker capture_output_str = capture_output.getvalue().strip() 338*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(run_name2 in capture_output_str.split('\n')[0]) 339*c2e18aaaSAndroid Build Coastguard Worker finally: 340*c2e18aaaSAndroid Build Coastguard Worker sys.stdout = sys.__stdout__ 341*c2e18aaaSAndroid Build Coastguard Worker 342*c2e18aaaSAndroid Build Coastguard Worker def test_register_unsupported_runner(self): 343*c2e18aaaSAndroid Build Coastguard Worker """Test register_unsupported_runner method.""" 344*c2e18aaaSAndroid Build Coastguard Worker self.rr.register_unsupported_runner('NotSupported') 345*c2e18aaaSAndroid Build Coastguard Worker runner = self.rr.runners['NotSupported'] 346*c2e18aaaSAndroid Build Coastguard Worker self.assertIsNotNone(runner) 347*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(runner, result_reporter.UNSUPPORTED_FLAG) 348*c2e18aaaSAndroid Build Coastguard Worker 349*c2e18aaaSAndroid Build Coastguard Worker def test_update_stats_passed(self): 350*c2e18aaaSAndroid Build Coastguard Worker """Test _update_stats method.""" 351*c2e18aaaSAndroid Build Coastguard Worker # Passed Test 352*c2e18aaaSAndroid Build Coastguard Worker group = result_reporter.RunStat() 353*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PASSED_TEST, group) 354*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.passed, 1) 355*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.failed, 0) 356*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.run_errors, False) 357*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.failed_tests, []) 358*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.passed, 1) 359*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.failed, 0) 360*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.ignored, 0) 361*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.run_errors, False) 362*c2e18aaaSAndroid Build Coastguard Worker # Passed Test New Group 363*c2e18aaaSAndroid Build Coastguard Worker group2 = result_reporter.RunStat() 364*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PASSED_TEST_MODULE_2, group2) 365*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.passed, 2) 366*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.failed, 0) 367*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.run_errors, False) 368*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.failed_tests, []) 369*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group2.passed, 1) 370*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group2.failed, 0) 371*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.ignored, 0) 372*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group2.run_errors, False) 373*c2e18aaaSAndroid Build Coastguard Worker 374*c2e18aaaSAndroid Build Coastguard Worker def test_update_stats_failed(self): 375*c2e18aaaSAndroid Build Coastguard Worker """Test _update_stats method.""" 376*c2e18aaaSAndroid Build Coastguard Worker # Passed Test 377*c2e18aaaSAndroid Build Coastguard Worker group = result_reporter.RunStat() 378*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PASSED_TEST, group) 379*c2e18aaaSAndroid Build Coastguard Worker # Passed Test New Group 380*c2e18aaaSAndroid Build Coastguard Worker group2 = result_reporter.RunStat() 381*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PASSED_TEST_MODULE_2, group2) 382*c2e18aaaSAndroid Build Coastguard Worker # Failed Test Old Group 383*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_FAILED_TEST, group) 384*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.passed, 2) 385*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.failed, 1) 386*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.run_errors, False) 387*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.failed_tests, [RESULT_FAILED_TEST.test_name]) 388*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.passed, 1) 389*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.failed, 1) 390*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.ignored, 0) 391*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.total, 2) 392*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group2.total, 1) 393*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.run_errors, False) 394*c2e18aaaSAndroid Build Coastguard Worker # Test Run Failure 395*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_RUN_FAILURE, group) 396*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.passed, 2) 397*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.failed, 1) 398*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.run_errors, True) 399*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.failed_tests, [RESULT_FAILED_TEST.test_name]) 400*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.passed, 1) 401*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.failed, 1) 402*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.ignored, 0) 403*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.run_errors, True) 404*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group2.run_errors, False) 405*c2e18aaaSAndroid Build Coastguard Worker # Invocation Failure 406*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_INVOCATION_FAILURE, group) 407*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.passed, 2) 408*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.failed, 1) 409*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.run_errors, True) 410*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.failed_tests, [RESULT_FAILED_TEST.test_name]) 411*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.passed, 1) 412*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.failed, 1) 413*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.ignored, 0) 414*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.run_errors, True) 415*c2e18aaaSAndroid Build Coastguard Worker 416*c2e18aaaSAndroid Build Coastguard Worker def test_update_stats_ignored_and_assumption_failure(self): 417*c2e18aaaSAndroid Build Coastguard Worker """Test _update_stats method.""" 418*c2e18aaaSAndroid Build Coastguard Worker # Passed Test 419*c2e18aaaSAndroid Build Coastguard Worker group = result_reporter.RunStat() 420*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PASSED_TEST, group) 421*c2e18aaaSAndroid Build Coastguard Worker # Passed Test New Group 422*c2e18aaaSAndroid Build Coastguard Worker group2 = result_reporter.RunStat() 423*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PASSED_TEST_MODULE_2, group2) 424*c2e18aaaSAndroid Build Coastguard Worker # Failed Test Old Group 425*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_FAILED_TEST, group) 426*c2e18aaaSAndroid Build Coastguard Worker # Test Run Failure 427*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_RUN_FAILURE, group) 428*c2e18aaaSAndroid Build Coastguard Worker # Invocation Failure 429*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_INVOCATION_FAILURE, group) 430*c2e18aaaSAndroid Build Coastguard Worker # Ignored Test 431*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_IGNORED_TEST, group) 432*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.passed, 2) 433*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.failed, 1) 434*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.run_errors, True) 435*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.failed_tests, [RESULT_FAILED_TEST.test_name]) 436*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.passed, 1) 437*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.failed, 1) 438*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.ignored, 1) 439*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.run_errors, True) 440*c2e18aaaSAndroid Build Coastguard Worker # 2nd Ignored Test 441*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_IGNORED_TEST, group) 442*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.passed, 2) 443*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.failed, 1) 444*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.run_errors, True) 445*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.failed_tests, [RESULT_FAILED_TEST.test_name]) 446*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.passed, 1) 447*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.failed, 1) 448*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.ignored, 2) 449*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.run_errors, True) 450*c2e18aaaSAndroid Build Coastguard Worker 451*c2e18aaaSAndroid Build Coastguard Worker # Assumption_Failure test 452*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_ASSUMPTION_FAILED_TEST, group) 453*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.assumption_failed, 1) 454*c2e18aaaSAndroid Build Coastguard Worker # 2nd Assumption_Failure test 455*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_ASSUMPTION_FAILED_TEST, group) 456*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(group.assumption_failed, 2) 457*c2e18aaaSAndroid Build Coastguard Worker 458*c2e18aaaSAndroid Build Coastguard Worker @patch.object( 459*c2e18aaaSAndroid Build Coastguard Worker atest_configs, 460*c2e18aaaSAndroid Build Coastguard Worker 'GLOBAL_ARGS', 461*c2e18aaaSAndroid Build Coastguard Worker arg_parser.create_atest_arg_parser().parse_args([]), 462*c2e18aaaSAndroid Build Coastguard Worker ) 463*c2e18aaaSAndroid Build Coastguard Worker def test_print_summary_ret_val(self): 464*c2e18aaaSAndroid Build Coastguard Worker """Test print_summary method's return value.""" 465*c2e18aaaSAndroid Build Coastguard Worker # PASS Case 466*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_PASSED_TEST) 467*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(0, self.rr.print_summary()) 468*c2e18aaaSAndroid Build Coastguard Worker # PASS Case + Fail Case 469*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_FAILED_TEST) 470*c2e18aaaSAndroid Build Coastguard Worker self.assertNotEqual(0, self.rr.print_summary()) 471*c2e18aaaSAndroid Build Coastguard Worker # PASS Case + Fail Case + PASS Case 472*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_PASSED_TEST_MODULE_2) 473*c2e18aaaSAndroid Build Coastguard Worker self.assertNotEqual(0, self.rr.print_summary()) 474*c2e18aaaSAndroid Build Coastguard Worker 475*c2e18aaaSAndroid Build Coastguard Worker @patch.object( 476*c2e18aaaSAndroid Build Coastguard Worker atest_configs, 477*c2e18aaaSAndroid Build Coastguard Worker 'GLOBAL_ARGS', 478*c2e18aaaSAndroid Build Coastguard Worker arg_parser.create_atest_arg_parser().parse_args([]), 479*c2e18aaaSAndroid Build Coastguard Worker ) 480*c2e18aaaSAndroid Build Coastguard Worker def test_print_summary_ret_val_err_stat(self): 481*c2e18aaaSAndroid Build Coastguard Worker """Test print_summary method's return value.""" 482*c2e18aaaSAndroid Build Coastguard Worker # PASS Case 483*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_PASSED_TEST) 484*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(0, self.rr.print_summary()) 485*c2e18aaaSAndroid Build Coastguard Worker # PASS Case + Fail Case 486*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_RUN_FAILURE) 487*c2e18aaaSAndroid Build Coastguard Worker self.assertNotEqual(0, self.rr.print_summary()) 488*c2e18aaaSAndroid Build Coastguard Worker # PASS Case + Fail Case + PASS Case 489*c2e18aaaSAndroid Build Coastguard Worker self.rr.process_test_result(RESULT_PASSED_TEST_MODULE_2) 490*c2e18aaaSAndroid Build Coastguard Worker self.assertNotEqual(0, self.rr.print_summary()) 491*c2e18aaaSAndroid Build Coastguard Worker 492*c2e18aaaSAndroid Build Coastguard Worker def test_collect_tests_only_no_throw(self): 493*c2e18aaaSAndroid Build Coastguard Worker rr = result_reporter.ResultReporter(collect_only=True) 494*c2e18aaaSAndroid Build Coastguard Worker rr.process_test_result(RESULT_PASSED_TEST) 495*c2e18aaaSAndroid Build Coastguard Worker 496*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(0, self.rr.print_collect_tests()) 497*c2e18aaaSAndroid Build Coastguard Worker 498*c2e18aaaSAndroid Build Coastguard Worker def test_update_perf_info(self): 499*c2e18aaaSAndroid Build Coastguard Worker """Test update_perf_info method.""" 500*c2e18aaaSAndroid Build Coastguard Worker group = result_reporter.RunStat() 501*c2e18aaaSAndroid Build Coastguard Worker # 1. Test PerfInfo after RESULT_PERF01_TEST01 502*c2e18aaaSAndroid Build Coastguard Worker # _update_stats() will call _update_perf_info() 503*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PERF01_TEST01, group) 504*c2e18aaaSAndroid Build Coastguard Worker correct_perf_info = [] 505*c2e18aaaSAndroid Build Coastguard Worker trim_perf01_test01 = { 506*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 507*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': '10001.10001', 508*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName01', 509*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 510*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 511*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 512*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 513*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 514*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '1001', 515*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName01', 516*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '11001.11001', 517*c2e18aaaSAndroid Build Coastguard Worker 'test_name': 'somePerfClass01#perfName01', 518*c2e18aaaSAndroid Build Coastguard Worker } 519*c2e18aaaSAndroid Build Coastguard Worker correct_perf_info.append(trim_perf01_test01) 520*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.perf_info.perf_info, correct_perf_info) 521*c2e18aaaSAndroid Build Coastguard Worker # 2. Test PerfInfo after RESULT_PERF01_TEST01 522*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PERF01_TEST02, group) 523*c2e18aaaSAndroid Build Coastguard Worker trim_perf01_test02 = { 524*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 525*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': '10002.10002', 526*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName02', 527*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 528*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 529*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 530*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 531*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 532*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '1002', 533*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName02', 534*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '11002.11002', 535*c2e18aaaSAndroid Build Coastguard Worker 'test_name': 'somePerfClass01#perfName02', 536*c2e18aaaSAndroid Build Coastguard Worker } 537*c2e18aaaSAndroid Build Coastguard Worker correct_perf_info.append(trim_perf01_test02) 538*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.perf_info.perf_info, correct_perf_info) 539*c2e18aaaSAndroid Build Coastguard Worker # 3. Test PerfInfo after RESULT_PERF02_TEST01 540*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PERF02_TEST01, group) 541*c2e18aaaSAndroid Build Coastguard Worker trim_perf02_test01 = { 542*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 543*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': '20001.20001', 544*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName11', 545*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 546*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 547*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 548*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 549*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 550*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '2001', 551*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName11', 552*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '21001.21001', 553*c2e18aaaSAndroid Build Coastguard Worker 'test_name': 'somePerfClass02#perfName11', 554*c2e18aaaSAndroid Build Coastguard Worker } 555*c2e18aaaSAndroid Build Coastguard Worker correct_perf_info.append(trim_perf02_test01) 556*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.perf_info.perf_info, correct_perf_info) 557*c2e18aaaSAndroid Build Coastguard Worker # 4. Test PerfInfo after RESULT_PERF01_TEST03_NO_CPU_TIME 558*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PERF01_TEST03_NO_CPU_TIME, group) 559*c2e18aaaSAndroid Build Coastguard Worker # Nothing added since RESULT_PERF01_TEST03_NO_CPU_TIME lack of cpu_time 560*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(self.rr.run_stats.perf_info.perf_info, correct_perf_info) 561*c2e18aaaSAndroid Build Coastguard Worker 562*c2e18aaaSAndroid Build Coastguard Worker def test_classify_perf_info(self): 563*c2e18aaaSAndroid Build Coastguard Worker """Test _classify_perf_info method.""" 564*c2e18aaaSAndroid Build Coastguard Worker group = result_reporter.RunStat() 565*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PERF01_TEST01, group) 566*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PERF01_TEST02, group) 567*c2e18aaaSAndroid Build Coastguard Worker self.rr._update_stats(RESULT_PERF02_TEST01, group) 568*c2e18aaaSAndroid Build Coastguard Worker # trim the time form 10001.10001 to 10001 569*c2e18aaaSAndroid Build Coastguard Worker trim_perf01_test01 = { 570*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 571*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': '10001.10001', 572*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName01', 573*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 574*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 575*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 576*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 577*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 578*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '1001', 579*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName01', 580*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '11001.11001', 581*c2e18aaaSAndroid Build Coastguard Worker 'test_name': 'somePerfClass01#perfName01', 582*c2e18aaaSAndroid Build Coastguard Worker } 583*c2e18aaaSAndroid Build Coastguard Worker trim_perf01_test02 = { 584*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 585*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': '10002.10002', 586*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName02', 587*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 588*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 589*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 590*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 591*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 592*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '1002', 593*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName02', 594*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '11002.11002', 595*c2e18aaaSAndroid Build Coastguard Worker 'test_name': 'somePerfClass01#perfName02', 596*c2e18aaaSAndroid Build Coastguard Worker } 597*c2e18aaaSAndroid Build Coastguard Worker trim_perf02_test01 = { 598*c2e18aaaSAndroid Build Coastguard Worker 'repetition_index': '0', 599*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': '20001.20001', 600*c2e18aaaSAndroid Build Coastguard Worker 'name': 'perfName11', 601*c2e18aaaSAndroid Build Coastguard Worker 'repetitions': '0', 602*c2e18aaaSAndroid Build Coastguard Worker 'run_type': 'iteration', 603*c2e18aaaSAndroid Build Coastguard Worker 'label': '2123', 604*c2e18aaaSAndroid Build Coastguard Worker 'threads': '1', 605*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 'ns', 606*c2e18aaaSAndroid Build Coastguard Worker 'iterations': '2001', 607*c2e18aaaSAndroid Build Coastguard Worker 'run_name': 'perfName11', 608*c2e18aaaSAndroid Build Coastguard Worker 'real_time': '21001.21001', 609*c2e18aaaSAndroid Build Coastguard Worker 'test_name': 'somePerfClass02#perfName11', 610*c2e18aaaSAndroid Build Coastguard Worker } 611*c2e18aaaSAndroid Build Coastguard Worker correct_classify_perf_info = { 612*c2e18aaaSAndroid Build Coastguard Worker 'somePerfClass01': [trim_perf01_test01, trim_perf01_test02], 613*c2e18aaaSAndroid Build Coastguard Worker 'somePerfClass02': [trim_perf02_test01], 614*c2e18aaaSAndroid Build Coastguard Worker } 615*c2e18aaaSAndroid Build Coastguard Worker classify_perf_info, max_len = ( 616*c2e18aaaSAndroid Build Coastguard Worker self.rr.run_stats.perf_info._classify_perf_info() 617*c2e18aaaSAndroid Build Coastguard Worker ) 618*c2e18aaaSAndroid Build Coastguard Worker correct_max_len = { 619*c2e18aaaSAndroid Build Coastguard Worker 'real_time': 11, 620*c2e18aaaSAndroid Build Coastguard Worker 'cpu_time': 11, 621*c2e18aaaSAndroid Build Coastguard Worker 'name': 10, 622*c2e18aaaSAndroid Build Coastguard Worker 'iterations': 9, 623*c2e18aaaSAndroid Build Coastguard Worker 'time_unit': 2, 624*c2e18aaaSAndroid Build Coastguard Worker } 625*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(max_len, correct_max_len) 626*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(classify_perf_info, correct_classify_perf_info) 627*c2e18aaaSAndroid Build Coastguard Worker 628*c2e18aaaSAndroid Build Coastguard Worker def test_print_perf_test_metrics_perf_tests_print_attempted(self): 629*c2e18aaaSAndroid Build Coastguard Worker test_infos = [ 630*c2e18aaaSAndroid Build Coastguard Worker test_info.TestInfo( 631*c2e18aaaSAndroid Build Coastguard Worker 'some_module', 632*c2e18aaaSAndroid Build Coastguard Worker 'TestRunner', 633*c2e18aaaSAndroid Build Coastguard Worker set(), 634*c2e18aaaSAndroid Build Coastguard Worker compatibility_suites=['performance-tests'], 635*c2e18aaaSAndroid Build Coastguard Worker ) 636*c2e18aaaSAndroid Build Coastguard Worker ] 637*c2e18aaaSAndroid Build Coastguard Worker sut = result_reporter.ResultReporter(test_infos=test_infos) 638*c2e18aaaSAndroid Build Coastguard Worker 639*c2e18aaaSAndroid Build Coastguard Worker is_print_attempted = sut._print_perf_test_metrics() 640*c2e18aaaSAndroid Build Coastguard Worker 641*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(is_print_attempted) 642*c2e18aaaSAndroid Build Coastguard Worker 643*c2e18aaaSAndroid Build Coastguard Worker def test_print_perf_test_metrics_not_perf_tests_print__not_attempted(self): 644*c2e18aaaSAndroid Build Coastguard Worker test_infos = [ 645*c2e18aaaSAndroid Build Coastguard Worker test_info.TestInfo( 646*c2e18aaaSAndroid Build Coastguard Worker 'some_module', 647*c2e18aaaSAndroid Build Coastguard Worker 'TestRunner', 648*c2e18aaaSAndroid Build Coastguard Worker set(), 649*c2e18aaaSAndroid Build Coastguard Worker compatibility_suites=['not-perf-test'], 650*c2e18aaaSAndroid Build Coastguard Worker ) 651*c2e18aaaSAndroid Build Coastguard Worker ] 652*c2e18aaaSAndroid Build Coastguard Worker sut = result_reporter.ResultReporter(test_infos=test_infos) 653*c2e18aaaSAndroid Build Coastguard Worker 654*c2e18aaaSAndroid Build Coastguard Worker is_print_attempted = sut._print_perf_test_metrics() 655*c2e18aaaSAndroid Build Coastguard Worker 656*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(is_print_attempted) 657*c2e18aaaSAndroid Build Coastguard Worker 658*c2e18aaaSAndroid Build Coastguard Worker 659*c2e18aaaSAndroid Build Coastguard Workerif __name__ == '__main__': 660*c2e18aaaSAndroid Build Coastguard Worker unittest.main() 661