diff options
author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-23 22:37:16 +0000 |
---|---|---|
committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-23 22:37:16 +0000 |
commit | 07875adbb432b39b538937eb0954ef7f74eadaaf (patch) | |
tree | 02d0bb4f7086a9f9e3da2f43838a13059cf12491 /native_client_sdk | |
parent | eafd3cab94f46e06427b9bc051bb914021c134f5 (diff) | |
download | chromium_src-07875adbb432b39b538937eb0954ef7f74eadaaf.zip chromium_src-07875adbb432b39b538937eb0954ef7f74eadaaf.tar.gz chromium_src-07875adbb432b39b538937eb0954ef7f74eadaaf.tar.bz2 |
[NaCl SDK] Fixes to gtest_ppapi so it compiles on win,linux host builds.
BUG=none
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/10834438
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153099 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
11 files changed, 27 insertions, 201 deletions
diff --git a/native_client_sdk/src/libraries/gtest_ppapi/condition_lock.h b/native_client_sdk/src/libraries/gtest_ppapi/condition_lock.h deleted file mode 100644 index 927d55e..0000000 --- a/native_client_sdk/src/libraries/gtest_ppapi/condition_lock.h +++ /dev/null @@ -1,86 +0,0 @@ -// 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. - -#ifndef GTEST_PPAPI_CONDITION_LOCK_H_ -#define GTEST_PPAPI_CONDITION_LOCK_H_ - -#include <pthread.h> - -// Class to manage a lock associated with a specific value. The calling thread -// can ask to acquire the lock only when the lock is in a certain condition. -class ConditionLock { - public: - ConditionLock() : condition_value_(0) { - InitLock(); - } - explicit ConditionLock(int32_t condition_value) - : condition_value_(condition_value) { - InitLock(); - } - - virtual ~ConditionLock() { - pthread_cond_destroy(&condition_condition_); - pthread_mutex_destroy(&condition_lock_); - } - - // Acquire the mutex without regard to the condition. - void Lock() { - pthread_mutex_lock(&condition_lock_); - } - - // Acquire the mutex lock when the lock values are equal. Blocks the - // calling thread until the lock can be acquired and the condition is met. - void LockWhenCondition(int32_t condition_value) { - Lock(); - while (condition_value != condition_value_) { - pthread_cond_wait(&condition_condition_, &condition_lock_); - } - // When this method returns, |contition_lock_| will be acquired. The - // calling thread must unlock it. - } - - // Acquire the mutex lock when the lock values are _NOT_ equal. Blocks the - // calling thread until the lock can be acquired and the condition is met. - void LockWhenNotCondition(int32_t condition_value) { - Lock(); - while (condition_value == condition_value_) { - pthread_cond_wait(&condition_condition_, &condition_lock_); - } - // When this method returns, |contition_lock_| will be acquired. The - // calling thread must unlock it. - } - - // Release the lock without changing the condition. Signal the condition - // so that threads waiting in LockWhenCondtion() will wake up. If there are - // no threads waiting for the signal, this has the same effect as a simple - // mutex unlock. - void Unlock() { - pthread_cond_broadcast(&condition_condition_); - pthread_mutex_unlock(&condition_lock_); - } - - // Release the lock, setting the condition's value. This assumes that - // |condition_lock_| has been acquired. - void UnlockWithCondition(unsigned int condition_value) { - condition_value_ = condition_value; - Unlock(); - } - - // Return the current condition value without any mutex protection. - int32_t condition_value() const { - return condition_value_; - } - - private: - void InitLock() { - pthread_mutex_init(&condition_lock_, NULL); - pthread_cond_init(&condition_condition_, NULL); - } - - pthread_mutex_t condition_lock_; - pthread_cond_t condition_condition_; - int32_t condition_value_; -}; - -#endif // CONDITION_LOCK_H_ diff --git a/native_client_sdk/src/libraries/gtest_ppapi/gtest_event_listener.cc b/native_client_sdk/src/libraries/gtest_ppapi/gtest_event_listener.cc index 020c036..970fa15 100644 --- a/native_client_sdk/src/libraries/gtest_ppapi/gtest_event_listener.cc +++ b/native_client_sdk/src/libraries/gtest_ppapi/gtest_event_listener.cc @@ -3,13 +3,18 @@ // found in the LICENSE file. #include "gtest_ppapi/gtest_event_listener.h" +#include "ppapi/c/pp_macros.h" #include "ppapi/cpp/instance.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/var.h" +#if defined(WIN32) +#undef PostMessage +#endif + GTestEventListener::GTestEventListener(pp::Instance* instance) : instance_(instance), - factory_(this) { + PP_ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { assert(pp::Module::Get()->core()->IsMainThread()); } @@ -24,7 +29,7 @@ void GTestEventListener::OnTestProgramStart( msg << " from "<< num_test_cases << " test case"; if (num_test_cases > 1) msg << 's'; msg << '.'; - PostMessage(msg.str()); + MyPostMessage(msg.str()); } void GTestEventListener::OnTestCaseStart( @@ -44,12 +49,12 @@ void GTestEventListener::OnTestPartResult( msg << test_part_result.file_name(); msg << "::" << test_part_result.line_number() << "::"; msg << test_part_result.summary(); - PostMessage(msg.str()); + MyPostMessage(msg.str()); msg.str(""); msg << "::failure_log::"; msg << test_part_result.summary(); - PostMessage(msg.str()); + MyPostMessage(msg.str()); } } @@ -59,7 +64,7 @@ void GTestEventListener::OnTestEnd(const ::testing::TestInfo& test_info) { msg << test_info.test_case_name() << "." << test_info.name(); msg << (test_info.result()->Failed() ? ": FAILED" : ": OK"); - PostMessage(msg.str()); + MyPostMessage(msg.str()); } void GTestEventListener::OnTestCaseEnd( @@ -76,20 +81,20 @@ void GTestEventListener::OnTestProgramEnd( msg << "::Result::"; msg << ((num_failed_tests > 0) ? "failed::" : "success::"); msg << num_passed_tests << "::" << num_failed_tests << "::"; - PostMessage(msg.str()); + MyPostMessage(msg.str()); } -void GTestEventListener::PostMessage(const std::string& str) { +void GTestEventListener::MyPostMessage(const std::string& str) { if (pp::Module::Get()->core()->IsMainThread()) { instance_->PostMessage(str); } else { pp::CompletionCallback cc = factory_.NewCallback( - >estEventListener::PostMessageCallback, str); + >estEventListener::MyPostMessageCallback, str); pp::Module::Get()->core()->CallOnMainThread(0, cc, PP_OK); } } -void GTestEventListener::PostMessageCallback(int32_t result, +void GTestEventListener::MyPostMessageCallback(int32_t result, const std::string& str) { instance_->PostMessage(str); } diff --git a/native_client_sdk/src/libraries/gtest_ppapi/gtest_event_listener.h b/native_client_sdk/src/libraries/gtest_ppapi/gtest_event_listener.h index 1af4c22..90d5d0a 100644 --- a/native_client_sdk/src/libraries/gtest_ppapi/gtest_event_listener.h +++ b/native_client_sdk/src/libraries/gtest_ppapi/gtest_event_listener.h @@ -7,7 +7,6 @@ #include <string> #include "gtest/gtest.h" -#include "gtest_ppapi/ref_count.h" #include "ppapi/utility/completion_callback_factory.h" namespace pp { @@ -37,8 +36,9 @@ class GTestEventListener : public ::testing::EmptyTestEventListener { virtual void OnTestProgramEnd(const ::testing::UnitTest& unit_test); private: - void PostMessage(const std::string& str); - void PostMessageCallback(int32_t result, const std::string& str); + // Called MyPostMessage as to not conflict with win32 macro PostMessage. + void MyPostMessage(const std::string& str); + void MyPostMessageCallback(int32_t result, const std::string& str); pp::Instance* instance_; pp::CompletionCallbackFactory<GTestEventListener> factory_; diff --git a/native_client_sdk/src/libraries/gtest_ppapi/gtest_instance.cc b/native_client_sdk/src/libraries/gtest_ppapi/gtest_instance.cc index e80368e..dc5e1a7 100644 --- a/native_client_sdk/src/libraries/gtest_ppapi/gtest_instance.cc +++ b/native_client_sdk/src/libraries/gtest_ppapi/gtest_instance.cc @@ -6,6 +6,10 @@ #include "gtest_ppapi/gtest_runner.h" #include "ppapi/cpp/var.h" +#if defined(WIN32) +#undef PostMessage +#endif + GTestInstance::GTestInstance(PP_Instance instance) : pp::Instance(instance) { } diff --git a/native_client_sdk/src/libraries/gtest_ppapi/gtest_runner.cc b/native_client_sdk/src/libraries/gtest_ppapi/gtest_runner.cc index b6e96d9..d8ce6dc 100644 --- a/native_client_sdk/src/libraries/gtest_ppapi/gtest_runner.cc +++ b/native_client_sdk/src/libraries/gtest_ppapi/gtest_runner.cc @@ -9,13 +9,13 @@ #include "gtest_ppapi/gtest_event_listener.h" #include "gtest_ppapi/gtest_nacl_environment.h" -pthread_t GTestRunner::g_test_runner_thread_ = NACL_PTHREAD_ILLEGAL_THREAD_ID; +pthread_t GTestRunner::g_test_runner_thread_; GTestRunner* GTestRunner::gtest_runner_ = NULL; void GTestRunner::CreateGTestRunnerThread(pp::Instance* instance, int argc, char** argv) { - assert(g_test_runner_thread_ == NACL_PTHREAD_ILLEGAL_THREAD_ID); - if (g_test_runner_thread_ == NACL_PTHREAD_ILLEGAL_THREAD_ID) { + assert(!gtest_runner_); + if (!gtest_runner_) { gtest_runner_ = new GTestRunner(); gtest_runner_->Init(instance, argc, argv); pthread_create(&g_test_runner_thread_, NULL, ThreadFunc, NULL); @@ -34,7 +34,6 @@ void* GTestRunner::ThreadFunc(void* param) { gtest_runner_->RunLoop(); delete gtest_runner_; gtest_runner_ = NULL; - pthread_exit(NULL); return NULL; } diff --git a/native_client_sdk/src/libraries/gtest_ppapi/gtest_runner.h b/native_client_sdk/src/libraries/gtest_ppapi/gtest_runner.h index 64745ea..c9c3256 100644 --- a/native_client_sdk/src/libraries/gtest_ppapi/gtest_runner.h +++ b/native_client_sdk/src/libraries/gtest_ppapi/gtest_runner.h @@ -4,7 +4,7 @@ #ifndef GTEST_PPAPI_GTEST_RUNNER_H_ #define GTEST_PPAPI_GTEST_RUNNER_H_ -#include "gtest_ppapi/pthread_ext.h" +#include <pthread.h> #include "gtest_ppapi/thread_condition.h" namespace pp { diff --git a/native_client_sdk/src/libraries/gtest_ppapi/library.dsc b/native_client_sdk/src/libraries/gtest_ppapi/library.dsc index ef26d33..cf3548a 100644 --- a/native_client_sdk/src/libraries/gtest_ppapi/library.dsc +++ b/native_client_sdk/src/libraries/gtest_ppapi/library.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib', 'glibc', 'win', 'linux'], 'TARGETS': [ { 'NAME' : 'gtest_ppapi', @@ -16,14 +16,10 @@ 'HEADERS': [ { 'FILES': [ - "condition_lock.h", "gtest_event_listener.h", "gtest_instance.h", "gtest_nacl_environment.h", "gtest_runner.h", - "pthread_ext.h", - "ref_count.h", - "scoped_mutex_lock.h", "thread_condition.h", ], 'DEST': 'include/gtest_ppapi', @@ -31,5 +27,4 @@ ], 'DEST': 'testing', 'NAME': 'gtest_ppapi', - 'EXPERIMENTAL': True } diff --git a/native_client_sdk/src/libraries/gtest_ppapi/pthread_ext.h b/native_client_sdk/src/libraries/gtest_ppapi/pthread_ext.h deleted file mode 100644 index 6d60957..0000000 --- a/native_client_sdk/src/libraries/gtest_ppapi/pthread_ext.h +++ /dev/null @@ -1,14 +0,0 @@ -// 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. - -#ifndef GTEST_PPAPI_PTHREAD_EXT_H_ -#define GTEST_PPAPI_PTHREAD_EXT_H_ - -// Include wrapper on pthread.h, with a few handy constants. - -#include <pthread.h> - -#define PTHREAD_MUTEX_SUCCESS 0 - -#endif // GTEST_PPAPI_PTHREAD_EXT_H_ diff --git a/native_client_sdk/src/libraries/gtest_ppapi/ref_count.h b/native_client_sdk/src/libraries/gtest_ppapi/ref_count.h deleted file mode 100644 index e0d89a2..0000000 --- a/native_client_sdk/src/libraries/gtest_ppapi/ref_count.h +++ /dev/null @@ -1,42 +0,0 @@ -// 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. -#ifndef GTEST_PPAPI_REF_COUNT_H_ -#define GTEST_PPAPI_REF_COUNT_H_ - -#include "gtest_ppapi/pthread_ext.h" - -// A thread-safe reference counter for class CompletionCallbackFactory. -class RefCount { - public: - RefCount() : ref_(0) { - pthread_mutex_init(&mutex_, NULL); - } - ~RefCount() { - pthread_mutex_destroy(&mutex_); - } - - int32_t AddRef() { - int32_t ret_val = 0; - if (pthread_mutex_lock(&mutex_) == PTHREAD_MUTEX_SUCCESS) { - ret_val = ++ref_; - pthread_mutex_unlock(&mutex_); - } - return ret_val; - } - - int32_t Release() { - int32_t ret_val = -1; - if (pthread_mutex_lock(&mutex_) == PTHREAD_MUTEX_SUCCESS) { - ret_val = --ref_; - pthread_mutex_unlock(&mutex_); - } - return ret_val; - } - - private: - int32_t ref_; - pthread_mutex_t mutex_; -}; - -#endif // GTEST_PPAPI_REF_COUNT_H_ diff --git a/native_client_sdk/src/libraries/gtest_ppapi/scoped_mutex_lock.h b/native_client_sdk/src/libraries/gtest_ppapi/scoped_mutex_lock.h deleted file mode 100644 index 3830396..0000000 --- a/native_client_sdk/src/libraries/gtest_ppapi/scoped_mutex_lock.h +++ /dev/null @@ -1,29 +0,0 @@ -// 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. - -#ifndef GTEST_PPAPI_SCOPED_MUTEX_LOCK_H_ -#define GTEST_PPAPI_SCOPED_MUTEX_LOCK_H_ - -#include "gtest_ppapi/pthread_ext.h" - -// A small helper RAII class that implements a scoped pthread_mutex lock. -class ScopedMutexLock { - public: - explicit ScopedMutexLock(pthread_mutex_t* mutex) : mutex_(mutex) { - if (pthread_mutex_lock(mutex_) != PTHREAD_MUTEX_SUCCESS) { - mutex_ = NULL; - } - } - ~ScopedMutexLock() { - if (mutex_) - pthread_mutex_unlock(mutex_); - } - bool is_valid() const { - return mutex_ != NULL; - } - private: - pthread_mutex_t* mutex_; // Weak reference. -}; - -#endif // GTEST_PPAPI_SCOPED_MUTEX_LOCK_H_ diff --git a/native_client_sdk/src/libraries/gtest_ppapi/thread_condition.h b/native_client_sdk/src/libraries/gtest_ppapi/thread_condition.h index 285a5ba..5da0152 100644 --- a/native_client_sdk/src/libraries/gtest_ppapi/thread_condition.h +++ b/native_client_sdk/src/libraries/gtest_ppapi/thread_condition.h @@ -5,7 +5,7 @@ #ifndef GTEST_PPAPI_THREAD_CONDITION_H_ #define GTEST_PPAPI_THREAD_CONDITION_H_ -#include "gtest_ppapi/pthread_ext.h" +#include <pthread.h> struct timespec; @@ -57,12 +57,6 @@ class ThreadCondition { pthread_cond_wait(&condition_, &cond_mutex_); } - // Same as Wait, but wait at most until abs_time. Returns false if the system - // time exceeds abs_time before the condition is signaled. - bool TimedWait(struct timespec *abs_time) { - return (pthread_cond_timedwait(&condition_, &cond_mutex_, abs_time) == 0); - } - private: pthread_mutex_t cond_mutex_; pthread_cond_t condition_; |