Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: native_client_sdk/src/libraries/c_salt/test/gtest_runner.cc

Issue 10854137: [NaCl SDK] gtest_ppapi library. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove hacks Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #include "c_salt/test/gtest_runner.h"
5
6 #include <cassert>
7
8 #include "c_salt/test/gtest_event_listener.h"
9 #include "c_salt/test/gtest_nacl_environment.h"
10 #include "gtest/gtest.h"
11
12 namespace c_salt {
13
14 pthread_t GTestRunner::g_test_runner_thread_ = NACL_PTHREAD_ILLEGAL_THREAD_ID;
15 GTestRunner* GTestRunner::gtest_runner_ = NULL;
16
17 void GTestRunner::CreateGTestRunnerThread(pp::Instance* instance,
18 int argc, char** argv) {
19 assert(g_test_runner_thread_ == NACL_PTHREAD_ILLEGAL_THREAD_ID);
20 if (g_test_runner_thread_ == NACL_PTHREAD_ILLEGAL_THREAD_ID) {
21 gtest_runner_ = new GTestRunner();
22 gtest_runner_->Init(instance, argc, argv);
23 pthread_create(&g_test_runner_thread_, NULL, ThreadFunc, NULL);
24 }
25 }
26
27 void GTestRunner::RunAllTests() {
28 status_signal_.Lock();
29 assert(status_ == kIdle);
30 status_ = kRunTests;
31 status_signal_.Signal();
32 status_signal_.Unlock();
33 }
34
35 void* GTestRunner::ThreadFunc(void* param) {
36 gtest_runner_->RunLoop();
37 delete gtest_runner_;
38 gtest_runner_ = NULL;
39 pthread_exit(NULL);
40 return NULL;
41 }
42
43 GTestRunner::GTestRunner() : status_(kIdle) { }
44
45 void GTestRunner::Init(pp::Instance* instance, int argc, char** argv) {
46 // Init gtest.
47 testing::InitGoogleTest(&argc, argv);
48
49 // Add GTestEventListener to the list of listeners. That will cause the
50 // test output to go to nacltest.js through PostMessage.
51 ::testing::TestEventListeners& listeners =
52 ::testing::UnitTest::GetInstance()->listeners();
53 delete listeners.Release(listeners.default_result_printer());
54 listeners.Append(new c_salt::GTestEventListener(instance));
55
56 // We use our own gtest environment, mainly to make the nacl instance
57 // available to the individual unit tests.
58 c_salt::GTestNaclEnvironment* test_env = new c_salt::GTestNaclEnvironment();
59 test_env->set_global_instance(instance);
60 ::testing::AddGlobalTestEnvironment(test_env);
61 }
62
63 void GTestRunner::RunLoop() {
64 // Stay idle until RunAlltests is called.
65 status_signal_.Lock();
66 while (status_ == kIdle) {
67 status_signal_.Wait();
68 }
69
70 assert(status_ == kRunTests);
71 status_signal_.Unlock();
72 RUN_ALL_TESTS();
73 }
74
75 } // namespace c_salt
76
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698