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