Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 1 | #include <getopt.h> |
| 2 | |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 3 | #include <iostream> |
| 4 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 5 | #include "gflags/gflags.h" |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 6 | #include "glog/logging.h" |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 7 | #include "gtest/gtest.h" |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 8 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 9 | #include "aos/init.h" |
Adam Snaider | c8b7e75 | 2023-09-14 14:27:53 -0700 | [diff] [blame] | 10 | #include "aos/testing/tmpdir.h" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 11 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 12 | DEFINE_bool(print_logs, false, |
| 13 | "Print the log messages as they are being generated."); |
| 14 | DEFINE_string(log_file, "", |
| 15 | "Print all log messages to FILE instead of standard output."); |
| 16 | |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 17 | namespace aos { |
Austin Schuh | cdab619 | 2019-12-29 17:47:46 -0800 | [diff] [blame] | 18 | |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 19 | namespace testing { |
| 20 | |
Brian Silverman | f5f8d8e | 2015-12-06 18:39:12 -0500 | [diff] [blame] | 21 | // Actually declared/defined in //aos/testing:test_logging. |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 22 | void SetLogFileName(const char *filename) __attribute__((weak)); |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 23 | void ForcePrintLogsDuringTests() __attribute__((weak)); |
| 24 | |
| 25 | } // namespace testing |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 26 | } // namespace aos |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 27 | |
| 28 | GTEST_API_ int main(int argc, char **argv) { |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 29 | ::testing::InitGoogleTest(&argc, argv); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 30 | FLAGS_logtostderr = true; |
Austin Schuh | 6228825 | 2020-11-18 23:26:04 -0800 | [diff] [blame] | 31 | |
| 32 | aos::InitGoogle(&argc, &argv); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 33 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 34 | if (FLAGS_print_logs) { |
| 35 | if (::aos::testing::ForcePrintLogsDuringTests) { |
| 36 | ::aos::testing::ForcePrintLogsDuringTests(); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 37 | } |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 38 | } |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 39 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 40 | if (!FLAGS_log_file.empty()) { |
| 41 | if (::aos::testing::ForcePrintLogsDuringTests) { |
| 42 | ::aos::testing::ForcePrintLogsDuringTests(); |
| 43 | } |
| 44 | if (::aos::testing::SetLogFileName) { |
| 45 | ::aos::testing::SetLogFileName(FLAGS_log_file.c_str()); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
Austin Schuh | cdab619 | 2019-12-29 17:47:46 -0800 | [diff] [blame] | 49 | // Point shared memory away from /dev/shm if we are testing. We don't care |
| 50 | // about RT in this case, so if it is backed by disk, we are fine. |
Adam Snaider | c8b7e75 | 2023-09-14 14:27:53 -0700 | [diff] [blame] | 51 | aos::testing::SetTestShmBase(); |
Austin Schuh | cdab619 | 2019-12-29 17:47:46 -0800 | [diff] [blame] | 52 | |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 53 | return RUN_ALL_TESTS(); |
| 54 | } |