OLD | NEW |
| (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 #ifndef C_SALT_TEST_GTEST_RUNNER_H_ | |
5 #define C_SALT_TEST_GTEST_RUNNER_H_ | |
6 | |
7 #include "c_salt/threading/pthread_ext.h" | |
8 #include "c_salt/threading/thread_condition.h" | |
9 | |
10 namespace pp { | |
11 class Instance; | |
12 } // namespace pp | |
13 | |
14 namespace c_salt { | |
15 | |
16 // GTestRunner is a threaded singleton for running gtest-based unit tests. | |
17 class GTestRunner { | |
18 public: | |
19 // Factory function to create the background gtest thread and associated | |
20 // GTestRunner singleton. It is an error to call the factory function more | |
21 // than once that raises an assert in debug mde. | |
22 // | |
23 // Parameters: | |
24 // instance: the NaCl instance. | |
25 // argc: arg count from pp::Instance::Init. | |
26 // argv: the arguments from pp::Instance::Init. | |
27 static void CreateGTestRunnerThread(pp::Instance* instance, | |
28 int argc, char** argv); | |
29 | |
30 // Get the GTestRunner singleton. | |
31 // @return A pointer to the GTestRunner singleton. | |
32 static GTestRunner* gtest_runner() { return gtest_runner_; } | |
33 | |
34 // Tell the GTestRunner to run all gtest unit tests. | |
35 void RunAllTests(); | |
36 | |
37 protected: | |
38 // The pthread thread function. | |
39 static void* ThreadFunc(void* param); | |
40 | |
41 // Don't try to create instances directly. Use the factory function instead. | |
42 GTestRunner(); | |
43 void Init(pp::Instance* instance, int argc, char** argv); | |
44 | |
45 // The thread run loop exits once all test have run. | |
46 void RunLoop(); | |
47 | |
48 private: | |
49 // The status and associated status signal are used to control the state of | |
50 // the thread run loop. | |
51 enum Status { kIdle, kRunTests }; | |
52 c_salt::threading::ThreadCondition status_signal_; | |
53 Status status_; | |
54 | |
55 static pthread_t g_test_runner_thread_; | |
56 static GTestRunner* gtest_runner_; | |
57 }; | |
58 | |
59 } // namespace c_salt | |
60 | |
61 #endif // C_SALT_TEST_GTEST_RUNNER_H_ | |
62 | |
OLD | NEW |