Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 1 | #include <iostream> |
| 2 | #include <getopt.h> |
| 3 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame^] | 4 | #include "gflags/gflags.h" |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 5 | #include "gtest/gtest.h" |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 6 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame^] | 7 | DEFINE_bool(print_logs, false, |
| 8 | "Print the log messages as they are being generated."); |
| 9 | DEFINE_string(log_file, "", |
| 10 | "Print all log messages to FILE instead of standard output."); |
| 11 | |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 12 | namespace aos { |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 13 | namespace testing { |
| 14 | |
Brian Silverman | f5f8d8e | 2015-12-06 18:39:12 -0500 | [diff] [blame] | 15 | // Actually declared/defined in //aos/testing:test_logging. |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 16 | void SetLogFileName(const char* filename) __attribute__((weak)); |
| 17 | void ForcePrintLogsDuringTests() __attribute__((weak)); |
| 18 | |
| 19 | } // namespace testing |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 20 | } // namespace aos |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 21 | |
| 22 | GTEST_API_ int main(int argc, char **argv) { |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame^] | 23 | ::testing::InitGoogleTest(&argc, argv); |
| 24 | ::gflags::ParseCommandLineFlags(&argc, &argv, false); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 25 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame^] | 26 | if (FLAGS_print_logs) { |
| 27 | if (::aos::testing::ForcePrintLogsDuringTests) { |
| 28 | ::aos::testing::ForcePrintLogsDuringTests(); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 29 | } |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame^] | 30 | } |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 31 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame^] | 32 | if (!FLAGS_log_file.empty()) { |
| 33 | if (::aos::testing::ForcePrintLogsDuringTests) { |
| 34 | ::aos::testing::ForcePrintLogsDuringTests(); |
| 35 | } |
| 36 | if (::aos::testing::SetLogFileName) { |
| 37 | ::aos::testing::SetLogFileName(FLAGS_log_file.c_str()); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
| 41 | return RUN_ALL_TESTS(); |
| 42 | } |