summaryrefslogtreecommitdiffstats
path: root/base/threading/platform_thread_unittest.cc
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 21:21:09 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 21:21:09 +0000
commit63e668013de9226ba017db40b49ea4528514aa73 (patch)
treede320cfc9fa5f396819570603bc1a144e4e728a9 /base/threading/platform_thread_unittest.cc
parent223a93f11d161cd63a6986d8bd81364bae16a600 (diff)
downloadchromium_src-63e668013de9226ba017db40b49ea4528514aa73.zip
chromium_src-63e668013de9226ba017db40b49ea4528514aa73.tar.gz
chromium_src-63e668013de9226ba017db40b49ea4528514aa73.tar.bz2
Revert 118118 - Temporarily revert 117127 for perf analysis.
BUG=110555 TBR=rsesek@chromium.org Review URL: https://chromiumcodereview.appspot.com/9252014 TBR=rsesek@chromium.org Review URL: https://chromiumcodereview.appspot.com/9250014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118152 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/threading/platform_thread_unittest.cc')
-rw-r--r--base/threading/platform_thread_unittest.cc21
1 files changed, 18 insertions, 3 deletions
diff --git a/base/threading/platform_thread_unittest.cc b/base/threading/platform_thread_unittest.cc
index 6bff1d4..e37709a 100644
--- a/base/threading/platform_thread_unittest.cc
+++ b/base/threading/platform_thread_unittest.cc
@@ -1,7 +1,8 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/compiler_specific.h"
#include "base/threading/platform_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -14,7 +15,7 @@ class TrivialThread : public PlatformThread::Delegate {
public:
TrivialThread() : did_run_(false) {}
- virtual void ThreadMain() {
+ virtual void ThreadMain() OVERRIDE {
did_run_ = true;
}
@@ -56,11 +57,14 @@ class FunctionTestThread : public TrivialThread {
public:
FunctionTestThread() : thread_id_(0) {}
- virtual void ThreadMain() {
+ virtual void ThreadMain() OVERRIDE {
thread_id_ = PlatformThread::CurrentId();
PlatformThread::YieldCurrentThread();
PlatformThread::Sleep(TimeDelta::FromMilliseconds(50));
+ // Make sure that the thread ID is the same across calls.
+ EXPECT_EQ(thread_id_, PlatformThread::CurrentId());
+
TrivialThread::ThreadMain();
}
@@ -83,6 +87,9 @@ TEST(PlatformThreadTest, Function) {
PlatformThread::Join(handle);
ASSERT_TRUE(thread.did_run());
EXPECT_NE(thread.thread_id(), main_thread_id);
+
+ // Make sure that the thread ID is the same across calls.
+ EXPECT_EQ(main_thread_id, PlatformThread::CurrentId());
}
TEST(PlatformThreadTest, FunctionTimesTen) {
@@ -100,7 +107,15 @@ TEST(PlatformThreadTest, FunctionTimesTen) {
for (size_t n = 0; n < arraysize(thread); n++) {
ASSERT_TRUE(thread[n].did_run());
EXPECT_NE(thread[n].thread_id(), main_thread_id);
+
+ // Make sure no two threads get the same ID.
+ for (size_t i = 0; i < n; ++i) {
+ EXPECT_NE(thread[i].thread_id(), thread[n].thread_id());
+ }
}
+
+ // Make sure that the thread ID is the same across calls.
+ EXPECT_EQ(main_thread_id, PlatformThread::CurrentId());
}
} // namespace base