Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: util/misc/clock_test.cc

Issue 640373003: util_test Clock.SleepNanoseconds: don’t set an upper bound for the amount of time spent sleeping (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 SleepNanoseconds(nanoseconds); 55 SleepNanoseconds(nanoseconds);
56 56
57 uint64_t end = ClockMonotonicNanoseconds(); 57 uint64_t end = ClockMonotonicNanoseconds();
58 uint64_t diff = end - start; 58 uint64_t diff = end - start;
59 59
60 // |nanoseconds| is the lower bound for the actual amount of time spent 60 // |nanoseconds| is the lower bound for the actual amount of time spent
61 // sleeping. 61 // sleeping.
62 EXPECT_GE(diff, nanoseconds); 62 EXPECT_GE(diff, nanoseconds);
63 63
64 // It’s difficult to set an upper bound for the time spent sleeping. Allow 64 // It’s difficult to set an upper bound for the time spent sleeping, and
65 // sleeps twice as long as requested, or sleeps a millisecond longer than 65 // attempting to do so results in a flaky test.
66 // requested, whichever is larger. This is quite a lot of slop, but the
67 // alternative would be test flakiness.
68 uint64_t slop = std::max(static_cast<uint64_t>(1E6), nanoseconds);
69 EXPECT_LE(diff, nanoseconds + slop);
70 } 66 }
71 67
72 TEST(Clock, SleepNanoseconds) { 68 TEST(Clock, SleepNanoseconds) {
73 const uint64_t kTestData[] = { 69 const uint64_t kTestData[] = {
74 0, 70 0,
75 1, 71 1,
76 static_cast<uint64_t>(1E3), // 1 microsecond 72 static_cast<uint64_t>(1E3), // 1 microsecond
77 static_cast<uint64_t>(1E4), // 10 microseconds 73 static_cast<uint64_t>(1E4), // 10 microseconds
78 static_cast<uint64_t>(1E5), // 100 microseconds 74 static_cast<uint64_t>(1E5), // 100 microseconds
79 static_cast<uint64_t>(1E6), // 1 millisecond 75 static_cast<uint64_t>(1E6), // 1 millisecond
80 static_cast<uint64_t>(1E7), // 10 milliseconds 76 static_cast<uint64_t>(1E7), // 10 milliseconds
81 static_cast<uint64_t>(2E7), // 20 milliseconds 77 static_cast<uint64_t>(2E7), // 20 milliseconds
82 static_cast<uint64_t>(5E7), // 50 milliseconds 78 static_cast<uint64_t>(5E7), // 50 milliseconds
83 }; 79 };
84 80
85 for (size_t index = 0; index < arraysize(kTestData); ++index) { 81 for (size_t index = 0; index < arraysize(kTestData); ++index) {
86 const uint64_t nanoseconds = kTestData[index]; 82 const uint64_t nanoseconds = kTestData[index];
87 SCOPED_TRACE( 83 SCOPED_TRACE(
88 base::StringPrintf("index %zu, nanoseconds %llu", index, nanoseconds)); 84 base::StringPrintf("index %zu, nanoseconds %llu", index, nanoseconds));
89 85
90 TestSleepNanoseconds(nanoseconds); 86 TestSleepNanoseconds(nanoseconds);
91 } 87 }
92 } 88 }
93 89
94 } // namespace 90 } // namespace
95 } // namespace test 91 } // namespace test
96 } // namespace crashpad 92 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698