def test_get_build_info(fixture, expected_result): elf_fixture_filename = os.path.join(ELF_FIXTURES_DIR, fixture) with open_copy(elf_fixture_filename, mode="rb") as elf_copy_file: b = BuildIdInspectorAndPatcher(elf_copy_file) assert b.get_build_info() == expected_result assert filecmp.cmp(elf_copy_file.name, elf_fixture_filename)
def test_no_build_id_on_dump(): elf_fixture_filename = os.path.join( ELF_FIXTURES_DIR, "memfault_build_id_present_and_unpopulated.elf") with pytest.raises(Exception, match="No Build ID Found"): with open(elf_fixture_filename, "rb") as elf_fixture_file: b = BuildIdInspectorAndPatcher(elf_fixture_file) b.dump_build_info(num_chars=1)
def test_no_memfault_sdk_present(): elf_fixture_filename = os.path.join(ELF_FIXTURES_DIR, "no_memfault_symbols.elf") with pytest.raises( Exception, match= "Could not locate 'g_memfault_build_id' symbol in provided ELF"): b = BuildIdInspectorAndPatcher(elf_fixture_filename) b.check_or_update_build_id()
def test_memfault_id_populated(capsys, snapshot): elf_fixture_filename = os.path.join( ELF_FIXTURES_DIR, "memfault_build_id_present_and_populated.elf") with temporary_filename(elf_fixture_filename) as elf_copy_filename: b = BuildIdInspectorAndPatcher(elf_copy_filename) b.check_or_update_build_id() assert filecmp.cmp(elf_copy_filename, elf_fixture_filename) out, _ = capsys.readouterr() lines = out.splitlines() snapshot.assert_match(lines)
def test_gnu_build_id_in_use(capsys, snapshot): elf_fixture_filename = os.path.join(ELF_FIXTURES_DIR, "gnu_id_present_and_used.elf") with open_copy(elf_fixture_filename, mode="rb") as elf_copy_file: b = BuildIdInspectorAndPatcher(elf_copy_file) b.check_or_update_build_id() assert filecmp.cmp(elf_copy_file.name, elf_fixture_filename) out, _ = capsys.readouterr() lines = out.splitlines() snapshot.assert_match(lines)
def test_build_id_dump(capsys, snapshot): elf_fixture_filename = os.path.join( ELF_FIXTURES_DIR, "memfault_build_id_present_and_populated.elf") with open_copy(elf_fixture_filename, mode="rb") as elf_copy_file: b = BuildIdInspectorAndPatcher(elf_copy_file) b.dump_build_info(num_chars=1) b.dump_build_info(num_chars=2) b.dump_build_info(num_chars=30) assert filecmp.cmp(elf_copy_file.name, elf_fixture_filename) out, _ = capsys.readouterr() lines = out.splitlines() snapshot.assert_match(lines)