DispatchTime.uptimeNanoseconds has an incorrect return value

Originator:micron
Number:rdar://30332506 Date Originated:02-Feb-2017
Status: Resolved:
Product:iOS + SDK Product Version:10.2.1
Classification: Reproducible:Always
 
DispatchTime.uptimeNanoseconds appears to be returning the dispatch_time_t value returned from DispatchTime.rawValue. dispatch_time_t is not necessarily measured in nanoseconds. This causes statements such as

```
DispatchTime(uptimeNanoseconds: DispatchTime.now().uptimeNanoseconds + offset)
```

to return unexpected values.

Steps to Reproduce:
Run the following test both in an iOS simulator and on an iOS device:

```
        let seconds = 1
        let now = DispatchTime.now()
        let oneSecondFromNow = now + .seconds(seconds)
        print("current dispatch time: \(now)")
        print("rawValue measured: \(oneSecondFromNow.rawValue - now.rawValue) dispatch_time_t in \(seconds) seconds")
        print("uptimeNanoseconds measured: \(oneSecondFromNow.uptimeNanoseconds - now.uptimeNanoseconds) nanoseconds in \(seconds) seconds")
        print("NSEC_PER_SEC = \(NSEC_PER_SEC)")
        XCTAssertEqual(oneSecondFromNow.uptimeNanoseconds, now.uptimeNanoseconds + NSEC_PER_SEC)
```

Expected Results:
As seen on an iPhone 6 simulator:

current dispatch time: DispatchTime(rawValue: 125467249779612)
rawValue measured: 1000000000 dispatch_time_t in 1 seconds
uptimeNanoseconds measured: 1000000000 nanoseconds in 1 seconds
NSEC_PER_SEC = 1000000000

Test passes since oneSecondFromNow.uptimeNanoseconds == 125468249779612 == now.uptimeNanoseconds + NSEC_PER_SEC

Actual Results:
Seen on an iPhone 6:

current dispatch time: DispatchTime(rawValue: 4710219239612)
rawValue measured: 24000000 dispatch_time_t in 1 seconds
uptimeNanoseconds measured: 24000000 nanoseconds in 1 seconds
NSEC_PER_SEC = 1000000000
XCTAssertEqual failed: ("4710243239612") is not equal to ("4711219239612")

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!