import os
import KernelCollection
def check(kernel_cache):
kernel_cache.buildKernelCollection("arm64", "/ppl-data-const/main.kc", "/ppl-data-const/main.kernel", "/ppl-data-const/extensions", ["com.apple.foo", "com.apple.bar"], [])
kernel_cache.analyze("/ppl-data-const/main.kc", ["-layout", "-arch", "arm64"])
assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__DATA_CONST"
assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0x18000"
assert kernel_cache.dictionary()["cache-segments"][3]["vmSize"] == "0x8000"
assert len(kernel_cache.dictionary()["dylibs"]) == 3
assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["name"] == "__PPLDATA_CONST"
assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0x18000"
assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
kernel_cache.analyze("/ppl-data-const/main.kc", ["-symbols", "-arch", "arm64"])
assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["name"] == "_x"
assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["vmAddr"] == "0x24000"
assert kernel_cache.dictionary()["dylibs"][2]["global-symbols"][0]["name"] == "_foo"
assert kernel_cache.dictionary()["dylibs"][2]["global-symbols"][0]["vmAddr"] == "0x14030"
kernel_cache.analyze("/ppl-data-const/main.kc", ["-fixups", "-arch", "arm64"])
assert kernel_cache.dictionary()["fixups"]["0x18000"] == "kc(0) + 0x24000"
assert kernel_cache.dictionary()["fixups"]["0x1C000"] == "kc(0) + 0x14030"