Brian Silverman | eeb62ca | 2013-09-11 15:08:03 -0700 | [diff] [blame] | 1 | #ifndef AOS_COMMON_QUEUE_TESTUTILS_H_ |
| 2 | #define AOS_COMMON_QUEUE_TESTUTILS_H_ |
| 3 | |
Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame] | 4 | #include "aos/linux_code/ipc_lib/shared_mem.h" |
Brian Silverman | eeb62ca | 2013-09-11 15:08:03 -0700 | [diff] [blame] | 5 | |
| 6 | // This file has some general helper functions for dealing with testing things |
| 7 | // that use shared memory etc. |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 8 | |
| 9 | namespace aos { |
| 10 | namespace common { |
| 11 | namespace testing { |
| 12 | |
Brian Silverman | eeb62ca | 2013-09-11 15:08:03 -0700 | [diff] [blame] | 13 | // Manages creating and cleaning up "shared memory" which works within this |
| 14 | // process and any that it fork(2)s. |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 15 | class GlobalCoreInstance { |
| 16 | public: |
Brian Silverman | eeb62ca | 2013-09-11 15:08:03 -0700 | [diff] [blame] | 17 | // Calls EnableTestLogging(). |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 18 | GlobalCoreInstance(); |
| 19 | ~GlobalCoreInstance(); |
| 20 | |
| 21 | private: |
| 22 | struct aos_core global_core_data_; |
| 23 | }; |
| 24 | |
Brian Silverman | b361697 | 2013-03-05 19:58:10 -0800 | [diff] [blame] | 25 | // Enables the logging framework for use during a gtest test. |
| 26 | // It will print out all WARNING and above messages all of the time. It will |
| 27 | // also print out all log messages when a test fails. |
| 28 | // This function only needs to be called once in each process (after gtest is |
| 29 | // initialized), however it can be called more than that. |
| 30 | void EnableTestLogging(); |
| 31 | |
Brian Silverman | eeb62ca | 2013-09-11 15:08:03 -0700 | [diff] [blame] | 32 | // Registers an exit handler (using atexit(3)) which will call _exit(2). |
| 33 | // Intended to be called in a freshly fork(2)ed process where it will run before |
| 34 | // any other exit handlers that were already registered and prevent them from |
| 35 | // being run. |
| 36 | void PreventExit(); |
| 37 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 38 | } // namespace testing |
| 39 | } // namespace common |
| 40 | } // namespace aos |
Brian Silverman | eeb62ca | 2013-09-11 15:08:03 -0700 | [diff] [blame] | 41 | |
| 42 | #endif // AOS_COMMON_QUEUE_TESTUTILS_H_ |