dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / kmod-info-local-symbols / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # Update the kmod_info entry for the files here
7
8 def check(kernel_cache):
9 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"], [])
10
11 # Check the layout
12 kernel_cache.analyze("/kmod-info-local-symbols/main.kc", ["-layout", "-arch", "x86_64"])
13
14 assert len(kernel_cache.dictionary()["dylibs"]) == 3
15 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
16
17 # Find the address and size of each kext in the layout and check that these match their kmod info values
18 # bar.kext
19 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
20 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["name"] == "__TEXT"
21 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["vmAddr"] == "0x205000"
22 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["vmSize"] == "0xFF8"
23 # foo.kext
24 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
25 assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["name"] == "__TEXT"
26 assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["vmAddr"] == "0x206000"
27 assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["vmSize"] == "0xFF8"
28
29 # Check the kmod info
30 kernel_cache.analyze("/kmod-info-local-symbols/main.kc", ["-kmod", "-arch", "x86_64"])
31 assert len(kernel_cache.dictionary()) == 3
32 assert kernel_cache.dictionary()[0]["name"] == "com.apple.kernel"
33 assert kernel_cache.dictionary()[0]["kmod_info"] == "none"
34
35 # bar.kext
36 assert kernel_cache.dictionary()[1]["name"] == "com.apple.bar"
37 assert kernel_cache.dictionary()[1]["kmod_info"]["info-version"] == "1"
38 assert kernel_cache.dictionary()[1]["kmod_info"]["name"] == "com.apple.bar"
39 assert kernel_cache.dictionary()[1]["kmod_info"]["version"] == "1.0.0"
40 assert kernel_cache.dictionary()[1]["kmod_info"]["address"] == "0x205000"
41 assert kernel_cache.dictionary()[1]["kmod_info"]["size"] == "0xFF8"
42
43 # foo.kext
44 assert kernel_cache.dictionary()[2]["name"] == "com.apple.foo"
45 assert kernel_cache.dictionary()[2]["kmod_info"]["info-version"] == "1"
46 assert kernel_cache.dictionary()[2]["kmod_info"]["name"] == "com.apple.foo"
47 assert kernel_cache.dictionary()[2]["kmod_info"]["version"] == "1.0.0"
48 assert kernel_cache.dictionary()[2]["kmod_info"]["address"] == "0x206000"
49 assert kernel_cache.dictionary()[2]["kmod_info"]["size"] == "0xFF8"
50
51 # [~]> xcrun -sdk macosx.internal cc -fvisibility=hidden -arch x86_64 -Wl,-static -mkernel -nostdlib -Wl,-e,__start -Wl,-pie main.c -Wl,-pagezero_size,0x0 -o main.kernel -Wl,-image_base,0x200000 -Wl,-segaddr,__HIB,0x100000 -Wl,-add_split_seg_info -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack
52 # [~]> xcrun -sdk macosx.internal cc -fvisibility=hidden -arch x86_64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info foo.c -o extensions/foo.kext/foo
53 # [~]> xcrun -sdk macosx.internal cc -fvisibility=hidden -arch x86_64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info bar.c -o extensions/bar.kext/bar
54 # [~]> rm -r extensions/*.kext/*.ld
55