blob: fb0ffcd4d8b243a0ace801a0900d8ae2eccea484 [file] [log] [blame]
Brian Silvermaneeb62ca2013-09-11 15:08:03 -07001#ifndef AOS_COMMON_QUEUE_TESTUTILS_H_
2#define AOS_COMMON_QUEUE_TESTUTILS_H_
3
Brian Silverman14fd0fb2014-01-14 21:42:01 -08004#include "aos/linux_code/ipc_lib/shared_mem.h"
Brian Silvermaneeb62ca2013-09-11 15:08:03 -07005
6// This file has some general helper functions for dealing with testing things
7// that use shared memory etc.
brians343bc112013-02-10 01:53:46 +00008
9namespace aos {
10namespace common {
11namespace testing {
12
Brian Silvermaneeb62ca2013-09-11 15:08:03 -070013// Manages creating and cleaning up "shared memory" which works within this
14// process and any that it fork(2)s.
brians343bc112013-02-10 01:53:46 +000015class GlobalCoreInstance {
16 public:
Brian Silvermaneeb62ca2013-09-11 15:08:03 -070017 // Calls EnableTestLogging().
brians343bc112013-02-10 01:53:46 +000018 GlobalCoreInstance();
19 ~GlobalCoreInstance();
20
21 private:
22 struct aos_core global_core_data_;
23};
24
Brian Silvermanb3616972013-03-05 19:58:10 -080025// 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.
30void EnableTestLogging();
31
Brian Silvermaneeb62ca2013-09-11 15:08:03 -070032// 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.
36void PreventExit();
37
Philipp Schradere41ed9d2015-03-15 22:57:13 +000038// Redirect the messages enabled by EnableTestLogging() function to a file.
39// By default the messages are printed to standard output.
40void SetLogFileName(const char* filename);
41
42// Force the messages to be printed as they are handled by the logging
43// framework. This can be useful for tests that hang where no messages would
44// otherwise be printed. This is also useful for tests that do pass, but where
45// we want to use graphing tools to verify what's happening.
46void ForcePrintLogsDuringTests();
47
brians343bc112013-02-10 01:53:46 +000048} // namespace testing
49} // namespace common
50} // namespace aos
Brian Silvermaneeb62ca2013-09-11 15:08:03 -070051
52#endif // AOS_COMMON_QUEUE_TESTUTILS_H_