Skip to content

Commit ba02fc8

Browse files
committed
Update test cases for thread state command
1 parent c0c78d2 commit ba02fc8

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

Tests/MachOKitTests/MachOFilePrintTests.swift

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -458,29 +458,26 @@ extension MachOFilePrintTests {
458458
}
459459

460460
func testThreadCommand() {
461-
let path = "/usr/local/bin/texindex" // has thread command
461+
let path = "/cores/core.2627" // has thread command
462462
let url = URL(fileURLWithPath: path)
463463
guard let machO = try? MachOFile(url: url) else { return }
464464

465465
let commands = Array(machO.loadCommands.infos(of: LoadCommand.thread))
466466
+ Array(machO.loadCommands.infos(of: LoadCommand.unixthread))
467467

468+
let cpuType = machO.header.cpuType!
469+
468470
for command in commands {
471+
let flavor = command.flavor(
472+
in: machO,
473+
cpuType: cpuType
474+
)
469475
print("Flavor:",
470-
command.flavor(
471-
in: machO,
472-
cpuType: machO.header.cpuType!
473-
)?.description ?? "unknown"
476+
flavor?.description ?? "unknown"
474477
)
475478
print("Count:", command.count(in: machO) ?? 0)
476-
if let state = command.stateData(in: machO) {
477-
print(
478-
"State:",
479-
state.withUnsafeBytes {
480-
[UInt64]($0.bindMemory(to: UInt64.self))
481-
}.map { "0x" + String($0, radix: 16) }
482-
.joined(separator: ", ")
483-
)
479+
if let state = command.state(in: machO, cpuType: cpuType) {
480+
print("State:", state)
484481
}
485482
}
486483
}

Tests/MachOKitTests/MachOPrintTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -392,22 +392,22 @@ extension MachOPrintTests {
392392
let commands = Array(machO.loadCommands.infos(of: LoadCommand.thread))
393393
+ Array(machO.loadCommands.infos(of: LoadCommand.unixthread))
394394

395+
let cpuType = machO.header.cpuType!
396+
395397
for command in commands {
398+
let flavor = command.flavor(
399+
cmdsStart: machO.cmdsStartPtr,
400+
cpuType: cpuType
401+
)
396402
print("Flavor:",
397-
command.flavor(
398-
cmdsStart: machO.cmdsStartPtr,
399-
cpuType: machO.header.cpuType!
400-
)?.description ?? "unknown"
403+
flavor?.description ?? "unknown"
401404
)
402405
print("Count:", command.count(cmdsStart: machO.cmdsStartPtr) ?? 0)
403-
if let state = command.stateData(cmdsStart: machO.cmdsStartPtr) {
404-
print(
405-
"State:",
406-
state.withUnsafeBytes {
407-
[UInt64]($0.bindMemory(to: UInt64.self))
408-
}.map { "0x" + String($0, radix: 16) }
409-
.joined(separator: ", ")
410-
)
406+
if let state = command.state(
407+
cmdsStart: machO.cmdsStartPtr,
408+
cpuType: cpuType
409+
) {
410+
print("State:", state)
411411
}
412412
}
413413
}

0 commit comments

Comments
 (0)