blob: ecf2889cb9c684c54aabfc798472b1cb4406cbee [file] [log] [blame]
Austin Schuh99f7c6a2024-06-25 22:07:44 -07001#include "absl/flags/flag.h"
2#include "absl/log/check.h"
3#include "absl/log/log.h"
Philipp Schradere41ed9d2015-03-15 22:57:13 +00004#include "gtest/gtest.h"
Brian Silverman9c72d7b2015-03-30 17:29:04 -04005
Philipp Schrader790cb542023-07-05 21:06:52 -07006#include "aos/init.h"
Adam Snaiderc8b7e752023-09-14 14:27:53 -07007#include "aos/testing/tmpdir.h"
Philipp Schrader790cb542023-07-05 21:06:52 -07008
Austin Schuh99f7c6a2024-06-25 22:07:44 -07009ABSL_FLAG(bool, print_logs, false,
10 "Print the log messages as they are being generated.");
11ABSL_FLAG(std::string, log_file, "",
12 "Print all log messages to FILE instead of standard output.");
Austin Schuh6b73f0d2019-01-07 17:03:03 -080013
Stephan Pleinesf63bde82024-01-13 15:59:33 -080014namespace aos::testing {
Brian Silverman9c72d7b2015-03-30 17:29:04 -040015
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050016// Actually declared/defined in //aos/testing:test_logging.
Austin Schuh60e77942022-05-16 17:48:24 -070017void SetLogFileName(const char *filename) __attribute__((weak));
Brian Silverman9c72d7b2015-03-30 17:29:04 -040018void ForcePrintLogsDuringTests() __attribute__((weak));
19
Stephan Pleinesf63bde82024-01-13 15:59:33 -080020} // namespace aos::testing
Philipp Schradere41ed9d2015-03-15 22:57:13 +000021
22GTEST_API_ int main(int argc, char **argv) {
Austin Schuh6b73f0d2019-01-07 17:03:03 -080023 ::testing::InitGoogleTest(&argc, argv);
Austin Schuh62288252020-11-18 23:26:04 -080024 aos::InitGoogle(&argc, &argv);
Philipp Schradere41ed9d2015-03-15 22:57:13 +000025
Austin Schuh99f7c6a2024-06-25 22:07:44 -070026 if (absl::GetFlag(FLAGS_print_logs)) {
Austin Schuh6b73f0d2019-01-07 17:03:03 -080027 if (::aos::testing::ForcePrintLogsDuringTests) {
28 ::aos::testing::ForcePrintLogsDuringTests();
Philipp Schradere41ed9d2015-03-15 22:57:13 +000029 }
Austin Schuh6b73f0d2019-01-07 17:03:03 -080030 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000031
Austin Schuh99f7c6a2024-06-25 22:07:44 -070032 if (!absl::GetFlag(FLAGS_log_file).empty()) {
Austin Schuh6b73f0d2019-01-07 17:03:03 -080033 if (::aos::testing::ForcePrintLogsDuringTests) {
34 ::aos::testing::ForcePrintLogsDuringTests();
35 }
36 if (::aos::testing::SetLogFileName) {
Austin Schuh99f7c6a2024-06-25 22:07:44 -070037 ::aos::testing::SetLogFileName(absl::GetFlag(FLAGS_log_file).c_str());
Philipp Schradere41ed9d2015-03-15 22:57:13 +000038 }
39 }
40
Austin Schuhcdab6192019-12-29 17:47:46 -080041 // 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 Snaiderc8b7e752023-09-14 14:27:53 -070043 aos::testing::SetTestShmBase();
Austin Schuhcdab6192019-12-29 17:47:46 -080044
Philipp Schradere41ed9d2015-03-15 22:57:13 +000045 return RUN_ALL_TESTS();
46}