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

Unified Diff: base/highres_timer_unittest.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/highres_timer-win32.cc ('k') | base/lang_enc.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/highres_timer_unittest.cc
diff --git a/base/highres_timer_unittest.cc b/base/highres_timer_unittest.cc
deleted file mode 100644
index 696524452c89ce1c277be7f1c39766c4917e5c01..0000000000000000000000000000000000000000
--- a/base/highres_timer_unittest.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2006-2009 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// ========================================================================
-#include "base/basictypes.h"
-#include "omaha/base/highres_timer-win32.h"
-#include "omaha/testing/unit_test.h"
-
-namespace omaha {
-
-// Timing tests are extremely sensitive to external interference from other
-// work currently being done on the machine. scoped_priority_boost temporarily
-// raises the priority of the caller's thread to reduce the chance of an
-// intervening context switch.
-
-class scoped_priority_boost {
- public:
- scoped_priority_boost() {
- orig_process_priority_ = ::GetPriorityClass(::GetCurrentProcess());
- if (0 != orig_process_priority_) {
- if (0 == ::SetPriorityClass(::GetCurrentProcess(),
- HIGH_PRIORITY_CLASS)) {
- orig_process_priority_ = 0;
- }
- }
-
- orig_thread_priority_ = ::GetThreadPriority(::GetCurrentThread());
- if (THREAD_PRIORITY_ERROR_RETURN != orig_thread_priority_) {
- if (0 == ::SetThreadPriority(::GetCurrentThread(),
- THREAD_PRIORITY_HIGHEST)) {
- orig_thread_priority_ = THREAD_PRIORITY_ERROR_RETURN;
- }
- }
- }
-
- ~scoped_priority_boost() {
- if (0 != orig_process_priority_) {
- ::SetPriorityClass(::GetCurrentProcess(), orig_process_priority_);
- }
- if (THREAD_PRIORITY_ERROR_RETURN != orig_thread_priority_) {
- ::SetPriorityClass(::GetCurrentProcess(), orig_process_priority_);
- }
- }
-
- bool succeeded() const {
- return (0 != orig_process_priority_) &&
- (THREAD_PRIORITY_ERROR_RETURN != orig_thread_priority_);
- }
-
- private:
- DWORD orig_process_priority_;
- int orig_thread_priority_;
-
- DISALLOW_COPY_AND_ASSIGN(scoped_priority_boost);
-};
-
-TEST(HighresTimer, MillisecondClock) {
- scoped_priority_boost spb;
- EXPECT_TRUE(spb.succeeded());
-
- HighresTimer timer;
-
- // note: this could fail if we context switch between initializing the timer
- // and here. Very unlikely however.
- EXPECT_EQ(0, timer.GetElapsedMs());
- timer.Start();
- uint64 half_ms = (HighresTimer::GetTimerFrequency() / 2000) + 1;
- // busy wait for a fraction more than half a millisecond.
- while (timer.start_ticks() + half_ms > HighresTimer::GetCurrentTicks()) {
- // Nothing
- }
- EXPECT_EQ(1, timer.GetElapsedMs());
-}
-
-TEST(HighresTimer, SecondClock) {
- scoped_priority_boost spb;
- EXPECT_TRUE(spb.succeeded());
-
- HighresTimer timer;
-
- EXPECT_EQ(0, timer.GetElapsedSec());
-#ifdef OS_WINDOWS
- ::Sleep(250);
-#else
- struct timespec ts1 = {0, 250000000};
- nanosleep(&ts1, 0);
-#endif
- EXPECT_EQ(0, timer.GetElapsedSec());
- EXPECT_LE(230, timer.GetElapsedMs());
- EXPECT_GE(270, timer.GetElapsedMs());
-#ifdef OS_WINDOWS
- ::Sleep(251);
-#else
- struct timespec ts2 = {0, 251000000};
- nanosleep(&ts2, 0);
-#endif
- EXPECT_EQ(1, timer.GetElapsedSec());
-}
-
-} // namespace omaha
-
« no previous file with comments | « base/highres_timer-win32.cc ('k') | base/lang_enc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698