1*c2e18aaaSAndroid Build Coastguard Worker#!/usr/bin/env python3 2*c2e18aaaSAndroid Build Coastguard Worker# 3*c2e18aaaSAndroid Build Coastguard Worker# Copyright 2024, 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"""Unit tests for coverage.""" 18*c2e18aaaSAndroid Build Coastguard Worker 19*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=invalid-name 20*c2e18aaaSAndroid Build Coastguard Worker 21*c2e18aaaSAndroid Build Coastguard Workerfrom pathlib import PosixPath 22*c2e18aaaSAndroid Build Coastguard Workerimport unittest 23*c2e18aaaSAndroid Build Coastguard Workerfrom unittest import mock 24*c2e18aaaSAndroid Build Coastguard Workerfrom atest import atest_utils 25*c2e18aaaSAndroid Build Coastguard Workerfrom atest import constants 26*c2e18aaaSAndroid Build Coastguard Workerfrom atest import module_info 27*c2e18aaaSAndroid Build Coastguard Workerfrom atest.coverage import coverage 28*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import test_info 29*c2e18aaaSAndroid Build Coastguard Worker 30*c2e18aaaSAndroid Build Coastguard Worker 31*c2e18aaaSAndroid Build Coastguard Workerclass DeduceCodeUnderTestUnittests(unittest.TestCase): 32*c2e18aaaSAndroid Build Coastguard Worker """Tests for _deduce_code_under_test.""" 33*c2e18aaaSAndroid Build Coastguard Worker 34*c2e18aaaSAndroid Build Coastguard Worker def test_code_under_test_is_defined_return_modules_in_code_under_test(self): 35*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 36*c2e18aaaSAndroid Build Coastguard Worker module( 37*c2e18aaaSAndroid Build Coastguard Worker name='test1', 38*c2e18aaaSAndroid Build Coastguard Worker dependencies=['dep1', 'dep2'], 39*c2e18aaaSAndroid Build Coastguard Worker code_under_test=['dep1'], 40*c2e18aaaSAndroid Build Coastguard Worker ), 41*c2e18aaaSAndroid Build Coastguard Worker module(name='dep1', dependencies=['dep1dep1', 'dep1dep2']), 42*c2e18aaaSAndroid Build Coastguard Worker module(name='dep1dep1'), 43*c2e18aaaSAndroid Build Coastguard Worker module(name='dep1dep2', dependencies=['dep1dep2dep']), 44*c2e18aaaSAndroid Build Coastguard Worker module(name='dep1dep2dep'), 45*c2e18aaaSAndroid Build Coastguard Worker module(name='dep2'), 46*c2e18aaaSAndroid Build Coastguard Worker ]) 47*c2e18aaaSAndroid Build Coastguard Worker 48*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 49*c2e18aaaSAndroid Build Coastguard Worker coverage._deduce_code_under_test([create_test_info('test1')], mod_info), 50*c2e18aaaSAndroid Build Coastguard Worker {'dep1'}, 51*c2e18aaaSAndroid Build Coastguard Worker ) 52*c2e18aaaSAndroid Build Coastguard Worker 53*c2e18aaaSAndroid Build Coastguard Worker def test_code_under_test_not_defined_return_all_modules_from_one_test(self): 54*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 55*c2e18aaaSAndroid Build Coastguard Worker module(name='test1', dependencies=['dep1', 'dep2']), 56*c2e18aaaSAndroid Build Coastguard Worker module(name='dep1', dependencies=['dep1dep1', 'dep1dep2']), 57*c2e18aaaSAndroid Build Coastguard Worker module(name='dep1dep1'), 58*c2e18aaaSAndroid Build Coastguard Worker module(name='dep1dep2', dependencies=['dep1dep2dep']), 59*c2e18aaaSAndroid Build Coastguard Worker module(name='dep1dep2dep'), 60*c2e18aaaSAndroid Build Coastguard Worker module(name='dep2'), 61*c2e18aaaSAndroid Build Coastguard Worker module(name='shouldnotappear'), 62*c2e18aaaSAndroid Build Coastguard Worker ]) 63*c2e18aaaSAndroid Build Coastguard Worker 64*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 65*c2e18aaaSAndroid Build Coastguard Worker coverage._deduce_code_under_test([create_test_info('test1')], mod_info), 66*c2e18aaaSAndroid Build Coastguard Worker { 67*c2e18aaaSAndroid Build Coastguard Worker 'test1', 68*c2e18aaaSAndroid Build Coastguard Worker 'dep1', 69*c2e18aaaSAndroid Build Coastguard Worker 'dep2', 70*c2e18aaaSAndroid Build Coastguard Worker 'dep1dep1', 71*c2e18aaaSAndroid Build Coastguard Worker 'dep1dep2', 72*c2e18aaaSAndroid Build Coastguard Worker 'dep1dep2dep', 73*c2e18aaaSAndroid Build Coastguard Worker }, 74*c2e18aaaSAndroid Build Coastguard Worker ) 75*c2e18aaaSAndroid Build Coastguard Worker 76*c2e18aaaSAndroid Build Coastguard Worker def test_code_under_test_not_defined_return_all_modules_from_all_tests(self): 77*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 78*c2e18aaaSAndroid Build Coastguard Worker module(name='test1', dependencies=['testlib', 'test1dep']), 79*c2e18aaaSAndroid Build Coastguard Worker module(name='test2', dependencies=['testlib', 'test2dep']), 80*c2e18aaaSAndroid Build Coastguard Worker module(name='testlib', dependencies=['testlibdep']), 81*c2e18aaaSAndroid Build Coastguard Worker module(name='testlibdep'), 82*c2e18aaaSAndroid Build Coastguard Worker module(name='test1dep'), 83*c2e18aaaSAndroid Build Coastguard Worker module(name='test2dep'), 84*c2e18aaaSAndroid Build Coastguard Worker module(name='shouldnotappear'), 85*c2e18aaaSAndroid Build Coastguard Worker ]) 86*c2e18aaaSAndroid Build Coastguard Worker 87*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 88*c2e18aaaSAndroid Build Coastguard Worker coverage._deduce_code_under_test( 89*c2e18aaaSAndroid Build Coastguard Worker [create_test_info('test1'), create_test_info('test2')], mod_info 90*c2e18aaaSAndroid Build Coastguard Worker ), 91*c2e18aaaSAndroid Build Coastguard Worker {'test1', 'test2', 'testlib', 'testlibdep', 'test1dep', 'test2dep'}, 92*c2e18aaaSAndroid Build Coastguard Worker ) 93*c2e18aaaSAndroid Build Coastguard Worker 94*c2e18aaaSAndroid Build Coastguard Worker 95*c2e18aaaSAndroid Build Coastguard Workerclass CollectJavaReportJarsUnittests(unittest.TestCase): 96*c2e18aaaSAndroid Build Coastguard Worker """Test cases for _collect_java_report_jars.""" 97*c2e18aaaSAndroid Build Coastguard Worker 98*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object( 99*c2e18aaaSAndroid Build Coastguard Worker atest_utils, 100*c2e18aaaSAndroid Build Coastguard Worker 'get_build_out_dir', 101*c2e18aaaSAndroid Build Coastguard Worker return_value=PosixPath('/out/soong/.intermediates'), 102*c2e18aaaSAndroid Build Coastguard Worker ) 103*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object( 104*c2e18aaaSAndroid Build Coastguard Worker PosixPath, 105*c2e18aaaSAndroid Build Coastguard Worker 'rglob', 106*c2e18aaaSAndroid Build Coastguard Worker return_value=[ 107*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/java_lib/variant-name/jacoco-report-classes/java_lib.jar' 108*c2e18aaaSAndroid Build Coastguard Worker ], 109*c2e18aaaSAndroid Build Coastguard Worker ) 110*c2e18aaaSAndroid Build Coastguard Worker def test_java_lib(self, _rglob, _get_build_out_dir): 111*c2e18aaaSAndroid Build Coastguard Worker code_under_test = {'java_lib'} 112*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 113*c2e18aaaSAndroid Build Coastguard Worker module(name='java_lib', path='path/to'), 114*c2e18aaaSAndroid Build Coastguard Worker ]) 115*c2e18aaaSAndroid Build Coastguard Worker 116*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 117*c2e18aaaSAndroid Build Coastguard Worker coverage._collect_java_report_jars(code_under_test, mod_info, False), 118*c2e18aaaSAndroid Build Coastguard Worker { 119*c2e18aaaSAndroid Build Coastguard Worker 'java_lib': [ 120*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/java_lib/variant-name/jacoco-report-classes/java_lib.jar' 121*c2e18aaaSAndroid Build Coastguard Worker ] 122*c2e18aaaSAndroid Build Coastguard Worker }, 123*c2e18aaaSAndroid Build Coastguard Worker ) 124*c2e18aaaSAndroid Build Coastguard Worker 125*c2e18aaaSAndroid Build Coastguard Worker def test_host_test_includes_installed(self): 126*c2e18aaaSAndroid Build Coastguard Worker code_under_test = {'java_host_test'} 127*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 128*c2e18aaaSAndroid Build Coastguard Worker module( 129*c2e18aaaSAndroid Build Coastguard Worker name='java_host_test', 130*c2e18aaaSAndroid Build Coastguard Worker installed=[ 131*c2e18aaaSAndroid Build Coastguard Worker '/path/to/out/host/java_host_test.jar', 132*c2e18aaaSAndroid Build Coastguard Worker '/path/to/out/host/java_host_test.config', 133*c2e18aaaSAndroid Build Coastguard Worker ], 134*c2e18aaaSAndroid Build Coastguard Worker ), 135*c2e18aaaSAndroid Build Coastguard Worker ]) 136*c2e18aaaSAndroid Build Coastguard Worker 137*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 138*c2e18aaaSAndroid Build Coastguard Worker coverage._collect_java_report_jars(code_under_test, mod_info, True), 139*c2e18aaaSAndroid Build Coastguard Worker {'java_host_test': ['/path/to/out/host/java_host_test.jar']}, 140*c2e18aaaSAndroid Build Coastguard Worker ) 141*c2e18aaaSAndroid Build Coastguard Worker 142*c2e18aaaSAndroid Build Coastguard Worker 143*c2e18aaaSAndroid Build Coastguard Workerclass CollectNativeReportBinariesUnittests(unittest.TestCase): 144*c2e18aaaSAndroid Build Coastguard Worker """Test cases for _collect_native_report_binaries.""" 145*c2e18aaaSAndroid Build Coastguard Worker 146*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object( 147*c2e18aaaSAndroid Build Coastguard Worker atest_utils, 148*c2e18aaaSAndroid Build Coastguard Worker 'get_build_out_dir', 149*c2e18aaaSAndroid Build Coastguard Worker return_value=PosixPath('/out/soong/.intermediates'), 150*c2e18aaaSAndroid Build Coastguard Worker ) 151*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(PosixPath, 'glob') 152*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object( 153*c2e18aaaSAndroid Build Coastguard Worker coverage, 154*c2e18aaaSAndroid Build Coastguard Worker '_strip_irrelevant_objects', 155*c2e18aaaSAndroid Build Coastguard Worker return_value={ 156*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/native_bin/variant-name-cov/unstripped/native_bin' 157*c2e18aaaSAndroid Build Coastguard Worker }, 158*c2e18aaaSAndroid Build Coastguard Worker ) 159*c2e18aaaSAndroid Build Coastguard Worker def test_native_binary(self, _strip_irrelevant_objects, _glob, _get_build_out_dir): 160*c2e18aaaSAndroid Build Coastguard Worker _glob.return_value = [ 161*c2e18aaaSAndroid Build Coastguard Worker PosixPath( 162*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/native_bin/variant-name-cov/unstripped/native_bin' 163*c2e18aaaSAndroid Build Coastguard Worker ) 164*c2e18aaaSAndroid Build Coastguard Worker ] 165*c2e18aaaSAndroid Build Coastguard Worker code_under_test = {'native_bin'} 166*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 167*c2e18aaaSAndroid Build Coastguard Worker module(name='native_bin', path='path/to'), 168*c2e18aaaSAndroid Build Coastguard Worker ]) 169*c2e18aaaSAndroid Build Coastguard Worker 170*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 171*c2e18aaaSAndroid Build Coastguard Worker coverage._collect_native_report_binaries( 172*c2e18aaaSAndroid Build Coastguard Worker code_under_test, mod_info, False 173*c2e18aaaSAndroid Build Coastguard Worker ), 174*c2e18aaaSAndroid Build Coastguard Worker { 175*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/native_bin/variant-name-cov/unstripped/native_bin' 176*c2e18aaaSAndroid Build Coastguard Worker }, 177*c2e18aaaSAndroid Build Coastguard Worker ) 178*c2e18aaaSAndroid Build Coastguard Worker 179*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object( 180*c2e18aaaSAndroid Build Coastguard Worker atest_utils, 181*c2e18aaaSAndroid Build Coastguard Worker 'get_build_out_dir', 182*c2e18aaaSAndroid Build Coastguard Worker return_value=PosixPath('/out/soong/.intermediates'), 183*c2e18aaaSAndroid Build Coastguard Worker ) 184*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(PosixPath, 'glob') 185*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object( 186*c2e18aaaSAndroid Build Coastguard Worker coverage, 187*c2e18aaaSAndroid Build Coastguard Worker '_strip_irrelevant_objects', 188*c2e18aaaSAndroid Build Coastguard Worker return_value={ 189*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/native_bin/variant-name-cov/unstripped/native_bin' 190*c2e18aaaSAndroid Build Coastguard Worker }, 191*c2e18aaaSAndroid Build Coastguard Worker ) 192*c2e18aaaSAndroid Build Coastguard Worker def test_skip_rsp_and_d_and_toc_files(self, _strip_irrelevant_objects, _glob, _get_build_out_dir): 193*c2e18aaaSAndroid Build Coastguard Worker _glob.return_value = [ 194*c2e18aaaSAndroid Build Coastguard Worker PosixPath( 195*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/native_bin/variant-name-cov/unstripped/native_bin' 196*c2e18aaaSAndroid Build Coastguard Worker ), 197*c2e18aaaSAndroid Build Coastguard Worker PosixPath( 198*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/native_bin/variant-name-cov/unstripped/native_bin.rsp' 199*c2e18aaaSAndroid Build Coastguard Worker ), 200*c2e18aaaSAndroid Build Coastguard Worker PosixPath( 201*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/native_bin/variant-name-cov/unstripped/native_bin.d' 202*c2e18aaaSAndroid Build Coastguard Worker ), 203*c2e18aaaSAndroid Build Coastguard Worker PosixPath( 204*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/native_bin/variant-name-cov/unstripped/native_bin.toc' 205*c2e18aaaSAndroid Build Coastguard Worker ), 206*c2e18aaaSAndroid Build Coastguard Worker ] 207*c2e18aaaSAndroid Build Coastguard Worker code_under_test = {'native_bin'} 208*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 209*c2e18aaaSAndroid Build Coastguard Worker module(name='native_bin', path='path/to'), 210*c2e18aaaSAndroid Build Coastguard Worker ]) 211*c2e18aaaSAndroid Build Coastguard Worker 212*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 213*c2e18aaaSAndroid Build Coastguard Worker coverage._collect_native_report_binaries( 214*c2e18aaaSAndroid Build Coastguard Worker code_under_test, mod_info, False 215*c2e18aaaSAndroid Build Coastguard Worker ), 216*c2e18aaaSAndroid Build Coastguard Worker { 217*c2e18aaaSAndroid Build Coastguard Worker '/out/soong/.intermediates/path/to/native_bin/variant-name-cov/unstripped/native_bin' 218*c2e18aaaSAndroid Build Coastguard Worker }, 219*c2e18aaaSAndroid Build Coastguard Worker ) 220*c2e18aaaSAndroid Build Coastguard Worker 221*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object( 222*c2e18aaaSAndroid Build Coastguard Worker coverage, 223*c2e18aaaSAndroid Build Coastguard Worker '_strip_irrelevant_objects', 224*c2e18aaaSAndroid Build Coastguard Worker return_value={ 225*c2e18aaaSAndroid Build Coastguard Worker '/out/host/nativetests/native_host_test' 226*c2e18aaaSAndroid Build Coastguard Worker }, 227*c2e18aaaSAndroid Build Coastguard Worker ) 228*c2e18aaaSAndroid Build Coastguard Worker def test_host_test_includes_installed(self, _strip_irrelevant_objects): 229*c2e18aaaSAndroid Build Coastguard Worker code_under_test = {'native_host_test'} 230*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 231*c2e18aaaSAndroid Build Coastguard Worker module( 232*c2e18aaaSAndroid Build Coastguard Worker name='native_host_test', 233*c2e18aaaSAndroid Build Coastguard Worker installed=['/out/host/nativetests/native_host_test'], 234*c2e18aaaSAndroid Build Coastguard Worker classes=[constants.MODULE_CLASS_NATIVE_TESTS], 235*c2e18aaaSAndroid Build Coastguard Worker ), 236*c2e18aaaSAndroid Build Coastguard Worker ]) 237*c2e18aaaSAndroid Build Coastguard Worker 238*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 239*c2e18aaaSAndroid Build Coastguard Worker coverage._collect_native_report_binaries( 240*c2e18aaaSAndroid Build Coastguard Worker code_under_test, mod_info, True 241*c2e18aaaSAndroid Build Coastguard Worker ), 242*c2e18aaaSAndroid Build Coastguard Worker {'/out/host/nativetests/native_host_test'}, 243*c2e18aaaSAndroid Build Coastguard Worker ) 244*c2e18aaaSAndroid Build Coastguard Worker 245*c2e18aaaSAndroid Build Coastguard Worker 246*c2e18aaaSAndroid Build Coastguard Workerclass GenerateCoverageReportUnittests(unittest.TestCase): 247*c2e18aaaSAndroid Build Coastguard Worker """Tests for the code-under-test feature.""" 248*c2e18aaaSAndroid Build Coastguard Worker 249*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(coverage, '_collect_java_report_jars', return_value={}) 250*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object( 251*c2e18aaaSAndroid Build Coastguard Worker coverage, '_collect_native_report_binaries', return_value=set() 252*c2e18aaaSAndroid Build Coastguard Worker ) 253*c2e18aaaSAndroid Build Coastguard Worker def test_generate_report_for_code_under_test_passed_in_from_atest( 254*c2e18aaaSAndroid Build Coastguard Worker self, _collect_native, _collect_java 255*c2e18aaaSAndroid Build Coastguard Worker ): 256*c2e18aaaSAndroid Build Coastguard Worker test_infos = [create_test_info('test')] 257*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 258*c2e18aaaSAndroid Build Coastguard Worker module(name='test', dependencies=['lib1', 'lib2']), 259*c2e18aaaSAndroid Build Coastguard Worker module(name='lib1'), 260*c2e18aaaSAndroid Build Coastguard Worker module(name='lib2', dependencies=['lib2dep']), 261*c2e18aaaSAndroid Build Coastguard Worker module(name='lib2dep'), 262*c2e18aaaSAndroid Build Coastguard Worker ]) 263*c2e18aaaSAndroid Build Coastguard Worker code_under_test = ['lib1', 'lib2'] 264*c2e18aaaSAndroid Build Coastguard Worker 265*c2e18aaaSAndroid Build Coastguard Worker coverage.generate_coverage_report( 266*c2e18aaaSAndroid Build Coastguard Worker '/tmp/results_dir', test_infos, mod_info, True, code_under_test 267*c2e18aaaSAndroid Build Coastguard Worker ) 268*c2e18aaaSAndroid Build Coastguard Worker 269*c2e18aaaSAndroid Build Coastguard Worker _collect_java.assert_called_with(code_under_test, mod_info, True) 270*c2e18aaaSAndroid Build Coastguard Worker _collect_native.assert_called_with(code_under_test, mod_info, True) 271*c2e18aaaSAndroid Build Coastguard Worker 272*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(coverage, '_collect_java_report_jars', return_value={}) 273*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object( 274*c2e18aaaSAndroid Build Coastguard Worker coverage, '_collect_native_report_binaries', return_value=set() 275*c2e18aaaSAndroid Build Coastguard Worker ) 276*c2e18aaaSAndroid Build Coastguard Worker def test_generate_report_for_modules_get_from_deduce_code_under_test( 277*c2e18aaaSAndroid Build Coastguard Worker self, _collect_native, _collect_java 278*c2e18aaaSAndroid Build Coastguard Worker ): 279*c2e18aaaSAndroid Build Coastguard Worker test_infos = [create_test_info('test')] 280*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 281*c2e18aaaSAndroid Build Coastguard Worker module(name='test', dependencies=['lib1', 'lib2']), 282*c2e18aaaSAndroid Build Coastguard Worker module(name='lib1'), 283*c2e18aaaSAndroid Build Coastguard Worker module(name='lib2', dependencies=['lib2dep']), 284*c2e18aaaSAndroid Build Coastguard Worker module(name='lib2dep'), 285*c2e18aaaSAndroid Build Coastguard Worker module(name='not_a_dep'), 286*c2e18aaaSAndroid Build Coastguard Worker ]) 287*c2e18aaaSAndroid Build Coastguard Worker 288*c2e18aaaSAndroid Build Coastguard Worker coverage.generate_coverage_report( 289*c2e18aaaSAndroid Build Coastguard Worker '/tmp/results_dir', test_infos, mod_info, False, [] 290*c2e18aaaSAndroid Build Coastguard Worker ) 291*c2e18aaaSAndroid Build Coastguard Worker 292*c2e18aaaSAndroid Build Coastguard Worker expected_code_under_test = {'test', 'lib1', 'lib2', 'lib2dep'} 293*c2e18aaaSAndroid Build Coastguard Worker _collect_java.assert_called_with(expected_code_under_test, mod_info, False) 294*c2e18aaaSAndroid Build Coastguard Worker _collect_native.assert_called_with( 295*c2e18aaaSAndroid Build Coastguard Worker expected_code_under_test, mod_info, False 296*c2e18aaaSAndroid Build Coastguard Worker ) 297*c2e18aaaSAndroid Build Coastguard Worker 298*c2e18aaaSAndroid Build Coastguard Worker 299*c2e18aaaSAndroid Build Coastguard Workerdef create_module_info(modules=None): 300*c2e18aaaSAndroid Build Coastguard Worker """Wrapper function for creating module_info.ModuleInfo.""" 301*c2e18aaaSAndroid Build Coastguard Worker name_to_module_info = {} 302*c2e18aaaSAndroid Build Coastguard Worker modules = modules or [] 303*c2e18aaaSAndroid Build Coastguard Worker 304*c2e18aaaSAndroid Build Coastguard Worker for m in modules: 305*c2e18aaaSAndroid Build Coastguard Worker name_to_module_info[m['module_name']] = m 306*c2e18aaaSAndroid Build Coastguard Worker 307*c2e18aaaSAndroid Build Coastguard Worker return module_info.load_from_dict(name_to_module_info) 308*c2e18aaaSAndroid Build Coastguard Worker 309*c2e18aaaSAndroid Build Coastguard Worker 310*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=too-many-arguments 311*c2e18aaaSAndroid Build Coastguard Workerdef module( 312*c2e18aaaSAndroid Build Coastguard Worker name=None, 313*c2e18aaaSAndroid Build Coastguard Worker path=None, 314*c2e18aaaSAndroid Build Coastguard Worker installed=None, 315*c2e18aaaSAndroid Build Coastguard Worker classes=None, 316*c2e18aaaSAndroid Build Coastguard Worker auto_test_config=None, 317*c2e18aaaSAndroid Build Coastguard Worker test_config=None, 318*c2e18aaaSAndroid Build Coastguard Worker shared_libs=None, 319*c2e18aaaSAndroid Build Coastguard Worker dependencies=None, 320*c2e18aaaSAndroid Build Coastguard Worker runtime_dependencies=None, 321*c2e18aaaSAndroid Build Coastguard Worker data=None, 322*c2e18aaaSAndroid Build Coastguard Worker data_dependencies=None, 323*c2e18aaaSAndroid Build Coastguard Worker compatibility_suites=None, 324*c2e18aaaSAndroid Build Coastguard Worker host_dependencies=None, 325*c2e18aaaSAndroid Build Coastguard Worker srcs=None, 326*c2e18aaaSAndroid Build Coastguard Worker supported_variants=None, 327*c2e18aaaSAndroid Build Coastguard Worker code_under_test=None, 328*c2e18aaaSAndroid Build Coastguard Worker): 329*c2e18aaaSAndroid Build Coastguard Worker name = name or 'libhello' 330*c2e18aaaSAndroid Build Coastguard Worker 331*c2e18aaaSAndroid Build Coastguard Worker m = {} 332*c2e18aaaSAndroid Build Coastguard Worker 333*c2e18aaaSAndroid Build Coastguard Worker m['module_name'] = name 334*c2e18aaaSAndroid Build Coastguard Worker m['class'] = classes or [] 335*c2e18aaaSAndroid Build Coastguard Worker m['path'] = [path or ''] 336*c2e18aaaSAndroid Build Coastguard Worker m['installed'] = installed or [] 337*c2e18aaaSAndroid Build Coastguard Worker m['is_unit_test'] = 'false' 338*c2e18aaaSAndroid Build Coastguard Worker m['auto_test_config'] = auto_test_config or [] 339*c2e18aaaSAndroid Build Coastguard Worker m['test_config'] = test_config or [] 340*c2e18aaaSAndroid Build Coastguard Worker m['shared_libs'] = shared_libs or [] 341*c2e18aaaSAndroid Build Coastguard Worker m['runtime_dependencies'] = runtime_dependencies or [] 342*c2e18aaaSAndroid Build Coastguard Worker m['dependencies'] = dependencies or [] 343*c2e18aaaSAndroid Build Coastguard Worker m['data'] = data or [] 344*c2e18aaaSAndroid Build Coastguard Worker m['data_dependencies'] = data_dependencies or [] 345*c2e18aaaSAndroid Build Coastguard Worker m['compatibility_suites'] = compatibility_suites or [] 346*c2e18aaaSAndroid Build Coastguard Worker m['host_dependencies'] = host_dependencies or [] 347*c2e18aaaSAndroid Build Coastguard Worker m['srcs'] = srcs or [] 348*c2e18aaaSAndroid Build Coastguard Worker m['supported_variants'] = supported_variants or [] 349*c2e18aaaSAndroid Build Coastguard Worker m['code_under_test'] = code_under_test or [] 350*c2e18aaaSAndroid Build Coastguard Worker return m 351*c2e18aaaSAndroid Build Coastguard Worker 352*c2e18aaaSAndroid Build Coastguard Worker 353*c2e18aaaSAndroid Build Coastguard Workerdef create_test_info(name='HelloWorldTest'): 354*c2e18aaaSAndroid Build Coastguard Worker """Helper function for creating test_info.TestInfo.""" 355*c2e18aaaSAndroid Build Coastguard Worker return test_info.TestInfo(name, 'AtestTradefedRunner', set()) 356*c2e18aaaSAndroid Build Coastguard Worker 357*c2e18aaaSAndroid Build Coastguard Worker 358*c2e18aaaSAndroid Build Coastguard Workerif __name__ == '__main__': 359*c2e18aaaSAndroid Build Coastguard Worker unittest.main() 360