OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 23 matching lines...) Expand all Loading... |
34 uint64_t now = start; | 34 uint64_t now = start; |
35 for (size_t iteration = 0; iteration < 10; ++iteration) { | 35 for (size_t iteration = 0; iteration < 10; ++iteration) { |
36 uint64_t last = now; | 36 uint64_t last = now; |
37 now = ClockMonotonicNanoseconds(); | 37 now = ClockMonotonicNanoseconds(); |
38 | 38 |
39 // Use EXPECT_GE instead of EXPECT_GT, because there are no guarantees about | 39 // Use EXPECT_GE instead of EXPECT_GT, because there are no guarantees about |
40 // the clock’s resolution. | 40 // the clock’s resolution. |
41 EXPECT_GE(now, last); | 41 EXPECT_GE(now, last); |
42 } | 42 } |
43 | 43 |
| 44 #if !defined(OS_WIN) // No SleepNanoseconds implemented on Windows. |
44 // SleepNanoseconds() should sleep for at least the value of the clock’s | 45 // SleepNanoseconds() should sleep for at least the value of the clock’s |
45 // resolution, so the clock’s value should definitely increase after a sleep. | 46 // resolution, so the clock’s value should definitely increase after a sleep. |
46 // EXPECT_GT can be used instead of EXPECT_GE after the sleep. | 47 // EXPECT_GT can be used instead of EXPECT_GE after the sleep. |
47 SleepNanoseconds(1); | 48 SleepNanoseconds(1); |
48 now = ClockMonotonicNanoseconds(); | 49 now = ClockMonotonicNanoseconds(); |
49 EXPECT_GT(now, start); | 50 EXPECT_GT(now, start); |
| 51 #endif // OS_WIN |
50 } | 52 } |
51 | 53 |
| 54 #if !defined(OS_WIN) // No SleepNanoseconds implemented on Windows. |
| 55 |
52 void TestSleepNanoseconds(uint64_t nanoseconds) { | 56 void TestSleepNanoseconds(uint64_t nanoseconds) { |
53 uint64_t start = ClockMonotonicNanoseconds(); | 57 uint64_t start = ClockMonotonicNanoseconds(); |
54 | 58 |
55 SleepNanoseconds(nanoseconds); | 59 SleepNanoseconds(nanoseconds); |
56 | 60 |
57 uint64_t end = ClockMonotonicNanoseconds(); | 61 uint64_t end = ClockMonotonicNanoseconds(); |
58 uint64_t diff = end - start; | 62 uint64_t diff = end - start; |
59 | 63 |
60 // |nanoseconds| is the lower bound for the actual amount of time spent | 64 // |nanoseconds| is the lower bound for the actual amount of time spent |
61 // sleeping. | 65 // sleeping. |
(...skipping 18 matching lines...) Expand all Loading... |
80 | 84 |
81 for (size_t index = 0; index < arraysize(kTestData); ++index) { | 85 for (size_t index = 0; index < arraysize(kTestData); ++index) { |
82 const uint64_t nanoseconds = kTestData[index]; | 86 const uint64_t nanoseconds = kTestData[index]; |
83 SCOPED_TRACE( | 87 SCOPED_TRACE( |
84 base::StringPrintf("index %zu, nanoseconds %llu", index, nanoseconds)); | 88 base::StringPrintf("index %zu, nanoseconds %llu", index, nanoseconds)); |
85 | 89 |
86 TestSleepNanoseconds(nanoseconds); | 90 TestSleepNanoseconds(nanoseconds); |
87 } | 91 } |
88 } | 92 } |
89 | 93 |
| 94 #endif // OS_WIN |
| 95 |
90 } // namespace | 96 } // namespace |
91 } // namespace test | 97 } // namespace test |
92 } // namespace crashpad | 98 } // namespace crashpad |
OLD | NEW |