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" |
| 10 | |
Austin Schuh | 6b73f0d | 2019-01-07 17:03:03 -0800 | [diff] [blame] | 11 | DEFINE_bool(print_logs, false, |
| 12 | "Print the log messages as they are being generated."); |
| 13 | DEFINE_string(log_file, "", |
| 14 | "Print all log messages to FILE instead of standard output."); |
| 15 | |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 16 | namespace aos { |
Austin Schuh | cdab619 | 2019-12-29 17:47:46 -0800 | [diff] [blame] | 17 | void SetShmBase(const std::string_view base) __attribute__((weak)); |
| 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. |
| 51 | if (::aos::SetShmBase) { |
| 52 | const char *tmpdir_c_str = getenv("TEST_TMPDIR"); |
| 53 | if (tmpdir_c_str != nullptr) { |
| 54 | aos::SetShmBase(tmpdir_c_str); |
| 55 | } |
| 56 | } |
| 57 | |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 58 | return RUN_ALL_TESTS(); |
| 59 | } |