aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-02-26 05:42:53 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-02-26 05:42:53 +0000
commitc85a77a6ab0ef05c4a9a8554bf8c5e1c8687cc75 (patch)
tree45ff15530d24e3b41939398d3afaffe98e11b3ba /test
parent4f874c187beb3d185f7892887c8b13f356bf1fd6 (diff)
downloadgoogletest-c85a77a6ab0ef05c4a9a8554bf8c5e1c8687cc75.tar.gz
googletest-c85a77a6ab0ef05c4a9a8554bf8c5e1c8687cc75.tar.bz2
googletest-c85a77a6ab0ef05c4a9a8554bf8c5e1c8687cc75.zip
Simplifies ThreadStartSemaphore's implementation.
Diffstat (limited to 'test')
-rw-r--r--test/gtest-port_test.cc19
1 files changed, 7 insertions, 12 deletions
diff --git a/test/gtest-port_test.cc b/test/gtest-port_test.cc
index f7f26215..357a99ed 100644
--- a/test/gtest-port_test.cc
+++ b/test/gtest-port_test.cc
@@ -35,10 +35,6 @@
#include <stdio.h>
-#if GTEST_HAS_PTHREAD
-#include <unistd.h> // For nanosleep().
-#endif // GTEST_HAS_PTHREAD
-
#if GTEST_OS_MAC
#include <time.h>
#endif // GTEST_OS_MAC
@@ -137,10 +133,7 @@ TEST(GetThreadCountTest, ReturnsCorrectValue) {
if (GetThreadCount() == 1)
break;
- timespec time;
- time.tv_sec = 0;
- time.tv_nsec = 100L * 1000 * 1000; // .1 seconds.
- nanosleep(&time, NULL);
+ SleepMilliseconds(100);
}
EXPECT_EQ(1U, GetThreadCount());
pthread_mutex_destroy(&mutex);
@@ -802,7 +795,7 @@ TEST(ThreadLocalTest, PointerAndConstPointerReturnSameValue) {
}
#if GTEST_IS_THREADSAFE
-TEST(MutexTestDeathTest, AssertHeldShouldAssertWhenNotLocked) {
+TEST(MutexDeathTest, AssertHeldShouldAssertWhenNotLocked) {
// AssertHeld() is flaky only in the presence of multiple threads accessing
// the lock. In this case, the test is robust.
EXPECT_DEATH_IF_SUPPORTED({
@@ -813,8 +806,10 @@ TEST(MutexTestDeathTest, AssertHeldShouldAssertWhenNotLocked) {
"The current thread is not holding the mutex @.+");
}
-void SleepMilliseconds(int time) {
- usleep(static_cast<useconds_t>(time * 1000.0));
+TEST(MutexTest, AssertHeldShouldNotAssertWhenLocked) {
+ Mutex m;
+ MutexLock lock(&m);
+ m.AssertHeld();
}
class AtomicCounterWithMutex {
@@ -873,7 +868,7 @@ TEST(MutexTest, OnlyOneThreadCanLockAtATime) {
kCycleCount),
&semaphore));
}
- semaphore.Signal(); // Start the threads.
+ semaphore.Signal(); // Starts the threads.
for (int i = 0; i < kThreadCount; ++i)
counting_threads[i]->Join();