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

Side by Side Diff: test/unittests/base/platform/time-unittest.cc

Issue 1966183003: [Reland] Implement CPU time for OS X and POSIX. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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 | « src/base/platform/time.cc ('k') | 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 V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/base/platform/time.h" 5 #include "src/base/platform/time.h"
6 6
7 #if V8_OS_MACOSX 7 #if V8_OS_MACOSX
8 #include <mach/mach_time.h> 8 #include <mach/mach_time.h>
9 #endif 9 #endif
10 #if V8_OS_POSIX 10 #if V8_OS_POSIX
11 #include <sys/time.h> 11 #include <sys/time.h>
12 #endif 12 #endif
13 13
14 #if V8_OS_WIN 14 #if V8_OS_WIN
15 #include "src/base/win32-headers.h" 15 #include "src/base/win32-headers.h"
16 #endif 16 #endif
17 17
18 #include "src/base/platform/elapsed-timer.h" 18 #include "src/base/platform/elapsed-timer.h"
19 #include "src/base/platform/platform.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace v8 { 22 namespace v8 {
22 namespace base { 23 namespace base {
23 24
24 TEST(TimeDelta, FromAndIn) { 25 TEST(TimeDelta, FromAndIn) {
25 EXPECT_EQ(TimeDelta::FromDays(2), TimeDelta::FromHours(48)); 26 EXPECT_EQ(TimeDelta::FromDays(2), TimeDelta::FromHours(48));
26 EXPECT_EQ(TimeDelta::FromHours(3), TimeDelta::FromMinutes(180)); 27 EXPECT_EQ(TimeDelta::FromHours(3), TimeDelta::FromMinutes(180));
27 EXPECT_EQ(TimeDelta::FromMinutes(2), TimeDelta::FromSeconds(120)); 28 EXPECT_EQ(TimeDelta::FromMinutes(2), TimeDelta::FromSeconds(120));
28 EXPECT_EQ(TimeDelta::FromSeconds(2), TimeDelta::FromMilliseconds(2000)); 29 EXPECT_EQ(TimeDelta::FromSeconds(2), TimeDelta::FromMilliseconds(2000));
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 TimeTicks highres_ticks = TimeTicks::HighResolutionNow(); 176 TimeTicks highres_ticks = TimeTicks::HighResolutionNow();
176 EXPECT_GE(normal_ticks, previous_normal_ticks); 177 EXPECT_GE(normal_ticks, previous_normal_ticks);
177 EXPECT_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0); 178 EXPECT_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0);
178 EXPECT_GE(highres_ticks, previous_highres_ticks); 179 EXPECT_GE(highres_ticks, previous_highres_ticks);
179 EXPECT_GE((highres_ticks - previous_highres_ticks).InMicroseconds(), 0); 180 EXPECT_GE((highres_ticks - previous_highres_ticks).InMicroseconds(), 0);
180 previous_normal_ticks = normal_ticks; 181 previous_normal_ticks = normal_ticks;
181 previous_highres_ticks = highres_ticks; 182 previous_highres_ticks = highres_ticks;
182 } 183 }
183 } 184 }
184 185
186
187 // Disable on windows until it is implemented.
188 #if V8_OS_ANDROID || V8_OS_WIN
189 #define MAYBE_ThreadNow DISABLED_ThreadNow
190 #else
191 #define MAYBE_ThreadNow ThreadNow
192 #endif
193 TEST(ThreadTicks, MAYBE_ThreadNow) {
194 if (ThreadTicks::IsSupported()) {
195 TimeTicks begin = TimeTicks::Now();
196 ThreadTicks begin_thread = ThreadTicks::Now();
197 // Make sure that ThreadNow value is non-zero.
198 EXPECT_GT(begin_thread, ThreadTicks());
199 // Sleep for 10 milliseconds to get the thread de-scheduled.
200 OS::Sleep(base::TimeDelta::FromMilliseconds(10));
201 ThreadTicks end_thread = ThreadTicks::Now();
202 TimeTicks end = TimeTicks::Now();
203 TimeDelta delta = end - begin;
204 TimeDelta delta_thread = end_thread - begin_thread;
205 // Make sure that some thread time have elapsed.
206 EXPECT_GT(delta_thread.InMicroseconds(), 0);
207 // But the thread time is at least 9ms less than clock time.
208 TimeDelta difference = delta - delta_thread;
209 EXPECT_GE(difference.InMicroseconds(), 9000);
210 }
211 }
212
185 } // namespace base 213 } // namespace base
186 } // namespace v8 214 } // namespace v8
OLDNEW
« no previous file with comments | « src/base/platform/time.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698