|
9 | 9 |
|
10 | 10 | // REQUIRES: objc_interop
|
11 | 11 |
|
12 |
| -// FIXME: rdar://34751238 DispatchTime.addSubtract test traps |
13 |
| -// XFAIL: CPU=armv7 || CPU=armv7k || CPU=armv7s || CPU=arm64 |
14 |
| - |
15 |
| - |
16 | 12 | import Dispatch
|
17 | 13 | import Foundation
|
18 | 14 | import StdlibUnittest
|
@@ -119,6 +115,31 @@ DispatchAPI.test("DispatchTime comparisons") {
|
119 | 115 | }
|
120 | 116 | }
|
121 | 117 |
|
| 118 | +DispatchAPI.test("DispatchTime.create") { |
| 119 | + var info = mach_timebase_info_data_t(numer: 1, denom: 1) |
| 120 | + mach_timebase_info(&info) |
| 121 | + let scales = info.numer != info.denom |
| 122 | + |
| 123 | + // Simple tests for non-overflow behavior |
| 124 | + var time = DispatchTime(uptimeNanoseconds: 0) |
| 125 | + expectEqual(time.uptimeNanoseconds, 0) |
| 126 | + |
| 127 | + time = DispatchTime(uptimeNanoseconds: 15 * NSEC_PER_SEC) |
| 128 | + expectEqual(time.uptimeNanoseconds, 15 * NSEC_PER_SEC) |
| 129 | + |
| 130 | + // On platforms where the timebase scale is not 1, the next two cases |
| 131 | + // overflow and become DISPATCH_TIME_FOREVER (UInt64.max) instead of trapping. |
| 132 | + time = DispatchTime(uptimeNanoseconds: UInt64.max - 1) |
| 133 | + expectEqual(time.uptimeNanoseconds, scales ? UInt64.max : UInt64.max - UInt64(1)) |
| 134 | + |
| 135 | + time = DispatchTime(uptimeNanoseconds: UInt64.max / 2) |
| 136 | + expectEqual(time.uptimeNanoseconds, scales ? UInt64.max : UInt64.max / 2) |
| 137 | + |
| 138 | + // UInt64.max must always be returned as UInt64.max. |
| 139 | + time = DispatchTime(uptimeNanoseconds: UInt64.max) |
| 140 | + expectEqual(time.uptimeNanoseconds, UInt64.max) |
| 141 | +} |
| 142 | + |
122 | 143 | DispatchAPI.test("DispatchTime.addSubtract") {
|
123 | 144 | var then = DispatchTime.now() + Double.infinity
|
124 | 145 | expectEqual(DispatchTime.distantFuture, then)
|
|
0 commit comments