feat(storage): 新增只读 SMART 辅助服务与寿命通电详情
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import Foundation
|
||||
|
||||
@main struct DiskHealthChecks {
|
||||
static func main() throws {
|
||||
func report(used: Any? = 2, low: Any? = 1121, high: Any? = 0, stores: Int = 1) -> Data {
|
||||
var smart: [String: Any] = [:]
|
||||
smart["PERCENTAGE_USED"] = used
|
||||
smart["POWER_ON_HOURS_0"] = low
|
||||
smart["POWER_ON_HOURS_1"] = high
|
||||
return try! PropertyListSerialization.data(fromPropertyList: [
|
||||
"SMARTDeviceSpecificKeysMayVaryNotGuaranteed": smart,
|
||||
"APFSPhysicalStores": Array(repeating: ["APFSPhysicalStore": "disk0s2"], count: stores)
|
||||
], format: .xml, options: 0)
|
||||
}
|
||||
let valid = DiskHealthReport.parse(report())!
|
||||
precondition(valid.remainingLife == 0.98 && valid.powerOnHours == 1121)
|
||||
precondition(DiskHealthReport.parse(report(used: 102))?.remainingLife == 0)
|
||||
precondition(DiskHealthReport.parse(report(used: -1))?.remainingLife == nil)
|
||||
precondition(DiskHealthReport.parse(report(used: true))?.remainingLife == nil)
|
||||
precondition(DiskHealthReport.parse(report(used: 256))?.remainingLife == nil)
|
||||
precondition(DiskHealthReport.parse(report(used: nil))?.powerOnHours == 1121)
|
||||
precondition(DiskHealthReport.parse(report(high: 1))?.powerOnHours == nil)
|
||||
precondition(DiskHealthReport.parse(report(low: -1))?.powerOnHours == nil)
|
||||
precondition(DiskHealthReport.parse(report(stores: 2)) == nil)
|
||||
precondition(DiskHealthReport.parse(report(used: nil, low: nil, high: nil)) == nil)
|
||||
precondition(DiskHealthReport.parse(Data("bad plist".utf8)) == nil)
|
||||
print("PASS: disk endurance, missing SMART, invalid counters, overflow and multi-store boundaries")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user