1#!/usr/bin/env python3 2# 3# Copyright 2018, The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17"""Unittests for module_info.""" 18 19# pylint: disable=line-too-long 20 21import os 22import unittest 23 24from unittest import mock 25 26import atest_utils 27import constants 28import module_info 29import unittest_utils 30import unittest_constants as uc 31 32JSON_FILE_PATH = os.path.join(uc.TEST_DATA_DIR, uc.JSON_FILE) 33EXPECTED_MOD_TARGET = 'tradefed' 34EXPECTED_MOD_TARGET_PATH = ['tf/core'] 35UNEXPECTED_MOD_TARGET = 'this_should_not_be_in_module-info.json' 36MOD_NO_PATH = 'module-no-path' 37PATH_TO_MULT_MODULES = 'shared/path/to/be/used' 38MULT_MOODULES_WITH_SHARED_PATH = ['module2', 'module1'] 39PATH_TO_MULT_MODULES_WITH_MULTI_ARCH = 'shared/path/to/be/used2' 40TESTABLE_MODULES_WITH_SHARED_PATH = ['multiarch1', 'multiarch2', 'multiarch3', 'multiarch3_32'] 41 42ROBO_MOD_PATH = ['/shared/robo/path'] 43NON_RUN_ROBO_MOD_NAME = 'robo_mod' 44RUN_ROBO_MOD_NAME = 'run_robo_mod' 45NON_RUN_ROBO_MOD = {constants.MODULE_NAME: NON_RUN_ROBO_MOD_NAME, 46 constants.MODULE_PATH: ROBO_MOD_PATH, 47 constants.MODULE_CLASS: ['random_class']} 48RUN_ROBO_MOD = {constants.MODULE_NAME: RUN_ROBO_MOD_NAME, 49 constants.MODULE_PATH: ROBO_MOD_PATH, 50 constants.MODULE_CLASS: [constants.MODULE_CLASS_ROBOLECTRIC]} 51MOD_PATH_INFO_DICT = {ROBO_MOD_PATH[0]: [RUN_ROBO_MOD, NON_RUN_ROBO_MOD]} 52MOD_NAME_INFO_DICT = { 53 RUN_ROBO_MOD_NAME: RUN_ROBO_MOD, 54 NON_RUN_ROBO_MOD_NAME: NON_RUN_ROBO_MOD} 55MOD_NAME1 = 'mod1' 56MOD_NAME2 = 'mod2' 57MOD_NAME3 = 'mod3' 58MOD_NAME4 = 'mod4' 59MOD_INFO_DICT = {} 60MODULE_INFO = {constants.MODULE_NAME: 'random_name', 61 constants.MODULE_PATH: 'a/b/c/path', 62 constants.MODULE_CLASS: ['random_class']} 63NAME_TO_MODULE_INFO = {'random_name' : MODULE_INFO} 64MERGED_DEP = '/tmp/out/atest_merged_dep.json' 65 66#pylint: disable=protected-access 67class ModuleInfoUnittests(unittest.TestCase): 68 """Unit tests for module_info.py""" 69 70 def tearDown(self): 71 if os.path.isfile(MERGED_DEP): 72 os.remove(MERGED_DEP) 73 74 @mock.patch.object(module_info.ModuleInfo, '_merge_soong_info') 75 @mock.patch('json.load', return_value={}) 76 @mock.patch('builtins.open', new_callable=mock.mock_open) 77 @mock.patch('os.path.isfile', return_value=True) 78 def test_load_mode_info_file_out_dir_handling(self, _isfile, _open, _json, 79 _merge): 80 """Test _load_module_info_file out dir handling.""" 81 # Test out default out dir is used. 82 build_top = '/path/to/top' 83 default_out_dir = os.path.join(build_top, 'out/dir/here') 84 os_environ_mock = {'ANDROID_PRODUCT_OUT': default_out_dir, 85 constants.ANDROID_BUILD_TOP: build_top} 86 default_out_dir_mod_targ = 'out/dir/here/module-info.json' 87 # Make sure module_info_target is what we think it is. 88 with mock.patch.dict('os.environ', os_environ_mock, clear=True): 89 mod_info = module_info.ModuleInfo() 90 self.assertEqual(default_out_dir_mod_targ, 91 mod_info.module_info_target) 92 93 # Test out custom out dir is used (OUT_DIR=dir2). 94 custom_out_dir = os.path.join(build_top, 'out2/dir/here') 95 os_environ_mock = {'ANDROID_PRODUCT_OUT': custom_out_dir, 96 constants.ANDROID_BUILD_TOP: build_top} 97 custom_out_dir_mod_targ = 'out2/dir/here/module-info.json' 98 # Make sure module_info_target is what we think it is. 99 with mock.patch.dict('os.environ', os_environ_mock, clear=True): 100 mod_info = module_info.ModuleInfo() 101 self.assertEqual(custom_out_dir_mod_targ, 102 mod_info.module_info_target) 103 104 # Test out custom abs out dir is used (OUT_DIR=/tmp/out/dir2). 105 abs_custom_out_dir = '/tmp/out/dir' 106 os_environ_mock = {'ANDROID_PRODUCT_OUT': abs_custom_out_dir, 107 constants.ANDROID_BUILD_TOP: build_top} 108 custom_abs_out_dir_mod_targ = '/tmp/out/dir/module-info.json' 109 # Make sure module_info_target is what we think it is. 110 with mock.patch.dict('os.environ', os_environ_mock, clear=True): 111 mod_info = module_info.ModuleInfo() 112 self.assertEqual(custom_abs_out_dir_mod_targ, 113 mod_info.module_info_target) 114 115 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 116 @mock.patch.object(module_info.ModuleInfo, '_load_module_info_file') 117 def test_get_path_to_module_info(self, mock_load_module): 118 """Test that we correctly create the path to module info dict.""" 119 mod_one = 'mod1' 120 mod_two = 'mod2' 121 mod_path_one = '/path/to/mod1' 122 mod_path_two = '/path/to/mod2' 123 mod_info_dict = {mod_one: {constants.MODULE_PATH: [mod_path_one], 124 constants.MODULE_NAME: mod_one}, 125 mod_two: {constants.MODULE_PATH: [mod_path_two], 126 constants.MODULE_NAME: mod_two}} 127 mock_load_module.return_value = ('mod_target', mod_info_dict) 128 path_to_mod_info = {mod_path_one: [{constants.MODULE_NAME: mod_one, 129 constants.MODULE_PATH: [mod_path_one]}], 130 mod_path_two: [{constants.MODULE_NAME: mod_two, 131 constants.MODULE_PATH: [mod_path_two]}]} 132 mod_info = module_info.ModuleInfo() 133 self.assertDictEqual(path_to_mod_info, 134 mod_info._get_path_to_module_info(mod_info_dict)) 135 136 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 137 def test_is_module(self): 138 """Test that we get the module when it's properly loaded.""" 139 # Load up the test json file and check that module is in it 140 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 141 self.assertTrue(mod_info.is_module(EXPECTED_MOD_TARGET)) 142 self.assertFalse(mod_info.is_module(UNEXPECTED_MOD_TARGET)) 143 144 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 145 def test_get_path(self): 146 """Test that we get the module path when it's properly loaded.""" 147 # Load up the test json file and check that module is in it 148 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 149 self.assertEqual(mod_info.get_paths(EXPECTED_MOD_TARGET), 150 EXPECTED_MOD_TARGET_PATH) 151 self.assertEqual(mod_info.get_paths(MOD_NO_PATH), []) 152 153 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 154 def test_get_module_names(self): 155 """test that we get the module name properly.""" 156 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 157 self.assertEqual(mod_info.get_module_names(EXPECTED_MOD_TARGET_PATH[0]), 158 [EXPECTED_MOD_TARGET]) 159 unittest_utils.assert_strict_equal( 160 self, mod_info.get_module_names(PATH_TO_MULT_MODULES), 161 MULT_MOODULES_WITH_SHARED_PATH) 162 163 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 164 def test_path_to_mod_info(self): 165 """test that we get the module name properly.""" 166 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 167 module_list = [] 168 for path_to_mod_info in mod_info.path_to_module_info[PATH_TO_MULT_MODULES_WITH_MULTI_ARCH]: 169 module_list.append(path_to_mod_info.get(constants.MODULE_NAME)) 170 module_list.sort() 171 TESTABLE_MODULES_WITH_SHARED_PATH.sort() 172 self.assertEqual(module_list, TESTABLE_MODULES_WITH_SHARED_PATH) 173 174 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 175 def test_is_suite_in_compatibility_suites(self): 176 """Test is_suite_in_compatibility_suites.""" 177 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 178 info = {'compatibility_suites': []} 179 self.assertFalse(mod_info.is_suite_in_compatibility_suites("cts", info)) 180 info2 = {'compatibility_suites': ["cts"]} 181 self.assertTrue(mod_info.is_suite_in_compatibility_suites("cts", info2)) 182 self.assertFalse(mod_info.is_suite_in_compatibility_suites("vts10", info2)) 183 info3 = {'compatibility_suites': ["cts", "vts10"]} 184 self.assertTrue(mod_info.is_suite_in_compatibility_suites("cts", info3)) 185 self.assertTrue(mod_info.is_suite_in_compatibility_suites("vts10", info3)) 186 self.assertFalse(mod_info.is_suite_in_compatibility_suites("ats", info3)) 187 188 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 189 @mock.patch.object(module_info.ModuleInfo, 'is_testable_module') 190 @mock.patch.object(module_info.ModuleInfo, 'is_suite_in_compatibility_suites') 191 def test_get_testable_modules(self, mock_is_suite_exist, mock_is_testable): 192 """Test get_testable_modules.""" 193 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 194 mock_is_testable.return_value = False 195 self.assertEqual(mod_info.get_testable_modules(), set()) 196 mod_info.name_to_module_info = NAME_TO_MODULE_INFO 197 mock_is_testable.return_value = True 198 mock_is_suite_exist.return_value = True 199 self.assertEqual(1, len(mod_info.get_testable_modules('test_suite'))) 200 mock_is_suite_exist.return_value = False 201 self.assertEqual(0, len(mod_info.get_testable_modules('test_suite'))) 202 self.assertEqual(1, len(mod_info.get_testable_modules())) 203 204 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 205 @mock.patch.object(module_info.ModuleInfo, 'has_test_config') 206 @mock.patch.object(module_info.ModuleInfo, 'is_robolectric_test') 207 def test_is_testable_module(self, mock_is_robo_test, mock_has_test_config): 208 """Test is_testable_module.""" 209 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 210 mock_is_robo_test.return_value = False 211 mock_has_test_config.return_value = True 212 installed_module_info = {constants.MODULE_INSTALLED: 213 uc.DEFAULT_INSTALL_PATH} 214 non_installed_module_info = {constants.MODULE_NAME: 'rand_name'} 215 # Empty mod_info or a non-installed module. 216 self.assertFalse(mod_info.is_testable_module(non_installed_module_info)) 217 self.assertFalse(mod_info.is_testable_module({})) 218 # Testable Module or is a robo module for non-installed module. 219 self.assertTrue(mod_info.is_testable_module(installed_module_info)) 220 mock_has_test_config.return_value = False 221 self.assertFalse(mod_info.is_testable_module(installed_module_info)) 222 mock_is_robo_test.return_value = True 223 self.assertTrue(mod_info.is_testable_module(non_installed_module_info)) 224 225 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 226 @mock.patch.object(module_info.ModuleInfo, 'is_auto_gen_test_config') 227 def test_has_test_config(self, mock_is_auto_gen): 228 """Test has_test_config.""" 229 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 230 info = {constants.MODULE_PATH:[uc.TEST_DATA_DIR]} 231 mock_is_auto_gen.return_value = True 232 # Validate we see the config when it's auto-generated. 233 self.assertTrue(mod_info.has_test_config(info)) 234 self.assertTrue(mod_info.has_test_config({})) 235 # Validate when actual config exists and there's no auto-generated config. 236 mock_is_auto_gen.return_value = False 237 info = {constants.MODULE_PATH:[uc.TEST_DATA_DIR]} 238 self.assertTrue(mod_info.has_test_config(info)) 239 self.assertFalse(mod_info.has_test_config({})) 240 # Validate the case mod_info MODULE_TEST_CONFIG be set 241 info2 = {constants.MODULE_PATH:[uc.TEST_CONFIG_DATA_DIR], 242 constants.MODULE_TEST_CONFIG:[os.path.join( 243 uc.TEST_CONFIG_DATA_DIR, "a.xml.data")]} 244 self.assertTrue(mod_info.has_test_config(info2)) 245 246 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 247 @mock.patch.object(module_info.ModuleInfo, 'get_module_names') 248 def test_get_robolectric_test_name(self, mock_get_module_names): 249 """Test get_robolectric_test_name.""" 250 # Happy path testing, make sure we get the run robo target. 251 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 252 mod_info.name_to_module_info = MOD_NAME_INFO_DICT 253 mod_info.path_to_module_info = MOD_PATH_INFO_DICT 254 mock_get_module_names.return_value = [RUN_ROBO_MOD_NAME, NON_RUN_ROBO_MOD_NAME] 255 self.assertEqual(mod_info.get_robolectric_test_name( 256 NON_RUN_ROBO_MOD_NAME), RUN_ROBO_MOD_NAME) 257 # Let's also make sure we don't return anything when we're not supposed 258 # to. 259 mock_get_module_names.return_value = [NON_RUN_ROBO_MOD_NAME] 260 self.assertEqual(mod_info.get_robolectric_test_name( 261 NON_RUN_ROBO_MOD_NAME), None) 262 263 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 264 @mock.patch.object(module_info.ModuleInfo, 'get_module_info') 265 @mock.patch.object(module_info.ModuleInfo, 'get_module_names') 266 def test_is_robolectric_test(self, mock_get_module_names, mock_get_module_info): 267 """Test is_robolectric_test.""" 268 # Happy path testing, make sure we get the run robo target. 269 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 270 mod_info.name_to_module_info = MOD_NAME_INFO_DICT 271 mod_info.path_to_module_info = MOD_PATH_INFO_DICT 272 mock_get_module_names.return_value = [RUN_ROBO_MOD_NAME, NON_RUN_ROBO_MOD_NAME] 273 mock_get_module_info.return_value = RUN_ROBO_MOD 274 # Test on a run robo module. 275 self.assertTrue(mod_info.is_robolectric_test(RUN_ROBO_MOD_NAME)) 276 # Test on a non-run robo module but shares with a run robo module. 277 self.assertTrue(mod_info.is_robolectric_test(NON_RUN_ROBO_MOD_NAME)) 278 # Make sure we don't find robo tests where they don't exist. 279 mock_get_module_info.return_value = None 280 self.assertFalse(mod_info.is_robolectric_test('rand_mod')) 281 282 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 283 @mock.patch.object(module_info.ModuleInfo, 'is_module') 284 def test_is_auto_gen_test_config(self, mock_is_module): 285 """Test is_auto_gen_test_config correctly detects the module.""" 286 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 287 mock_is_module.return_value = True 288 is_auto_test_config = {'auto_test_config': [True]} 289 is_not_auto_test_config = {'auto_test_config': [False]} 290 is_not_auto_test_config_again = {'auto_test_config': []} 291 MOD_INFO_DICT[MOD_NAME1] = is_auto_test_config 292 MOD_INFO_DICT[MOD_NAME2] = is_not_auto_test_config 293 MOD_INFO_DICT[MOD_NAME3] = is_not_auto_test_config_again 294 MOD_INFO_DICT[MOD_NAME4] = {} 295 mod_info.name_to_module_info = MOD_INFO_DICT 296 self.assertTrue(mod_info.is_auto_gen_test_config(MOD_NAME1)) 297 self.assertFalse(mod_info.is_auto_gen_test_config(MOD_NAME2)) 298 self.assertFalse(mod_info.is_auto_gen_test_config(MOD_NAME3)) 299 self.assertFalse(mod_info.is_auto_gen_test_config(MOD_NAME4)) 300 301 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 302 def test_is_robolectric_module(self): 303 """Test is_robolectric_module correctly detects the module.""" 304 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 305 is_robolectric_module = {'class': ['ROBOLECTRIC']} 306 is_not_robolectric_module = {'class': ['OTHERS']} 307 MOD_INFO_DICT[MOD_NAME1] = is_robolectric_module 308 MOD_INFO_DICT[MOD_NAME2] = is_not_robolectric_module 309 mod_info.name_to_module_info = MOD_INFO_DICT 310 self.assertTrue(mod_info.is_robolectric_module(MOD_INFO_DICT[MOD_NAME1])) 311 self.assertFalse(mod_info.is_robolectric_module(MOD_INFO_DICT[MOD_NAME2])) 312 313 @mock.patch.object(module_info.ModuleInfo, 'get_atest_merged_info_path') 314 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 315 def test_merge_build_system_infos(self, _merge): 316 """Test _merge_build_system_infos.""" 317 _merge.return_value = MERGED_DEP 318 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 319 java_dep_file = os.path.join(uc.TEST_DATA_DIR, 320 'module_bp_java_deps.json') 321 mod_info_1 = {constants.MODULE_NAME: 'module_1', 322 constants.MODULE_DEPENDENCIES: []} 323 name_to_mod_info = {'module_1' : mod_info_1} 324 expect_deps = ['test_dep_level_1_1', 'test_dep_level_1_2'] 325 name_to_mod_info = mod_info._merge_build_system_infos( 326 name_to_mod_info, java_bp_info_path=java_dep_file) 327 self.assertEqual( 328 name_to_mod_info['module_1'].get(constants.MODULE_DEPENDENCIES), 329 expect_deps) 330 331 @mock.patch.object(module_info.ModuleInfo, 'get_atest_merged_info_path') 332 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 333 def test_merge_dependency_with_ori_dependency(self, _merge): 334 """Test _merge_dependency.""" 335 _merge.return_value = MERGED_DEP 336 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 337 java_dep_file = os.path.join(uc.TEST_DATA_DIR, 338 'module_bp_java_deps.json') 339 mod_info_1 = {constants.MODULE_NAME: 'module_1', 340 constants.MODULE_DEPENDENCIES: ['ori_dep_1']} 341 name_to_mod_info = {'module_1' : mod_info_1} 342 expect_deps = ['ori_dep_1', 'test_dep_level_1_1', 'test_dep_level_1_2'] 343 name_to_mod_info = mod_info._merge_build_system_infos( 344 name_to_mod_info, java_bp_info_path=java_dep_file) 345 self.assertEqual( 346 name_to_mod_info['module_1'].get(constants.MODULE_DEPENDENCIES), 347 expect_deps) 348 349 @mock.patch.object(module_info.ModuleInfo, 'get_atest_merged_info_path') 350 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 351 def test_get_module_dependency(self, _merge): 352 """Test get_module_dependency.""" 353 _merge.return_value = MERGED_DEP 354 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 355 java_dep_file = os.path.join(uc.TEST_DATA_DIR, 356 'module_bp_java_deps.json') 357 expect_deps = {'test_dep_level_1_1', 'module_1', 'test_dep_level_1_2', 358 'test_dep_level_2_2', 'test_dep_level_2_1', 'module_2'} 359 mod_info._merge_build_system_infos(mod_info.name_to_module_info, 360 java_bp_info_path=java_dep_file) 361 self.assertEqual( 362 mod_info.get_module_dependency('dep_test_module'), 363 expect_deps) 364 365 @mock.patch.object(module_info.ModuleInfo, 'get_atest_merged_info_path') 366 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 367 def test_get_module_dependency_w_loop(self, _merge): 368 """Test get_module_dependency with problem dep file.""" 369 _merge.return_value = MERGED_DEP 370 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 371 # Java dependency file with a endless loop define. 372 java_dep_file = os.path.join(uc.TEST_DATA_DIR, 373 'module_bp_java_loop_deps.json') 374 expect_deps = {'test_dep_level_1_1', 'module_1', 'test_dep_level_1_2', 375 'test_dep_level_2_2', 'test_dep_level_2_1', 'module_2'} 376 mod_info._merge_build_system_infos(mod_info.name_to_module_info, 377 java_bp_info_path=java_dep_file) 378 self.assertEqual( 379 mod_info.get_module_dependency('dep_test_module'), 380 expect_deps) 381 382 @mock.patch.object(module_info.ModuleInfo, 'get_atest_merged_info_path') 383 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 384 def test_get_install_module_dependency(self, _merge): 385 """Test get_install_module_dependency.""" 386 _merge.return_value = MERGED_DEP 387 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 388 java_dep_file = os.path.join(uc.TEST_DATA_DIR, 389 'module_bp_java_deps.json') 390 expect_deps = {'module_1', 'test_dep_level_2_1'} 391 mod_info._merge_build_system_infos(mod_info.name_to_module_info, 392 java_bp_info_path=java_dep_file) 393 self.assertEqual( 394 mod_info.get_install_module_dependency('dep_test_module'), 395 expect_deps) 396 397 @mock.patch.object(module_info.ModuleInfo, 'get_atest_merged_info_path') 398 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 399 def test_cc_merge_build_system_infos(self, _merge): 400 """Test _merge_build_system_infos for cc.""" 401 _merge.return_value = MERGED_DEP 402 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 403 cc_dep_file = os.path.join(uc.TEST_DATA_DIR, 404 'module_bp_cc_deps.json') 405 mod_info_1 = {constants.MODULE_NAME: 'module_cc_1', 406 constants.MODULE_DEPENDENCIES: []} 407 name_to_mod_info = {'module_cc_1' : mod_info_1} 408 expect_deps = ['test_cc_dep_level_1_1', 'test_cc_dep_level_1_2'] 409 name_to_mod_info = mod_info._merge_build_system_infos( 410 name_to_mod_info, cc_bp_info_path=cc_dep_file) 411 self.assertEqual( 412 name_to_mod_info['module_cc_1'].get(constants.MODULE_DEPENDENCIES), 413 expect_deps) 414 415 @mock.patch.object(atest_utils, 'get_build_out_dir') 416 def test_get_atest_merged_info_path(self, mock_out_dir): 417 """Test get_atest_merged_info_path.""" 418 expect_out = '/test/output/' 419 mock_out_dir.return_value = expect_out 420 expect_path = os.path.join(expect_out, 'soong', 421 module_info._MERGED_INFO) 422 self.assertEqual(expect_path, module_info.ModuleInfo.get_atest_merged_info_path()) 423 424 @mock.patch.object(atest_utils, 'get_build_out_dir') 425 def test_get_java_dep_info_path(self, mock_out_dir): 426 """Test get_java_dep_info_path.""" 427 expect_out = '/test/output/' 428 mock_out_dir.return_value = expect_out 429 expect_path = os.path.join(expect_out, 'soong', 430 module_info._JAVA_DEP_INFO) 431 self.assertEqual(expect_path, module_info.ModuleInfo.get_java_dep_info_path()) 432 433 @mock.patch.object(atest_utils, 'get_build_out_dir') 434 def test_get_cc_dep_info_path(self, mock_out_dir): 435 """Test get_cc_dep_info_path.""" 436 expect_out = '/test/output/' 437 mock_out_dir.return_value = expect_out 438 expect_path = os.path.join(expect_out, 'soong', 439 module_info._CC_DEP_INFO) 440 self.assertEqual(expect_path, module_info.ModuleInfo.get_cc_dep_info_path()) 441 442 @mock.patch.dict('os.environ', {constants.ANDROID_BUILD_TOP:'/'}) 443 def test_is_unit_test(self): 444 """Test is_unit_test.""" 445 module_name = 'myModule' 446 maininfo_with_unittest = {constants.MODULE_NAME: module_name, 447 constants.MODULE_IS_UNIT_TEST: 'true'} 448 mod_info = module_info.ModuleInfo(module_file=JSON_FILE_PATH) 449 self.assertTrue(mod_info.is_unit_test(maininfo_with_unittest)) 450 451if __name__ == '__main__': 452 unittest.main() 453