summaryrefslogtreecommitdiff
path: root/test/gtest_stress_test.cc
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-02-24 17:19:25 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-02-24 17:19:25 +0000
commit050a520ddf9a34b93a3b41704fa2450d7450783f (patch)
treec91cb1205fb45e4a96889ae478afa66a0559694c /test/gtest_stress_test.cc
parent6851df92502ee6b9b96f008ae66e676f9565fc46 (diff)
downloadgoogletest-050a520ddf9a34b93a3b41704fa2450d7450783f.tar.gz
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).
git-svn-id: http://googletest.googlecode.com/svn/trunk@376 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'test/gtest_stress_test.cc')
-rw-r--r--test/gtest_stress_test.cc44
1 files changed, 16 insertions, 28 deletions
diff --git a/test/gtest_stress_test.cc b/test/gtest_stress_test.cc
index 75d6268..3cb68de 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();
}