4 // Some of these tests here verify that kdd is able to parse old
5 // kcdata files and generate the correct output. To do so, we include
6 // compressed versions of the raw kcdata and as well as the expected
9 // NOTE: If you're adding sample data/plist files, you'll need to first
10 // add them to the project and then make sure each is part of the
13 // Other tests verify the expected behavior of libkdd for certain
21 // Swift's bridging to uuid_t is awkward.
23 func nsuuid2uuid_t(_ nsuuid : NSUUID) -> uuid_t {
24 let dat = nsuuid2array(nsuuid)
25 return nsarray2uuid(dat)
28 func nsarray2uuid(_ a : [Int]) -> uuid_t {
29 return uuid_t(UInt8(a[0]),
47 func nsuuid2array(_ uuid: NSUUID) -> [Int] {
49 let ptr = UnsafeMutablePointer<UInt8>.allocate(capacity: 16)
51 defer { ptr.deallocate(capacity:16) }
55 ret.append(Int(ptr[i]))
60 func decompress(_ data:NSData) throws -> NSData {
61 var stream = z_stream(next_in: nil, avail_in: 0, total_in: 0, next_out: nil, avail_out: 0, total_out: 0, msg: nil, state: nil, zalloc: nil, zfree: nil, opaque: nil, data_type: 0, adler: 0, reserved: 0)
63 let bufsize : Int = 1000
64 let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufsize)
65 defer { buffer.deallocate(capacity:bufsize) }
66 let output = NSMutableData()
67 stream.next_out = buffer
68 stream.avail_out = UInt32(bufsize)
69 stream.next_in = UnsafeMutablePointer(mutating:data.bytes.assumingMemoryBound(to:Bytef.self))
70 stream.avail_in = UInt32(data.length)
71 inflateInit2_(&stream, 16+MAX_WBITS, ZLIB_VERSION, Int32(MemoryLayout<z_stream>.size))
74 let z = inflate(&stream, Z_NO_FLUSH);
75 if (z == Z_OK || z == Z_STREAM_END) {
76 output.append(buffer, length: bufsize - Int(stream.avail_out))
77 stream.avail_out = UInt32(bufsize)
78 stream.next_out = buffer
79 if (z == Z_STREAM_END) {
83 throw NSError(domain: "zlib", code: Int(z), userInfo: nil)
89 extension Dictionary {
90 func value(forKeyPath s:String) -> Any? {
91 return (self as NSDictionary).value(forKeyPath:s)
96 class Tests: XCTestCase {
98 override func setUp() {
100 continueAfterFailure = false
103 override func tearDown() {
104 // Put teardown code here. This method is called after the invocation of each test method in the class.
108 func parseBuffer(_ buffer:NSData) throws -> [AnyHashable:Any] {
110 guard let dict = parseKCDataBuffer(UnsafeMutablePointer(mutating:buffer.bytes.assumingMemoryBound(to:UInt8.self)), UInt32(buffer.length), &error)
112 XCTAssert(error != nil)
118 func testPaddingFlags(_ pad : Int) {
119 let buffer = NSMutableData(capacity:1000)!
121 var item = kcdata_item()
123 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
126 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
128 item.type = UInt32(KCDATA_TYPE_LIBRARY_LOADINFO)
129 item.flags = UInt64(pad)
130 item.size = UInt32(MemoryLayout<dyld_uuid_info_32>.size)
131 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
133 let uuid = NSUUID(uuidString: "de305d54-75b4-431b-adb2-eb6b9e546014")!
135 var payload = dyld_uuid_info_32(imageLoadAddress: 42, imageUUID: nsuuid2uuid_t(uuid))
136 buffer.append(&payload, length:MemoryLayout<dyld_uuid_info_32>.size)
138 item.type = KCDATA_TYPE_BUFFER_END
141 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
143 guard let dict = try? self.parseBuffer(buffer)
144 else { XCTFail(); return; }
146 var uuidarray = nsuuid2array(uuid)
148 uuidarray.removeLast()
151 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageLoadAddress") as? Int == 42)
152 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageUUID") as! [Int] == uuidarray)
155 func testPaddingFlags() {
160 func testBootArgs() {
161 let s = "hello, I am some boot args"
163 let buffer = NSMutableData(capacity:1000)!
165 var item = kcdata_item()
167 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
170 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
172 item.type = UInt32(STACKSHOT_KCTYPE_BOOTARGS)
174 item.size = UInt32(s.utf8.count + 1)
175 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
176 s.utf8CString.withUnsafeBufferPointer({
177 buffer.append($0.baseAddress!, length:s.utf8.count + 1)
179 item.type = KCDATA_TYPE_BUFFER_END
182 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
184 guard let dict = try? self.parseBuffer(buffer) else { XCTFail(); return; }
185 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.boot_args") as? String == s)
188 func testBootArgsMissingNul() {
189 let s = "hello, I am some boot args"
191 let buffer = NSMutableData(capacity:1000)!
193 var item = kcdata_item()
195 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
198 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
200 item.type = UInt32(STACKSHOT_KCTYPE_BOOTARGS)
202 item.size = UInt32(s.utf8.count)
203 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
204 s.utf8CString.withUnsafeBufferPointer({
205 buffer.append($0.baseAddress!, length:s.utf8.count)
208 item.type = KCDATA_TYPE_BUFFER_END
211 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
213 XCTAssert( (try? self.parseBuffer(buffer)) == nil )
216 func testLoadInfo() {
217 let buffer = NSMutableData(capacity:1000)!
219 var item = kcdata_item()
221 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
224 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
226 item.type = UInt32(KCDATA_TYPE_LIBRARY_LOADINFO)
228 item.size = UInt32(MemoryLayout<dyld_uuid_info_32>.size)
229 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
231 let uuid = NSUUID(uuidString: "de305d54-75b4-431b-adb2-eb6b9e546014")!
233 var payload = dyld_uuid_info_32(imageLoadAddress: 42, imageUUID: nsuuid2uuid_t(uuid))
234 buffer.append(&payload, length:MemoryLayout<dyld_uuid_info_32>.size)
236 item.type = KCDATA_TYPE_BUFFER_END
239 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
241 guard let dict = try? self.parseBuffer(buffer)
242 else { XCTFail(); return; }
244 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageLoadAddress") as? Int == 42)
245 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageUUID") as! [Int] == nsuuid2array(uuid))
248 func testLoadInfoWrongSize() {
249 // test what happens when a struct size is short
251 let buffer = NSMutableData(capacity:1000)!
253 var item = kcdata_item()
255 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
258 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
260 item.type = UInt32(KCDATA_TYPE_LIBRARY_LOADINFO)
262 item.size = UInt32(MemoryLayout<dyld_uuid_info_32>.size) - 1
263 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
265 let uuid = NSUUID(uuidString: "de305d54-75b4-431b-adb2-eb6b9e546014")!
267 var payload = dyld_uuid_info_32(imageLoadAddress: 42, imageUUID: nsuuid2uuid_t(uuid))
268 buffer.append(&payload, length:MemoryLayout<dyld_uuid_info_32>.size - 1)
270 item.type = KCDATA_TYPE_BUFFER_END
273 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
275 guard let dict = try? self.parseBuffer(buffer)
276 else { XCTFail(); return; }
277 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageLoadAddress") as? Int == 42)
278 var uuidarray = nsuuid2array(uuid)
279 uuidarray.removeLast()
280 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageUUID") as! [Int] == uuidarray)
283 func testLoadInfoWayWrongSize() {
284 // test what happens when a struct size is short
286 let buffer = NSMutableData(capacity:1000)!
288 var item = kcdata_item()
290 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
293 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
295 item.type = UInt32(KCDATA_TYPE_LIBRARY_LOADINFO)
297 item.size = UInt32(MemoryLayout<dyld_uuid_info_32>.size) - 16
298 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
300 let uuid = NSUUID(uuidString: "de305d54-75b4-431b-adb2-eb6b9e546014")!
302 var payload = dyld_uuid_info_32(imageLoadAddress: 42, imageUUID: nsuuid2uuid_t(uuid))
303 buffer.append(&payload, length:MemoryLayout<dyld_uuid_info_32>.size - 16)
305 item.type = KCDATA_TYPE_BUFFER_END
308 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
309 guard let dict = try? self.parseBuffer(buffer)
310 else { XCTFail(); return; }
311 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageLoadAddress") as? Int == 42)
312 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageUUID") == nil)
315 func testLoadInfoPreposterousWrongSize() {
316 // test what happens when a struct size is short
318 let buffer = NSMutableData(capacity:1000)!
320 var item = kcdata_item()
322 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
325 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
327 item.type = UInt32(KCDATA_TYPE_LIBRARY_LOADINFO)
329 item.size = UInt32(1)
330 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
332 var payload = UInt8(42)
333 buffer.append(&payload, length:1)
335 item.type = KCDATA_TYPE_BUFFER_END
338 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
340 guard let dict = try? self.parseBuffer(buffer)
341 else { XCTFail(); return; }
342 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageLoadAddress") == nil)
343 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info.imageUUID") == nil)
347 func testNewArray(n : Int, pad : Int) {
348 let buffer = NSMutableData(capacity:1000)!
349 var item = kcdata_item()
351 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
354 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
356 item.type = UInt32(KCDATA_TYPE_ARRAY_PAD0) + UInt32(pad)
357 item.flags = UInt64(STACKSHOT_KCTYPE_DONATING_PIDS) << 32 | UInt64(n)
358 item.size = UInt32(n * MemoryLayout<UInt32>.size + pad)
359 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
362 var payload = UInt32(42 * i)
363 buffer.append(&payload, length:MemoryLayout<UInt32>.size)
367 var payload = UInt8(42-i)
368 buffer.append(&payload, length:MemoryLayout<UInt8>.size)
371 item.type = KCDATA_TYPE_BUFFER_END
374 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
376 guard let dict = try? self.parseBuffer(buffer)
377 else { XCTFail(); return; }
378 XCTAssert((dict.value(forKeyPath:"kcdata_crashinfo.donating_pids") as! [Any]).count == n)
380 let x = dict["kcdata_crashinfo"] as? NSDictionary
381 let y = x?["donating_pids"] as? NSArray
382 XCTAssert((y?[i]) as? Int == 42 * i)
386 func testNewArrays() {
387 self.testNewArray(n:0,pad:0)
390 self.testNewArray(n:i, pad:pad)
396 func testArrayLoadInfo(n : Int) {
397 let buffer = NSMutableData(capacity:1000)!
398 var item = kcdata_item()
400 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
403 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
405 item.type = UInt32(KCDATA_TYPE_ARRAY_PAD0)
406 item.flags = UInt64(KCDATA_TYPE_LIBRARY_LOADINFO) << 32 | UInt64(n)
407 item.size = UInt32(n * MemoryLayout<dyld_uuid_info_32>.size)
408 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
410 let uuid = NSUUID(uuidString: "de305d54-75b4-431b-adb2-eb6b9e546014")!
414 var payload = dyld_uuid_info_32(imageLoadAddress:UInt32(i+42), imageUUID: nsuuid2uuid_t(uuid))
416 buffer.append(&payload, length:MemoryLayout<dyld_uuid_info_32>.size)
419 item.type = KCDATA_TYPE_BUFFER_END
422 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
424 guard let dict = try? self.parseBuffer(buffer)
425 else { XCTFail(); return; }
426 XCTAssert((dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info") as! [Any]).count == n)
428 guard let loadinfo = dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info") as? [Any]
429 else { XCTFail(); return; }
430 guard let loadinfo_i = loadinfo[i] as? [AnyHashable:Any]
431 else { XCTFail(); return; }
432 XCTAssert(loadinfo_i["imageLoadAddress"] as? Int == 42 + i)
433 XCTAssert(loadinfo_i["imageUUID"] as! [Int] == nsuuid2array(uuid))
437 func testArrayLoadInfo() {
439 testArrayLoadInfo(n: n)
443 func testArrayLoadInfoWrongSize() {
444 // test what happens when array element sizes are too short
448 let buffer = NSMutableData(capacity:1000)!
449 var item = kcdata_item()
451 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
454 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
456 item.type = UInt32(KCDATA_TYPE_ARRAY_PAD0)
457 item.flags = UInt64(KCDATA_TYPE_LIBRARY_LOADINFO) << 32 | UInt64(n)
458 item.size = UInt32(n * (MemoryLayout<dyld_uuid_info_32>.size - wrong))
459 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
461 let uuid = NSUUID(uuidString: "de305d54-75b4-431b-adb2-eb6b9e546014")!
464 var payload = dyld_uuid_info_32(imageLoadAddress:UInt32(i+42), imageUUID: nsuuid2uuid_t(uuid))
465 buffer.append(&payload, length:MemoryLayout<dyld_uuid_info_32>.size-wrong)
468 item.type = KCDATA_TYPE_BUFFER_END
471 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
472 var uuidarray = nsuuid2array(uuid)
473 uuidarray.removeLast()
475 guard let dict = try? self.parseBuffer(buffer)
476 else { XCTFail(); return; }
477 XCTAssert((dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info") as! [Any]).count == n)
479 guard let loadinfo = dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info") as? [Any]
480 else { XCTFail(); return; }
481 guard let loadinfo_i = loadinfo[i] as? [AnyHashable:Any]
482 else { XCTFail(); return; }
483 XCTAssert(loadinfo_i["imageLoadAddress"] as? Int == 42 + i)
484 XCTAssert(loadinfo_i["imageUUID"] as! [Int] == uuidarray)
490 func testArrayLoadInfoWayWrongSize() {
491 // test what happens when array element sizes are too short
495 let buffer = NSMutableData(capacity:1000)!
496 var item = kcdata_item()
498 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
501 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
503 item.type = UInt32(KCDATA_TYPE_ARRAY_PAD0)
504 item.flags = UInt64(KCDATA_TYPE_LIBRARY_LOADINFO) << 32 | UInt64(n)
505 item.size = UInt32(n * (MemoryLayout<dyld_uuid_info_32>.size - wrong))
506 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
508 let uuid = NSUUID(uuidString: "de305d54-75b4-431b-adb2-eb6b9e546014")!
511 var payload = dyld_uuid_info_32(imageLoadAddress:UInt32(i+42), imageUUID: nsuuid2uuid_t(uuid))
512 buffer.append(&payload, length:MemoryLayout<dyld_uuid_info_32>.size-wrong)
515 item.type = KCDATA_TYPE_BUFFER_END
518 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
521 guard let dict = try? self.parseBuffer(buffer)
522 else { XCTFail(); return; }
523 XCTAssert((dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info") as! [Any]).count == n)
525 guard let loadinfo = dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info") as? [Any]
526 else { XCTFail(); return; }
527 guard let loadinfo_i = loadinfo[i] as? [AnyHashable:Any]
528 else { XCTFail(); return; }
529 XCTAssert(loadinfo_i["imageLoadAddress"] as? Int == 42 + i)
530 XCTAssert(loadinfo_i["imageUUID"] == nil)
534 func testArrayLoadInfoPreposterouslyWrongSize() {
535 // test what happens when array element sizes are too short
539 let buffer = NSMutableData(capacity:1000)!
540 var item = kcdata_item()
542 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
545 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
547 item.type = UInt32(KCDATA_TYPE_ARRAY_PAD0)
548 item.flags = UInt64(KCDATA_TYPE_LIBRARY_LOADINFO) << 32 | UInt64(n)
549 item.size = UInt32(n * (MemoryLayout<dyld_uuid_info_32>.size - wrong))
550 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
553 var payload = UInt8(42*i)
554 buffer.append(&payload, length:1)
557 item.type = KCDATA_TYPE_BUFFER_END
560 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
563 guard let dict = try? self.parseBuffer(buffer)
564 else { XCTFail(); return; }
565 XCTAssert((dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info") as! [Any]).count == n)
567 guard let loadinfo = dict.value(forKeyPath:"kcdata_crashinfo.dyld_load_info") as? [Any]
568 else { XCTFail(); return; }
569 guard let loadinfo_i = loadinfo[i] as? [AnyHashable:Any]
570 else { XCTFail(); return; }
571 XCTAssert(loadinfo_i["imageLoadAddress"] == nil)
572 XCTAssert(loadinfo_i["imageUUID"] == nil)
578 let buffer = NSMutableData(capacity:1000)!
580 var item = kcdata_item()
582 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
585 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
587 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
589 item.size = UInt32(MemoryLayout<UInt64>.size)
590 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
592 var payload : UInt64 = 42
593 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
595 item.type = KCDATA_TYPE_BUFFER_END
598 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
600 let buffer2 = NSMutableData(capacity:1000)!
602 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
605 buffer2.append(&item, length: MemoryLayout<kcdata_item>.size)
607 item.type = UInt32(KCDATA_TYPE_NESTED_KCDATA)
609 item.size = UInt32(buffer.length)
610 buffer2.append(&item, length: MemoryLayout<kcdata_item>.size)
611 buffer2.append(buffer as Data)
613 item.type = KCDATA_TYPE_BUFFER_END
616 buffer2.append(&item, length: MemoryLayout<kcdata_item>.size)
618 guard let dict2 = try? self.parseBuffer(buffer2)
619 else { XCTFail(); return; }
621 XCTAssert(dict2.value(forKeyPath:"kcdata_crashinfo.kcdata_crashinfo.crashed_threadid") as? Int == 42)
625 func testReadThreadid() {
626 let buffer = NSMutableData(capacity:1000)!
628 var item = kcdata_item()
630 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
633 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
635 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
637 item.size = UInt32(MemoryLayout<UInt64>.size)
638 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
640 var payload : UInt64 = 42
641 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
643 item.type = KCDATA_TYPE_BUFFER_END
646 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
648 guard let dict = try? self.parseBuffer(buffer)
649 else { XCTFail(); return; }
651 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.crashed_threadid") as? Int == 42)
655 func testRepeatedKey() {
656 // test a repeated item of the same key causes error
658 let buffer = NSMutableData(capacity:1000)!
660 var item = kcdata_item()
662 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
665 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
667 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
669 item.size = UInt32(MemoryLayout<UInt64>.size)
670 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
672 var payload : UInt64 = 42
673 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
675 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
677 item.size = UInt32(MemoryLayout<UInt64>.size)
678 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
681 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
683 item.type = KCDATA_TYPE_BUFFER_END
686 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
688 XCTAssert( (try? self.parseBuffer(buffer)) == nil )
692 func testContainer() {
693 let buffer = NSMutableData(capacity:1000)!
695 var item = kcdata_item()
696 var payload64 : UInt64
697 var payload32 : UInt32
699 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
702 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
704 item.type = UInt32(KCDATA_TYPE_CONTAINER_BEGIN)
706 item.size = UInt32(MemoryLayout<UInt32>.size)
707 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
708 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
709 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
711 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
713 item.size = UInt32(MemoryLayout<UInt64>.size)
714 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
716 buffer.append(&payload64, length:MemoryLayout<UInt64>.size)
718 item.type = UInt32(KCDATA_TYPE_CONTAINER_END)
720 item.size = UInt32(MemoryLayout<UInt32>.size)
721 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
722 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
723 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
726 item.type = KCDATA_TYPE_BUFFER_END
729 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
731 guard let dict = try? self.parseBuffer(buffer)
732 else { XCTFail(); return; }
734 XCTAssert(dict.value(forKeyPath: "kcdata_crashinfo.task_snapshots.0.crashed_threadid") as? Int == 42)
737 func testDispatchQueueLabel() {
738 let buffer = NSMutableData(capacity:1000)!
740 var item = kcdata_item()
741 let dql = "houston.we.had.a.problem"
742 var payload32 : UInt32
744 item.type = KCDATA_BUFFER_BEGIN_STACKSHOT
747 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
749 item.type = UInt32(KCDATA_TYPE_CONTAINER_BEGIN)
751 item.size = UInt32(MemoryLayout<UInt32>.size)
752 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
753 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
754 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
756 item.type = UInt32(KCDATA_TYPE_CONTAINER_BEGIN)
758 item.size = UInt32(MemoryLayout<UInt32>.size)
759 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
760 payload32 = UInt32(STACKSHOT_KCCONTAINER_THREAD)
761 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
763 item.type = UInt32(STACKSHOT_KCTYPE_THREAD_DISPATCH_QUEUE_LABEL)
765 item.size = UInt32(dql.utf8.count + 1)
766 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
767 dql.utf8CString.withUnsafeBufferPointer({
768 buffer.append($0.baseAddress!, length:dql.utf8.count + 1)
771 item.type = UInt32(KCDATA_TYPE_CONTAINER_END)
773 item.size = UInt32(MemoryLayout<UInt32>.size)
774 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
775 payload32 = UInt32(STACKSHOT_KCCONTAINER_THREAD)
776 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
778 item.type = UInt32(KCDATA_TYPE_CONTAINER_END)
780 item.size = UInt32(MemoryLayout<UInt32>.size)
781 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
782 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
783 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
786 item.type = KCDATA_TYPE_BUFFER_END
789 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
791 guard let dict = try? self.parseBuffer(buffer)
792 else { XCTFail(); return; }
794 XCTAssert(dict.value(forKeyPath: "kcdata_stackshot.task_snapshots.0.thread_snapshots.0.dispatch_queue_label") as? String == dql)
797 func testRepeatedContainer() {
798 //repeated container of same name and key shoudl fail
800 let buffer = NSMutableData(capacity:1000)!
802 var item = kcdata_item()
803 var payload64 : UInt64
804 var payload32 : UInt32
806 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
809 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
811 item.type = UInt32(KCDATA_TYPE_CONTAINER_BEGIN)
813 item.size = UInt32(MemoryLayout<UInt32>.size)
814 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
815 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
816 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
818 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
820 item.size = UInt32(MemoryLayout<UInt64>.size)
821 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
823 buffer.append(&payload64, length:MemoryLayout<UInt64>.size)
825 item.type = UInt32(KCDATA_TYPE_CONTAINER_END)
827 item.size = UInt32(MemoryLayout<UInt32>.size)
828 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
829 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
830 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
833 item.type = UInt32(KCDATA_TYPE_CONTAINER_BEGIN)
835 item.size = UInt32(MemoryLayout<UInt32>.size)
836 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
837 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
838 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
840 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
842 item.size = UInt32(MemoryLayout<UInt64>.size)
843 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
845 buffer.append(&payload64, length:MemoryLayout<UInt64>.size)
847 item.type = UInt32(KCDATA_TYPE_CONTAINER_END)
849 item.size = UInt32(MemoryLayout<UInt32>.size)
850 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
851 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
852 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
854 item.type = KCDATA_TYPE_BUFFER_END
857 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
859 XCTAssert( (try? self.parseBuffer(buffer)) == nil )
863 func testContainerNoEnd() {
864 let buffer = NSMutableData(capacity:1000)!
866 var item = kcdata_item()
867 var payload64 : UInt64
868 var payload32 : UInt32
870 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
873 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
875 item.type = UInt32(KCDATA_TYPE_CONTAINER_BEGIN)
877 item.size = UInt32(MemoryLayout<UInt32>.size)
878 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
879 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
880 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
882 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
884 item.size = UInt32(MemoryLayout<UInt64>.size)
885 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
887 buffer.append(&payload64, length:MemoryLayout<UInt64>.size)
889 item.type = KCDATA_TYPE_BUFFER_END
892 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
894 XCTAssert( (try? self.parseBuffer(buffer)) == nil )
897 func testContainerNoEndNoEnd() {
898 let buffer = NSMutableData(capacity:1000)!
900 var item = kcdata_item()
901 var payload64 : UInt64
902 var payload32 : UInt32
904 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
907 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
909 item.type = UInt32(KCDATA_TYPE_CONTAINER_BEGIN)
911 item.size = UInt32(MemoryLayout<UInt32>.size)
912 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
913 payload32 = UInt32(STACKSHOT_KCCONTAINER_TASK)
914 buffer.append(&payload32, length:MemoryLayout<UInt32>.size)
916 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
918 item.size = UInt32(MemoryLayout<UInt64>.size)
919 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
921 buffer.append(&payload64, length:MemoryLayout<UInt64>.size)
923 XCTAssert( (try? self.parseBuffer(buffer)) == nil )
929 let buffer = NSMutableData(capacity:1000)!
931 var item = kcdata_item()
933 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
936 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
938 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
940 item.size = UInt32(MemoryLayout<UInt64>.size)
941 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
943 var payload : UInt64 = 42
944 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
946 XCTAssert( (try? self.parseBuffer(buffer)) == nil )
950 func testCrazySize() {
951 let buffer = NSMutableData(capacity:1000)!
953 var item = kcdata_item()
955 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
958 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
960 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
963 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
965 var payload : UInt64 = 42
966 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
968 item.type = KCDATA_TYPE_BUFFER_END
971 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
973 XCTAssert( (try? self.parseBuffer(buffer)) == nil )
976 func testReadRepeatedArray() {
977 // repeated arrays should be concatenated
980 let buffer = NSMutableData(capacity:1000)!
982 var item = kcdata_item()
984 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
987 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
989 item.type = UInt32(KCDATA_TYPE_ARRAY)
990 item.flags = UInt64(TASK_CRASHINFO_CRASHED_THREADID) << 32 | UInt64(n)
991 item.size = UInt32(n * MemoryLayout<UInt64>.size)
992 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
995 var payload : UInt64 = UInt64(i)
996 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
999 item.type = UInt32(KCDATA_TYPE_ARRAY)
1000 item.flags = UInt64(TASK_CRASHINFO_CRASHED_THREADID) << 32 | UInt64(n)
1001 item.size = UInt32(n * MemoryLayout<UInt64>.size)
1002 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1005 var payload : UInt64 = UInt64(i)
1006 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
1009 item.type = KCDATA_TYPE_BUFFER_END
1012 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1014 guard let dict = try? self.parseBuffer(buffer)
1015 else { XCTFail(); return }
1017 XCTAssert( 2*n == (dict.value(forKeyPath:"kcdata_crashinfo.crashed_threadid") as! [Any]).count)
1019 let x = dict["kcdata_crashinfo"] as? NSDictionary
1020 let y = x?["crashed_threadid"] as? NSArray
1021 XCTAssert((y?[i]) as? Int == i % n)
1025 func testReadThreadidArray(n : Int, pad : Int) {
1026 let buffer = NSMutableData(capacity:1000)!
1028 var item = kcdata_item()
1030 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
1033 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1035 item.type = UInt32(KCDATA_TYPE_ARRAY)
1036 item.flags = UInt64(TASK_CRASHINFO_CRASHED_THREADID) << 32 | UInt64(n)
1037 item.size = UInt32(n * MemoryLayout<UInt64>.size + pad)
1038 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1041 var payload : UInt64 = UInt64(i)
1042 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
1046 var payload : UInt8 = 0
1047 buffer.append(&payload, length:1)
1050 item.type = KCDATA_TYPE_BUFFER_END
1053 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1055 guard let dict = try? self.parseBuffer(buffer)
1056 else { XCTFail(); return; }
1058 XCTAssert( n == (dict.value(forKeyPath:"kcdata_crashinfo.crashed_threadid") as! [Any]).count)
1061 let x = dict["kcdata_crashinfo"] as? NSDictionary
1062 let y = x?["crashed_threadid"] as? NSArray
1063 XCTAssert((y?[i]) as? Int == i)
1068 func testReadThreadidArray() {
1069 // test that we can correctly read old arrays with a variety of sizes and paddings
1070 self.testReadThreadidArray(n: 0, pad:0)
1073 self.testReadThreadidArray(n: n, pad:pad)
1078 func testReadThreadidArrayWrongSize1() {
1079 /// for old style arrays, if the element size is determined by the type. If the array of that size element at the given count doesn't fit, then parsing should fail
1083 let buffer = NSMutableData(capacity:1000)!
1085 var item = kcdata_item()
1087 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
1090 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1092 item.type = UInt32(KCDATA_TYPE_ARRAY)
1093 item.flags = UInt64(TASK_CRASHINFO_CRASHED_THREADID) << 32 | UInt64(n)
1094 item.size = UInt32(4)
1095 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1097 var payload : UInt32 = UInt32(42)
1098 buffer.append(&payload, length:MemoryLayout<UInt32>.size)
1100 item.type = KCDATA_TYPE_BUFFER_END
1103 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1105 XCTAssert( (try? self.parseBuffer(buffer)) == nil )
1108 func testReadThreadidArrayWrongSize5() {
1109 /// if the count is bigger than the buffer, parsing will just fail
1113 let buffer = NSMutableData(capacity:1000)!
1115 var item = kcdata_item()
1117 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
1120 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1122 item.type = UInt32(KCDATA_TYPE_ARRAY)
1123 item.flags = UInt64(TASK_CRASHINFO_CRASHED_THREADID) << 32 | UInt64(n)
1124 item.size = UInt32(4)
1125 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1127 var payload : UInt32 = UInt32(42)
1128 buffer.append(&payload, length:MemoryLayout<UInt32>.size)
1130 item.type = KCDATA_TYPE_BUFFER_END
1133 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1135 XCTAssert( (try? self.parseBuffer(buffer)) == nil )
1139 func testReadThreadidArrayPaddedSize() {
1140 // test that we can tolerate a little padding at the end of an array
1143 let buffer = NSMutableData(capacity:1000)!
1145 var item = kcdata_item()
1147 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
1150 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1152 item.type = UInt32(KCDATA_TYPE_ARRAY)
1153 item.flags = UInt64(TASK_CRASHINFO_CRASHED_THREADID) << 32 | UInt64(n)
1154 item.size = UInt32(n * MemoryLayout<UInt64>.size) + 1
1155 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1158 var payload : UInt64 = UInt64(i)
1159 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
1161 var payload : UInt8 = 0
1162 buffer.append(&payload, length:1)
1164 item.type = KCDATA_TYPE_BUFFER_END
1167 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1169 guard let dict = try? self.parseBuffer(buffer)
1170 else { XCTFail(); return; }
1172 XCTAssert( n == (dict.value(forKeyPath:"kcdata_crashinfo.crashed_threadid") as! [Any]).count)
1174 let x = dict["kcdata_crashinfo"] as? NSDictionary
1175 let y = x?["crashed_threadid"] as? NSArray
1176 XCTAssert((y?[i]) as? Int == i)
1180 func testReadThreadidArrayPaddedSize15() {
1181 // test that we can tolerate a little padding at the end of an array
1184 let buffer = NSMutableData(capacity:1000)!
1186 var item = kcdata_item()
1188 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
1191 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1193 item.type = UInt32(KCDATA_TYPE_ARRAY)
1194 item.flags = UInt64(TASK_CRASHINFO_CRASHED_THREADID) << 32 | UInt64(n)
1195 item.size = UInt32(n * MemoryLayout<UInt64>.size) + 15
1196 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1199 var payload : UInt64 = UInt64(i)
1200 buffer.append(&payload, length:MemoryLayout<UInt64>.size)
1203 var payload : UInt8 = 0
1204 buffer.append(&payload, length:1)
1207 item.type = KCDATA_TYPE_BUFFER_END
1210 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1212 guard let dict = try? self.parseBuffer(buffer)
1213 else { XCTFail(); return; }
1215 XCTAssert( n == (dict.value(forKeyPath:"kcdata_crashinfo.crashed_threadid") as! [Any]).count)
1217 let x = dict["kcdata_crashinfo"] as? NSDictionary
1218 let y = x?["crashed_threadid"] as? NSArray
1219 XCTAssert((y?[i]) as? Int == i)
1224 func testReadThreadidWrongSize(size : UInt32) {
1225 let buffer = NSMutableData(capacity:1000)!
1227 var item = kcdata_item()
1229 item.type = KCDATA_BUFFER_BEGIN_CRASHINFO
1232 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1234 item.type = UInt32(TASK_CRASHINFO_CRASHED_THREADID)
1237 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1239 var payload : UInt64 = 42
1240 buffer.append(&payload, length:Int(size))
1242 item.type = KCDATA_TYPE_BUFFER_END
1245 buffer.append(&item, length: MemoryLayout<kcdata_item>.size)
1247 guard let dict = try? self.parseBuffer(buffer)
1248 else { XCTFail(); return; }
1250 XCTAssert(dict.value(forKeyPath:"kcdata_crashinfo.crashed_threadid") == nil)
1253 func testReadThreadidWrongSize0() {
1254 self.testReadThreadidWrongSize(size: 0)
1257 func testReadThreadidWrongSize7() {
1258 self.testReadThreadidWrongSize(size: 7)
1261 func dataWithResource(_ name:String) -> NSData? {
1262 guard let filename = Bundle(for: self.classForCoder).path(forResource: name, ofType: nil)
1264 return NSData(contentsOfFile:filename)!
1267 func testSampleStackshot(_ name : String) {
1268 // check that we agree with sample file
1270 guard let sampledata = self.dataWithResource(name)
1271 else { XCTFail("failed to open bundle resource named " + name); return }
1272 var dict : NSDictionary?
1274 dict = try? self.parseBuffer(sampledata) as NSDictionary
1277 if let decoded = NSData(base64Encoded: sampledata as Data, options:.ignoreUnknownCharacters) {
1278 dict = try? self.parseBuffer(decoded) as NSDictionary
1283 if let decompressed = try? decompress(sampledata) {
1284 dict = try? self.parseBuffer(decompressed) as NSDictionary
1292 guard let plistdata = self.dataWithResource(name + ".plist.gz") ??
1293 self.dataWithResource(name + ".plist")
1294 else {XCTFail(); return}
1296 var opt_dict2 = try? PropertyListSerialization.propertyList(from: plistdata as Data, options: [], format: nil)
1297 if opt_dict2 == nil {
1298 opt_dict2 = try? PropertyListSerialization.propertyList(from:decompress(plistdata) as Data, options:[], format: nil)
1300 guard let dict2 = opt_dict2
1301 else { XCTFail(); return}
1303 XCTAssertEqual(dict, dict2 as! NSDictionary);
1305 //XCTAssert(dict == dict2 as? NSDictionary)
1307 // check that we agree with python
1311 let kcdatapy = Bundle(for: self.classForCoder).path(forResource: "kcdata.py", ofType: nil)
1313 let task = Process()
1314 task.launchPath = kcdatapy
1315 task.arguments = ["-p",
1316 Bundle(for:self.classForCoder).path(forResource: name, ofType: nil)!]
1318 task.standardOutput = pipe
1321 let data = pipe.fileHandleForReading.readDataToEndOfFile()
1323 guard let dict3 = try? PropertyListSerialization.propertyList(from:data, options:[], format: nil) as? NSDictionary
1324 else { XCTFail(); return }
1326 XCTAssert(dict == dict3)
1331 func testSampleStackshot() {
1332 self.testSampleStackshot("stackshot-sample")
1335 func testSampleStackshotOldArrays() {
1336 self.testSampleStackshot("stackshot-sample-old-arrays")
1339 func testSampleStackshotNewArrays() {
1340 self.testSampleStackshot("stackshot-sample-new-arrays")
1343 func testSampleDeltaStackshotOldArrays() {
1344 self.testSampleStackshot("delta-stackshot-sample-old-arrays")
1347 func testSampleDeltaStackshotNewArrays() {
1348 self.testSampleStackshot("delta-stackshot-sample-new-arrays")
1351 func testSampleCorpse() {
1352 self.testSampleStackshot("corpse-sample")
1355 func testSampleStackshotTailspin() {
1356 self.testSampleStackshot("stackshot-sample-tailspin")
1359 func testSampleStackshotTailspin2() {
1360 self.testSampleStackshot("stackshot-sample-tailspin-2")
1363 func testSampleExitReason() {
1364 self.testSampleStackshot("exitreason-sample")
1367 func testSampleThreadT() {
1368 self.testSampleStackshot("stackshot-sample-ths-thread-t")
1371 func testSampleCpuTimes() {
1372 self.testSampleStackshot("stackshot-sample-cputime")
1375 func testSampleDuration() {
1376 self.testSampleStackshot("stackshot-sample-duration")
1379 func testSampleNested() {
1380 self.testSampleStackshot("nested-sample")
1383 func testSampleTermWithReason() {
1384 self.testSampleStackshot("test-twr-sample")
1387 func testSampleCorpseTermWithReason() {
1388 self.testSampleStackshot("corpse-twr-sample")
1391 func testSampleCorpseTermWithReasonV2() {
1392 self.testSampleStackshot("corpse-twr-sample-v2")
1395 func testSampleCodesigningExitReason() {
1396 self.testSampleStackshot("exitreason-codesigning")
1399 func testSampleThreadGroups() {
1400 self.testSampleStackshot("stackshot-sample-thread-groups")
1403 func testSampleThreadGroupsFlags() {
1404 self.testSampleStackshot("stackshot-sample-thread-groups-flags")
1407 func testSampleCoalitions() {
1408 self.testSampleStackshot("stackshot-sample-coalitions")
1411 func testSampleTurnstileInfo() {
1412 self.testSampleStackshot("stackshot-sample-turnstileinfo")
1415 func testStackshotSharedcacheV2() {
1416 self.testSampleStackshot("stackshot-sample-sharedcachev2")
1419 func testStackshotFaultStats() {
1420 self.testSampleStackshot("stackshot-fault-stats")
1423 func testStackshotwithKCID() {
1424 self.testSampleStackshot("stackshot-with-kcid")
1427 func testXNUPostTestConfig() {
1428 self.testSampleStackshot("xnupost_testconfig-sample")
1431 func testStackshotWithWaitinfo() {
1432 self.testSampleStackshot("stackshot-with-waitinfo")
1435 func testStackshotWithThreadPolicy() {
1436 self.testSampleStackshot("stackshot-sample-thread-policy")
1439 func testDeltaStackshotWithThreadPolicy() {
1440 self.testSampleStackshot("stackshot-sample-delta-thread-policy")
1443 func testStackshotWithInstrsCycles() {
1444 self.testSampleStackshot("stackshot-sample-instrs-cycles")
1447 func testStackshotWithStacktop() {
1448 self.testSampleStackshot("stackshot-sample-stacktop")
1451 func testStackshotWithASID() {
1452 self.testSampleStackshot("stackshot-sample-asid")
1455 func testStackshotWithPageTables() {
1456 self.testSampleStackshot("stackshot-sample-asid-pagetable")
1459 func testStackshotCPUTimes() {
1460 self.testSampleStackshot("stackshot-sample-cpu-times")
1463 func testStackshotWithSharedCacheLayout() {
1464 self.testSampleStackshot("stackshot-with-shared-cache-layout")
1467 func testStackshotDispatchQueueLabel() {
1468 self.testSampleStackshot("stackshot-sample-dispatch-queue-label")
1471 func testTrivial() {