Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 1 | #include "absl/flags/flag.h" |
| 2 | #include "absl/log/check.h" |
| 3 | #include "absl/log/log.h" |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 4 | #include "gtest/gtest.h" |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 5 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 6 | #include "aos/init.h" |
Adam Snaider | c8b7e75 | 2023-09-14 14:27:53 -0700 | [diff] [blame] | 7 | #include "aos/testing/tmpdir.h" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 8 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 9 | ABSL_FLAG(bool, print_logs, false, |
| 10 | "Print the log messages as they are being generated."); |
| 11 | ABSL_FLAG(std::string, log_file, "", |
| 12 | "Print all log messages to FILE instead of standard output."); |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 13 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 14 | namespace aos::testing { |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 15 | |
Brian Silverman | f5f8d8e | 2015-12-06 18:39:12 -0500 | [diff] [blame] | 16 | // Actually declared/defined in //aos/testing:test_logging. |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 17 | void SetLogFileName(const char *filename) __attribute__((weak)); |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 18 | void ForcePrintLogsDuringTests() __attribute__((weak)); |
| 19 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 20 | } // namespace aos::testing |
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); |
Austin Schuh | 6228825 | 2020-11-18 23:26:04 -0800 | [diff] [blame] | 24 | aos::InitGoogle(&argc, &argv); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 25 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 26 | if (absl::GetFlag(FLAGS_print_logs)) { |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 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 | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 32 | if (!absl::GetFlag(FLAGS_log_file).empty()) { |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 33 | if (::aos::testing::ForcePrintLogsDuringTests) { |
| 34 | ::aos::testing::ForcePrintLogsDuringTests(); |
| 35 | } |
| 36 | if (::aos::testing::SetLogFileName) { |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 37 | ::aos::testing::SetLogFileName(absl::GetFlag(FLAGS_log_file).c_str()); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
Austin Schuh | cdab619 | 2019-12-29 17:47:46 -0800 | [diff] [blame] | 41 | // Point shared memory away from /dev/shm if we are testing. We don't care |
| 42 | // 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] | 43 | aos::testing::SetTestShmBase(); |
Austin Schuh | cdab619 | 2019-12-29 17:47:46 -0800 | [diff] [blame] | 44 | |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 45 | return RUN_ALL_TESTS(); |
| 46 | } |