1#!/usr/bin/env python3 2 3import os 4import sys 5import tempfile 6 7import_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) 8import_path = os.path.abspath(os.path.join(import_path, 'utils')) 9sys.path.insert(1, import_path) 10 11from utils import run_header_abi_dumper_on_file 12from utils import run_header_abi_linker 13from utils import TARGET_ARCHS 14from utils import SOURCE_ABI_DUMP_EXT 15 16SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) 17INPUT_DIR = os.path.join(SCRIPT_DIR, 'input') 18EXPECTED_DIR = os.path.join(SCRIPT_DIR, 'expected') 19REF_DUMP_DIR = os.path.join(SCRIPT_DIR, 'reference_dumps') 20ARCH_TARGET_CFLAGS = {'arm': ['-target', 'arm-linux-androideabi'], 21 'arm64': ['-target', 'aarch64-linux-android'], 22 'x86' : ['-target', 'i386-linux-androideabi'], 23 'x86_64' : ['-target', 'x86_64-linux-android'], 24 'mips' : ['-target', 'mips-linux-androideabi'], 25 'mips64' : ['-target', 'mips64-linux-android'],} 26 27def relative_to_abs_path(relative_path): 28 return os.path.join(SCRIPT_DIR, relative_path) 29 30def relative_to_abs_path_list(relative_path_list): 31 abs_paths = [] 32 for relative_path in relative_path_list: 33 abs_paths.append(relative_to_abs_path(relative_path)) 34 return abs_paths 35 36class Module(object): 37 def __init__(self, name, arch, srcs, version_script, cflags, 38 export_include_dirs, api): 39 self.name = name 40 self.arch = arch 41 self.srcs = relative_to_abs_path_list(srcs) 42 self.version_script = relative_to_abs_path(version_script) 43 self.cflags = cflags 44 self.arch_cflags = [''] 45 if self.arch != '': 46 self.arch_cflags = ARCH_TARGET_CFLAGS.get(self.arch) 47 self.export_include_dirs = relative_to_abs_path_list(export_include_dirs) 48 self.api = api 49 50 def get_name(self): 51 return self.name 52 53 def get_arch(self): 54 return self.arch 55 56 def get_srcs(self): 57 return self.srcs 58 59 def get_export_include_dirs(self): 60 return self.export_include_dirs 61 62 def get_cflags(self): 63 return self.cflags 64 65 def get_version_script(self): 66 return self.version_script 67 68 def get_api(self): 69 return self.api 70 71 def make_lsdump(self, default_cflags): 72 """ For each source file, produce a .sdump file, and link them to form 73 an lsump file""" 74 dumps_to_link = [] 75 with tempfile.TemporaryDirectory() as tmp: 76 output_lsdump = os.path.join(tmp, self.name) + SOURCE_ABI_DUMP_EXT 77 for src in self.srcs: 78 output_path = os.path.join(tmp, os.path.basename(src)) + '.sdump' 79 dumps_to_link.append(output_path) 80 run_header_abi_dumper_on_file( 81 src, output_path, self.export_include_dirs, 82 self.cflags + self.arch_cflags + default_cflags) 83 return run_header_abi_linker(output_lsdump, dumps_to_link, 84 self.version_script, self.api, 85 self.arch) 86 @staticmethod 87 def mutate_module_for_arch(module, target_arch): 88 name = module.get_name() 89 srcs = module.get_srcs() 90 version_script = module.get_version_script() 91 cflags = module.get_cflags() 92 export_include_dirs = module.get_export_include_dirs() 93 api = module.get_api() 94 return Module(name, target_arch, srcs, version_script, cflags, 95 export_include_dirs, api) 96 97 @staticmethod 98 def mutate_module_for_all_arches(module): 99 modules = [] 100 for target_arch in TARGET_ARCHS: 101 modules.append(Module.mutate_module_for_arch(module, target_arch)) 102 return modules 103 104 @staticmethod 105 def get_test_modules(): 106 modules = [] 107 for module in TEST_MODULES.values(): 108 if module.get_arch() == '': 109 modules += Module.mutate_module_for_all_arches(module) 110 return modules 111 112 @staticmethod 113 def get_test_module_by_name(name): 114 return TEST_MODULES[name] 115 116TEST_MODULES = [ 117 Module( 118 name = 'libc_and_cpp', 119 srcs = ['integration/c_and_cpp/source1.cpp', 120 'integration/c_and_cpp/source2.c', 121 ], 122 version_script = 'integration/c_and_cpp/map.txt', 123 export_include_dirs = ['integration/c_and_cpp/include'], 124 cflags = [], 125 arch = '', 126 api = 'current', 127 ), 128 Module( 129 name = 'libc_and_cpp_with_unused_struct', 130 srcs = ['integration/c_and_cpp/source1.cpp', 131 'integration/c_and_cpp/source2.c', 132 ], 133 version_script = 'integration/c_and_cpp/map.txt', 134 export_include_dirs = ['integration/c_and_cpp/include'], 135 cflags = ['-DINCLUDE_UNUSED_STRUCTS=1'], 136 arch = '', 137 api = 'current', 138 ), 139 Module( 140 name = 'libc_and_cpp_with_unused_cstruct', 141 srcs = ['integration/c_and_cpp/source1.cpp', 142 'integration/c_and_cpp/source2.c', 143 ], 144 version_script = 'integration/c_and_cpp/map.txt', 145 export_include_dirs = ['integration/c_and_cpp/include'], 146 cflags = ['-DINCLUDE_UNUSED_STRUCTS=1', '-DMAKE_UNUSED_STRUCT_C=1'], 147 arch = '', 148 api = 'current', 149 ), 150 Module( 151 name = 'libgolden_cpp', 152 srcs = ['integration/cpp/gold/golden_1.cpp', 153 'integration/cpp/gold/high_volume_speaker.cpp', 154 'integration/cpp/gold/low_volume_speaker.cpp', 155 ], 156 version_script = 'integration/cpp/gold/map.txt', 157 export_include_dirs = ['integration/cpp/gold/include'], 158 cflags = [], 159 arch = '', 160 api = 'current', 161 ), 162 Module( 163 name = 'libgolden_cpp_odr', 164 srcs = ['integration/cpp/gold/golden_1.cpp', 165 'integration/cpp/gold/high_volume_speaker.cpp', 166 'integration/cpp/gold/low_volume_speaker.cpp', 167 ], 168 version_script = 'integration/cpp/gold/map.txt', 169 export_include_dirs = ['integration/cpp/gold/include'], 170 cflags = ['-DTEST_ODR'], 171 arch = '', 172 api = 'current', 173 ), 174 Module( 175 name = 'libgolden_cpp_add_function', 176 srcs = ['integration/cpp/gold/golden_1.cpp', 177 'integration/cpp/gold/high_volume_speaker.cpp', 178 'integration/cpp/gold/low_volume_speaker.cpp', 179 ], 180 version_script = 'integration/cpp/gold/map_add_function.txt', 181 export_include_dirs = ['integration/cpp/gold/include'], 182 cflags = ['-DGOLDEN_ADD_FUNCTION=1'], 183 arch = '', 184 api = 'current', 185 ), 186 Module( 187 name = 'libgolden_cpp_add_function_and_unexported_elf', 188 srcs = ['integration/cpp/gold/golden_1.cpp', 189 'integration/cpp/gold/high_volume_speaker.cpp', 190 'integration/cpp/gold/low_volume_speaker.cpp', 191 ], 192 version_script = \ 193 'integration/cpp/gold/map_add_function_elf_symbol.txt', 194 export_include_dirs = ['integration/cpp/gold/include'], 195 cflags = ['-DGOLDEN_ADD_FUNCTION=1', '-DADD_UNEXPORTED_ELF_SYMBOL'], 196 arch = '', 197 api = 'current', 198 ), 199 Module( 200 name = 'libgolden_cpp_change_function_access', 201 srcs = ['integration/cpp/gold/golden_1.cpp', 202 'integration/cpp/gold/high_volume_speaker.cpp', 203 'integration/cpp/gold/low_volume_speaker.cpp', 204 ], 205 version_script = 'integration/cpp/gold/map.txt', 206 export_include_dirs = ['integration/cpp/gold/include'], 207 cflags = ['-DGOLDEN_CHANGE_FUNCTION_ACCESS=1'], 208 arch = '', 209 api = 'current', 210 ), 211 Module( 212 name = 'libgolden_cpp_add_global_variable', 213 srcs = ['integration/cpp/gold/golden_1.cpp', 214 'integration/cpp/gold/high_volume_speaker.cpp', 215 'integration/cpp/gold/low_volume_speaker.cpp', 216 ], 217 version_script = 'integration/cpp/gold/map_added_globvar.txt', 218 export_include_dirs = ['integration/cpp/gold/include'], 219 cflags = ['-DGOLDEN_ADD_GLOBVAR=1'], 220 arch = '', 221 api = 'current', 222 ), 223 Module( 224 name = 'libgolden_cpp_add_global_variable_private', 225 srcs = ['integration/cpp/gold/golden_1.cpp', 226 'integration/cpp/gold/high_volume_speaker.cpp', 227 'integration/cpp/gold/low_volume_speaker.cpp', 228 ], 229 version_script = 'integration/cpp/gold/map_added_globvar.txt', 230 export_include_dirs = ['integration/cpp/gold/include'], 231 cflags = ['-DGOLDEN_ADD_GLOBVAR=1', '-DGOLDEN_ADD_GLOBVAR_PRIVATE'], 232 arch = '', 233 api = 'current', 234 ), 235 Module( 236 name = 'libgolden_cpp_return_type_diff', 237 srcs = ['integration/cpp/gold/golden_1.cpp', 238 'integration/cpp/gold/high_volume_speaker.cpp', 239 'integration/cpp/gold/low_volume_speaker.cpp', 240 ], 241 version_script = 'integration/cpp/gold/map.txt', 242 export_include_dirs = ['integration/cpp/gold/include'], 243 cflags = ['-DGOLDEN_RETURN_TYPE_DIFF=1'], 244 arch = '', 245 api = 'current', 246 ), 247 Module( 248 name = 'libgolden_cpp_parameter_type_diff', 249 srcs = ['integration/cpp/gold/golden_1.cpp', 250 'integration/cpp/gold/high_volume_speaker.cpp', 251 'integration/cpp/gold/low_volume_speaker.cpp', 252 ], 253 version_script = 'integration/cpp/gold/map_parameter_type_diff.txt', 254 export_include_dirs = ['integration/cpp/gold/include'], 255 cflags = ['-DGOLDEN_PARAMETER_TYPE_DIFF=1'], 256 arch = '', 257 api = 'current', 258 ), 259 Module( 260 name = 'libgolden_cpp_vtable_diff', 261 srcs = ['integration/cpp/gold/golden_1.cpp', 262 'integration/cpp/gold/high_volume_speaker.cpp', 263 'integration/cpp/gold/low_volume_speaker.cpp', 264 ], 265 version_script = 'integration/cpp/gold/map.txt', 266 export_include_dirs = ['integration/cpp/gold/include'], 267 cflags = ['-DGOLDEN_VTABLE_DIFF=1'], 268 arch = '', 269 api = 'current', 270 ), 271 Module( 272 name = 'libgolden_cpp_member_diff', 273 srcs = ['integration/cpp/gold/golden_1.cpp', 274 'integration/cpp/gold/high_volume_speaker.cpp', 275 'integration/cpp/gold/low_volume_speaker.cpp', 276 ], 277 version_script = 'integration/cpp/gold/map.txt', 278 export_include_dirs = ['integration/cpp/gold/include'], 279 cflags = ['-DGOLDEN_MEMBER_DIFF=1'], 280 arch = '', 281 api = 'current', 282 ), 283 Module( 284 name = 'libgolden_cpp_member_fake_diff', 285 srcs = ['integration/cpp/gold/golden_1.cpp', 286 'integration/cpp/gold/high_volume_speaker.cpp', 287 'integration/cpp/gold/low_volume_speaker.cpp', 288 ], 289 version_script = 'integration/cpp/gold/map.txt', 290 export_include_dirs = ['integration/cpp/gold/include'], 291 cflags = ['-DGOLDEN_MEMBER_FAKE_DIFF=1'], 292 arch = '', 293 api = 'current', 294 ), 295 Module( 296 name = 'libgolden_cpp_member_cv_diff', 297 srcs = ['integration/cpp/gold/golden_1.cpp', 298 'integration/cpp/gold/high_volume_speaker.cpp', 299 'integration/cpp/gold/low_volume_speaker.cpp', 300 ], 301 version_script = 'integration/cpp/gold/map.txt', 302 export_include_dirs = ['integration/cpp/gold/include'], 303 cflags = ['-DGOLDEN_MEMBER_CV_DIFF=1'], 304 arch = '', 305 api = 'current', 306 ), 307 Module( 308 name = 'libgolden_cpp_change_member_access', 309 srcs = ['integration/cpp/gold/golden_1.cpp', 310 'integration/cpp/gold/high_volume_speaker.cpp', 311 'integration/cpp/gold/low_volume_speaker.cpp', 312 ], 313 version_script = 'integration/cpp/gold/map.txt', 314 export_include_dirs = ['integration/cpp/gold/include'], 315 cflags = ['-DGOLDEN_CHANGE_MEMBER_ACCESS=1'], 316 arch = '', 317 api = 'current', 318 ), 319 Module( 320 name = 'libgolden_cpp_member_integral_type_diff', 321 srcs = ['integration/cpp/gold/golden_1.cpp', 322 'integration/cpp/gold/high_volume_speaker.cpp', 323 'integration/cpp/gold/low_volume_speaker.cpp', 324 ], 325 version_script = 'integration/cpp/gold/map.txt', 326 export_include_dirs = ['integration/cpp/gold/include'], 327 cflags = ['-DGOLDEN_MEMBER_INTEGRAL_TYPE_DIFF=1'], 328 arch = '', 329 api = 'current', 330 ), 331 Module( 332 name = 'libgolden_cpp_enum_diff', 333 srcs = ['integration/cpp/gold/golden_1.cpp', 334 'integration/cpp/gold/high_volume_speaker.cpp', 335 'integration/cpp/gold/low_volume_speaker.cpp', 336 ], 337 version_script = 'integration/cpp/gold/map.txt', 338 export_include_dirs = ['integration/cpp/gold/include'], 339 cflags = ['-DGOLDEN_ENUM_DIFF=1'], 340 arch = '', 341 api = 'current', 342 ), 343 Module( 344 name = 'libgolden_cpp_enum_extended', 345 srcs = ['integration/cpp/gold/golden_1.cpp', 346 'integration/cpp/gold/high_volume_speaker.cpp', 347 'integration/cpp/gold/low_volume_speaker.cpp', 348 ], 349 version_script = 'integration/cpp/gold/map.txt', 350 export_include_dirs = ['integration/cpp/gold/include'], 351 cflags = ['-DGOLDEN_ENUM_EXTENSION=1'], 352 arch = '', 353 api = 'current', 354 ), 355 Module( 356 name = 'libgolden_cpp_unreferenced_elf_symbol_removed', 357 srcs = ['integration/cpp/gold/golden_1.cpp', 358 'integration/cpp/gold/high_volume_speaker.cpp', 359 'integration/cpp/gold/low_volume_speaker.cpp', 360 ], 361 version_script = 'integration/cpp/gold/map_elf_symbol_removed.txt', 362 export_include_dirs = ['integration/cpp/gold/include'], 363 cflags = [], 364 arch = '', 365 api = 'current', 366 ), 367 Module( 368 name = 'libreproducability', 369 srcs = ['integration/c_and_cpp/reproducability.c', 370 ], 371 version_script = 'integration/c_and_cpp/repro_map.txt', 372 export_include_dirs = ['integration/c_and_cpp/include'], 373 cflags = [], 374 arch = '', 375 api = 'current', 376 ), 377 Module( 378 name = 'libgolden_cpp_member_name_changed', 379 srcs = ['integration/cpp/gold/golden_1.cpp', 380 'integration/cpp/gold/high_volume_speaker.cpp', 381 'integration/cpp/gold/low_volume_speaker.cpp', 382 ], 383 version_script = 'integration/cpp/gold/map.txt', 384 export_include_dirs = ['integration/cpp/gold/include'], 385 cflags = ['-DGOLDEN_CHANGE_MEMBER_NAME_SAME_OFFSET=1'], 386 arch = '', 387 api = 'current', 388 ), 389 Module( 390 name = 'libgolden_cpp_function_pointer', 391 srcs = ['integration/cpp/gold/golden_1.cpp', 392 'integration/cpp/gold/high_volume_speaker.cpp', 393 'integration/cpp/gold/low_volume_speaker.cpp', 394 ], 395 version_script = 'integration/cpp/gold/map.txt', 396 export_include_dirs = ['integration/cpp/gold/include'], 397 cflags = ['-DGOLDEN_FUNCTION_POINTER=1'], 398 arch = '', 399 api = 'current', 400 ), 401 Module( 402 name = 'libgolden_cpp_function_pointer_parameter_added', 403 srcs = ['integration/cpp/gold/golden_1.cpp', 404 'integration/cpp/gold/high_volume_speaker.cpp', 405 'integration/cpp/gold/low_volume_speaker.cpp', 406 ], 407 version_script = 'integration/cpp/gold/map.txt', 408 export_include_dirs = ['integration/cpp/gold/include'], 409 cflags = ['-DGOLDEN_FUNCTION_POINTER_ADD_PARAM=1', 410 '-DGOLDEN_FUNCTION_POINTER=1'], 411 arch = '', 412 api = 'current', 413 ), 414] 415 416TEST_MODULES = { m.name: m for m in TEST_MODULES } 417