]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/KernelCollection.py
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / KernelCollection.py
1 #!/usr/bin/python2.7
2
3 import string
4 import os
5 import json
6 import sys
7 import commands
8 import subprocess
9
10
11 class KernelCollection:
12
13 def __init__(self):
14 self.print_json=False
15
16 def __init__(self, print_json):
17 self.print_json = print_json
18
19 def buildKernelCollection(self, arch_flag, kernel_cache_path, kernel_path, extensions_dir, bundle_ids=[], options=[]):
20 try:
21 test_root = os.path.dirname(__file__)
22 build_root = os.path.realpath(os.path.dirname(__file__) + "/..")
23 app_cache_util = build_root + "/../build/Release/dyld_app_cache_util"
24 args = [app_cache_util,
25 "-create-kernel-collection", test_root + kernel_cache_path,
26 "-kernel", test_root + kernel_path,
27 "-arch", arch_flag]
28 if extensions_dir is not None:
29 args.append("-extensions")
30 args.append(test_root + extensions_dir)
31 for bundle_id in bundle_ids:
32 args.append("-bundle-id")
33 args.append(bundle_id)
34 file_text = subprocess.check_output(["file", build_root + kernel_cache_path]);
35 for opt in options:
36 args.append(opt.replace("$PWD", test_root))
37
38 runline = ""
39 for arg in args:
40 if not arg:
41 runline = runline + '"' + arg + '"' + ' '
42 else:
43 runline = runline + arg + ' '
44
45 self.dict = {}
46 if self.print_json:
47 print "Run with: " + runline
48 process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
49 self.json_text, self.error_message = process.communicate()
50 if self.print_json:
51 print self.json_text
52 print self.error_message
53 if process.returncode:
54 if not self.print_json:
55 print self.error_message
56 print "Non-zero return code"
57 print "Run with: " + runline
58 sys.exit(0)
59 #print self.json_text
60 #print self.error_message
61 if self.json_text:
62 self.dict = json.loads(self.json_text)
63 self.error_message = ""
64 except subprocess.CalledProcessError as e:
65 #print "can't make closure for " + kernel_cache_path
66 self.error_message = e.output
67 self.dict = {}
68 except:
69 assert False
70 self.dict = {}
71
72 def buildPageableKernelCollection(self, arch_flag, aux_kernel_cache_path, kernel_cache_path, extensions_dir, bundle_ids=[], options=[]):
73 try:
74 test_root = os.path.dirname(__file__)
75 build_root = os.path.realpath(os.path.dirname(__file__) + "/..")
76 app_cache_util = build_root + "/../build/Release/dyld_app_cache_util"
77 args = [app_cache_util,
78 "-create-pageable-kernel-collection", test_root + aux_kernel_cache_path,
79 "-kernel-collection", test_root + kernel_cache_path,
80 "-arch", arch_flag]
81 if extensions_dir is not None:
82 args.append("-extensions")
83 args.append(test_root + extensions_dir)
84 for bundle_id in bundle_ids:
85 args.append("-bundle-id")
86 args.append(bundle_id)
87 file_text = subprocess.check_output(["file", build_root + kernel_cache_path]);
88 for opt in options:
89 args.append(opt)
90 self.dict = {}
91 if self.print_json:
92 print "Run with: " + ' '.join(args)
93 process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
94 self.json_text, self.error_message = process.communicate()
95 if self.print_json:
96 print self.json_text
97 print self.error_message
98 if process.returncode:
99 if not self.print_json:
100 print self.error_message
101 print "Non-zero return code"
102 print "Run with: " + ' '.join(args)
103 sys.exit(0)
104 #print self.json_text
105 #print self.error_message
106 if self.json_text:
107 self.dict = json.loads(self.json_text)
108 self.error_message = ""
109 except subprocess.CalledProcessError as e:
110 #print "can't make closure for " + kernel_cache_path
111 self.error_message = e.output
112 self.dict = {}
113 except:
114 assert False
115 self.dict = {}
116
117 def buildAuxKernelCollection(self, arch_flag, aux_kernel_cache_path, kernel_cache_path, pageable_cache_path, extensions_dir, bundle_ids=[], options=[]):
118 try:
119 test_root = os.path.dirname(__file__)
120 build_root = os.path.realpath(os.path.dirname(__file__) + "/..")
121 app_cache_util = build_root + "/../build/Release/dyld_app_cache_util"
122 args = [app_cache_util,
123 "-create-aux-kernel-collection", test_root + aux_kernel_cache_path,
124 "-kernel-collection", test_root + kernel_cache_path,
125 "-arch", arch_flag]
126 if pageable_cache_path:
127 args.append("-pageable-collection")
128 args.append(test_root + pageable_cache_path)
129 if extensions_dir is not None:
130 args.append("-extensions")
131 args.append(test_root + extensions_dir)
132 for bundle_id in bundle_ids:
133 args.append("-bundle-id")
134 args.append(bundle_id)
135 file_text = subprocess.check_output(["file", build_root + kernel_cache_path]);
136 for opt in options:
137 args.append(opt)
138 self.dict = {}
139 if self.print_json:
140 print "Run with: " + ' '.join(args)
141 process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
142 self.json_text, self.error_message = process.communicate()
143 if self.print_json:
144 print self.json_text
145 print self.error_message
146 if process.returncode:
147 if not self.print_json:
148 print self.error_message
149 print "Non-zero return code"
150 print "Run with: " + ' '.join(args)
151 sys.exit(0)
152 #print self.json_text
153 #print self.error_message
154 if self.json_text:
155 self.dict = json.loads(self.json_text)
156 self.error_message = ""
157 except subprocess.CalledProcessError as e:
158 #print "can't make closure for " + kernel_cache_path
159 self.error_message = e.output
160 self.dict = {}
161 except:
162 assert False
163 self.dict = {}
164
165 def analyze(self, app_cache_path, options=[]):
166 try:
167 test_root = os.path.dirname(__file__)
168 build_root = os.path.realpath(os.path.dirname(__file__) + "/..")
169 app_cache_util = build_root + "/../build/Release/dyld_app_cache_util"
170 args = [app_cache_util, "-app-cache", test_root + app_cache_path, "-platform", "kernel"]
171 file_text = subprocess.check_output(["file", build_root + app_cache_path]);
172 for opt in options:
173 args.append(opt)
174 self.dict = {}
175 if self.print_json:
176 print "Run with: " + ' '.join(args)
177 process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
178 self.json_text, self.error_message = process.communicate()
179 if self.print_json:
180 print self.json_text
181 print self.error_message
182 if process.returncode:
183 if not self.print_json:
184 print self.error_message
185 print "Non-zero return code"
186 print "Run with: " + ' '.join(args)
187 sys.exit(0)
188 #print self.json_text
189 #print self.error_message
190 if self.json_text:
191 self.dict = json.loads(self.json_text)
192 self.error_message = ""
193 except subprocess.CalledProcessError as e:
194 #print "can't make closure for " + app_cache_path
195 self.error_message = e.output
196 self.dict = {}
197 except:
198 assert False
199 self.dict = {}
200
201 def dictionary(self):
202 return self.dict
203
204 def error(self):
205 return self.error_message
206