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 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 17 | namespace aos::testing { |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 18 | |
Brian Silverman | f5f8d8e | 2015-12-06 18:39:12 -0500 | [diff] [blame] | 19 | // Actually declared/defined in //aos/testing:test_logging. |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 20 | void SetLogFileName(const char *filename) __attribute__((weak)); |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 21 | void ForcePrintLogsDuringTests() __attribute__((weak)); |
| 22 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 23 | } // namespace aos::testing |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 24 | |
| 25 | GTEST_API_ int main(int argc, char **argv) { |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 26 | ::testing::InitGoogleTest(&argc, argv); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 27 | FLAGS_logtostderr = true; |
Austin Schuh | 6228825 | 2020-11-18 23:26:04 -0800 | [diff] [blame] | 28 | |
| 29 | aos::InitGoogle(&argc, &argv); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 30 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 31 | if (FLAGS_print_logs) { |
| 32 | if (::aos::testing::ForcePrintLogsDuringTests) { |
| 33 | ::aos::testing::ForcePrintLogsDuringTests(); |
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 | } |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 36 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 37 | if (!FLAGS_log_file.empty()) { |
| 38 | if (::aos::testing::ForcePrintLogsDuringTests) { |
| 39 | ::aos::testing::ForcePrintLogsDuringTests(); |
| 40 | } |
| 41 | if (::aos::testing::SetLogFileName) { |
| 42 | ::aos::testing::SetLogFileName(FLAGS_log_file.c_str()); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
Austin Schuh | cdab619 | 2019-12-29 17:47:46 -0800 | [diff] [blame] | 46 | // Point shared memory away from /dev/shm if we are testing. We don't care |
| 47 | // 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] | 48 | aos::testing::SetTestShmBase(); |
Austin Schuh | cdab619 | 2019-12-29 17:47:46 -0800 | [diff] [blame] | 49 | |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 50 | return RUN_ALL_TESTS(); |
| 51 | } |