diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-02-24 17:19:25 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-02-24 17:19:25 +0000 |
commit | 3bef459eac9aa84c579f34249aebc9ff56832054 (patch) | |
tree | c91cb1205fb45e4a96889ae478afa66a0559694c /test/gtest_stress_test.cc | |
parent | dd280cfa8dff2247f71a1177d7c8f0c2fde9789a (diff) | |
download | googletest-3bef459eac9aa84c579f34249aebc9ff56832054.tar.gz googletest-3bef459eac9aa84c579f34249aebc9ff56832054.tar.bz2 googletest-3bef459eac9aa84c579f34249aebc9ff56832054.zip |
Adds threading support (by Miklos Fazekas, Vlad Losev, and Chandler Carruth); adds wide InitGoogleTest to gtest.def (by Vlad Losev); updates the version number (by Zhanyong Wan); updates the release notes for 1.5.0 (by Vlad Losev); removes scons scripts from the distribution (by Zhanyong Wan); adds the cmake build script to the distribution (by Zhanyong Wan); adds fused source files to the distribution (by Vlad Losev and Chandler Carruth).
Diffstat (limited to 'test/gtest_stress_test.cc')
-rw-r--r-- | test/gtest_stress_test.cc | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/test/gtest_stress_test.cc b/test/gtest_stress_test.cc index 75d6268e..3cb68de8 100644 --- a/test/gtest_stress_test.cc +++ b/test/gtest_stress_test.cc @@ -48,23 +48,17 @@ namespace testing { namespace { +using internal::scoped_ptr; using internal::String; using internal::TestPropertyKeyIs; using internal::Vector; +using internal::ThreadStartSemaphore; +using internal::ThreadWithParam; // In order to run tests in this file, for platforms where Google Test is -// thread safe, implement ThreadWithParam with the following interface: -// -// template <typename T> class ThreadWithParam { -// public: -// // Creates the thread. The thread should execute thread_func(param) when -// // started by a call to Start(). -// ThreadWithParam(void (*thread_func)(T), T param); -// // Starts the thread. -// void Start(); -// // Waits for the thread to finish. -// void Join(); -// }; +// thread safe, implement ThreadWithParam and ThreadStartSemaphore. See the +// description of their API in gtest-port.h, where they are defined for +// already supported platforms. // How many threads to create? const int kThreadCount = 50; @@ -132,22 +126,17 @@ void CheckTestFailureCount(int expected_failures) { // Tests using SCOPED_TRACE() and Google Test assertions in many threads // concurrently. TEST(StressTest, CanUseScopedTraceAndAssertionsInManyThreads) { - ThreadWithParam<int>* threads[kThreadCount] = {}; - for (int i = 0; i != kThreadCount; i++) { - // Creates a thread to run the ManyAsserts() function. - threads[i] = new ThreadWithParam<int>(&ManyAsserts, i); - - // Starts the thread. - threads[i]->Start(); - } + { + scoped_ptr<ThreadWithParam<int> > threads[kThreadCount]; + ThreadStartSemaphore semaphore; + for (int i = 0; i != kThreadCount; i++) + threads[i].reset(new ThreadWithParam<int>(&ManyAsserts, i, &semaphore)); - // At this point, we have many threads running. + semaphore.Signal(); // Starts all the threads. - for (int i = 0; i != kThreadCount; i++) { - // We block until the thread is done. - threads[i]->Join(); - delete threads[i]; - threads[i] = NULL; + // Blocks until all the threads are done. + for (int i = 0; i != kThreadCount; i++) + threads[i]->Join(); } // Ensures that kThreadCount*kThreadCount failures have been reported. @@ -180,8 +169,7 @@ void FailingThread(bool is_fatal) { } void GenerateFatalFailureInAnotherThread(bool is_fatal) { - ThreadWithParam<bool> thread(&FailingThread, is_fatal); - thread.Start(); + ThreadWithParam<bool> thread(&FailingThread, is_fatal, NULL); thread.Join(); } |