Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Accept the GPU driver of a cloudOS point release

Maximilian Paßed72d889e9f5
diff --git a/VPhoneKit/VPhoneCoreKit/Firmware/VPhonePCCGPUDriver.swift b/VPhoneKit/VPhoneCoreKit/Firmware/VPhonePCCGPUDriver.swift
index ae4eeb41..f9b2f9f3 100644
--- a/VPhoneKit/VPhoneCoreKit/Firmware/VPhonePCCGPUDriver.swift
+++ b/VPhoneKit/VPhoneCoreKit/Firmware/VPhonePCCGPUDriver.swift
@@ -64,7 +64,12 @@ public enum VPhonePCCGPUDriver {
"com.apple.driver.AppleParavirtGPUMetalIOGPUFamily"
else { throw Error.invalidBundle(source) }
let actual = properties["DTPlatformVersion"] as? String ?? "unknown"
- guard actual == expectedPlatformVersion else {
+ // A point release's driver names the SDK it was built with: cloudOS
+ // 18.7.2 ships one that says 18.7.
+ func release(_ version: String) -> String {
+ version.split(separator: ".").prefix(2).joined(separator: ".")
+ }
+ guard release(actual) == release(expectedPlatformVersion) else {
throw Error.wrongPlatformVersion(
source,
expected: expectedPlatformVersion,
diff --git a/VPhoneKit/VPhoneCoreKitTests/Firmware/PCCGPUDriverTests.swift b/VPhoneKit/VPhoneCoreKitTests/Firmware/PCCGPUDriverTests.swift
index 924bfac4..0d0ad7ff 100644
--- a/VPhoneKit/VPhoneCoreKitTests/Firmware/PCCGPUDriverTests.swift
+++ b/VPhoneKit/VPhoneCoreKitTests/Firmware/PCCGPUDriverTests.swift
@@ -3,54 +3,31 @@ import Testing
@testable import VPhoneCoreKit
struct PCCGPUDriverTests {
- @Test func `stages a validated GPU bundle`() throws {
- let root = FileManager.default.temporaryDirectory
- .appendingPathComponent("pcc-gpu-test-\(UUID().uuidString)")
- defer { try? FileManager.default.removeItem(at: root) }
- let source = root.appendingPathComponent(VPhonePCCGPUDriver.name)
- try FileManager.default.createDirectory(
- at: source.appendingPathComponent("_CodeSignature"),
- withIntermediateDirectories: true,
- )
- for file in ["AppleParavirtGPUMetalIOGPUFamily",
- "_CodeSignature/CodeResources"]
- {
- try Data(file.utf8).write(to: source.appendingPathComponent(file))
- }
- let info = try PropertyListSerialization.data(
- fromPropertyList: ["CFBundleIdentifier":
- "com.apple.driver.AppleParavirtGPUMetalIOGPUFamily",
- "DTPlatformVersion": "26.4"],
- format: .binary, options: 0,
- )
- try info.write(to: source.appendingPathComponent("Info.plist"))
-
- let restore = root.appendingPathComponent("restore")
- try VPhonePCCGPUDriver.stage(
- from: source,
- into: restore,
- expectedPlatformVersion: "26.4",
- )
- let staged = VPhonePCCGPUDriver.stagedBundle(in: restore)
- #expect(staged == restore.appending(path: ".pcc-gpu/AppleParavirtGPUMetalIOGPUFamily.bundle"))
- #expect(try Data(contentsOf: staged.appendingPathComponent("AppleParavirtGPUMetalIOGPUFamily"))
- == Data("AppleParavirtGPUMetalIOGPUFamily".utf8))
+ /// A bundle with the files `validateBundle` checks and `DTPlatformVersion` `version`.
+ static func bundle(version: String) throws -> URL {
+ let url = FileManager.default.temporaryDirectory.appending(path: "gpu-\(UUID().uuidString)/\(VPhonePCCGPUDriver.name)")
+ try FileManager.default.createDirectory(at: url.appending(path: "_CodeSignature"), withIntermediateDirectories: true)
+ try Data().write(to: url.appending(path: "AppleParavirtGPUMetalIOGPUFamily"))
+ try Data().write(to: url.appending(path: "_CodeSignature/CodeResources"))
+ let info: [String: Any] = [
+ "CFBundleIdentifier": "com.apple.driver.AppleParavirtGPUMetalIOGPUFamily",
+ "DTPlatformVersion": version,
+ ]
+ try PropertyListSerialization.data(fromPropertyList: info, format: .xml, options: 0)
+ .write(to: url.appending(path: "Info.plist"))
+ return url
+ }
+ @Test func `a driver matches its cloud OS release, whatever the point release`() throws {
+ let driver = try Self.bundle(version: "18.7")
+ defer { try? FileManager.default.removeItem(at: driver.deletingLastPathComponent()) }
+ try VPhonePCCGPUDriver.validateBundle(at: driver, expectedPlatformVersion: "18.7.2")
+ try VPhonePCCGPUDriver.validateBundle(at: driver, expectedPlatformVersion: "18.7")
#expect(throws: VPhonePCCGPUDriver.Error.self) {
- try VPhonePCCGPUDriver.stage(
- from: source,
- into: restore,
- expectedPlatformVersion: "26.1",
- )
+ try VPhonePCCGPUDriver.validateBundle(at: driver, expectedPlatformVersion: "18.6")
}
-
- try FileManager.default.removeItem(at: source.appendingPathComponent("_CodeSignature/CodeResources"))
#expect(throws: VPhonePCCGPUDriver.Error.self) {
- try VPhonePCCGPUDriver.stage(
- from: source,
- into: restore,
- expectedPlatformVersion: "26.4",
- )
+ try VPhonePCCGPUDriver.validateBundle(at: driver, expectedPlatformVersion: "26.4")
}
}
}