import os
import KernelCollection
def check(kernel_cache):
kernel_cache.buildKernelCollection("x86_64", "/kmod-info-local-symbols/main.kc", "/kmod-info-local-symbols/main.kernel", "/kmod-info-local-symbols/extensions", ["com.apple.foo", "com.apple.bar"], [])
kernel_cache.analyze("/kmod-info-local-symbols/main.kc", ["-layout", "-arch", "x86_64"])
assert len(kernel_cache.dictionary()["dylibs"]) == 3
assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["name"] == "__TEXT"
assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["vmAddr"] == "0x205000"
assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["vmSize"] == "0xFF8"
assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["name"] == "__TEXT"
assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["vmAddr"] == "0x206000"
assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["vmSize"] == "0xFF8"
kernel_cache.analyze("/kmod-info-local-symbols/main.kc", ["-kmod", "-arch", "x86_64"])
assert len(kernel_cache.dictionary()) == 3
assert kernel_cache.dictionary()[0]["name"] == "com.apple.kernel"
assert kernel_cache.dictionary()[0]["kmod_info"] == "none"
assert kernel_cache.dictionary()[1]["name"] == "com.apple.bar"
assert kernel_cache.dictionary()[1]["kmod_info"]["info-version"] == "1"
assert kernel_cache.dictionary()[1]["kmod_info"]["name"] == "com.apple.bar"
assert kernel_cache.dictionary()[1]["kmod_info"]["version"] == "1.0.0"
assert kernel_cache.dictionary()[1]["kmod_info"]["address"] == "0x205000"
assert kernel_cache.dictionary()[1]["kmod_info"]["size"] == "0xFF8"
assert kernel_cache.dictionary()[2]["name"] == "com.apple.foo"
assert kernel_cache.dictionary()[2]["kmod_info"]["info-version"] == "1"
assert kernel_cache.dictionary()[2]["kmod_info"]["name"] == "com.apple.foo"
assert kernel_cache.dictionary()[2]["kmod_info"]["version"] == "1.0.0"
assert kernel_cache.dictionary()[2]["kmod_info"]["address"] == "0x206000"
assert kernel_cache.dictionary()[2]["kmod_info"]["size"] == "0xFF8"