def test_elf_linker(fizz_buzz, expected_linker_path): # Found by running `readelf -l fizz-buzz`. fizz_buzz_elf = Elf(fizz_buzz, chroot=chroot) expected_linker_path = os.path.join( chroot, os.path.relpath(expected_linker_path, '/')) assert fizz_buzz_elf.linker_file.path == expected_linker_path, \ 'The correct linker should be extracted from the ELF program header.'
def test_elf_direct_dependencies(fizz_buzz): fizz_buzz_elf = Elf(fizz_buzz, chroot=chroot) dependencies = fizz_buzz_elf.direct_dependencies assert all(file.path.startswith(chroot) for file in dependencies), \ 'All dependencies should be located within the chroot.' assert len(dependencies), 'There should be at least one dependency.' # These don't apply to the musl binary. if 'glib' in fizz_buzz: assert len(dependencies) == 2, 'The linker and libc should be the only dependencies.' assert any('libc.so' in file.path for file in dependencies), \ '"libc" was not found as a direct dependency of the executable.'
def test_elf_type(fizz_buzz, expected_type): elf = Elf(fizz_buzz, chroot=chroot) assert elf.type == expected_type, 'Fizz buzz should match the expected ELF binary type.'
def test_elf_dependencies(fizz_buzz): fizz_buzz_elf = Elf(fizz_buzz, chroot=chroot) direct_dependencies = fizz_buzz_elf.direct_dependencies all_dependencies = fizz_buzz_elf.dependencies assert set(direct_dependencies).issubset(all_dependencies), \ 'The direct dependencies should be a subset of all dependencies.'
def test_elf_bits(fizz_buzz, bits): fizz_buzz_elf = Elf(fizz_buzz, chroot=chroot) # Can be checked by running `file fizz-buzz`. assert fizz_buzz_elf.bits == bits, \ 'The fizz buzz executable should be %d-bit.' % bits