blob: 19409889430854d19d0f2d5ed539a0db78d60d98 [file] [log] [blame]
Austin Schuh6b73f0d2019-01-07 17:03:03 -08001#include "gflags/gflags.h"
Austin Schuhcb108412019-10-13 16:09:54 -07002#include "glog/logging.h"
Philipp Schradere41ed9d2015-03-15 22:57:13 +00003#include "gtest/gtest.h"
Brian Silverman9c72d7b2015-03-30 17:29:04 -04004
Philipp Schrader790cb542023-07-05 21:06:52 -07005#include "aos/init.h"
Adam Snaiderc8b7e752023-09-14 14:27:53 -07006#include "aos/testing/tmpdir.h"
Philipp Schrader790cb542023-07-05 21:06:52 -07007
Austin Schuh6b73f0d2019-01-07 17:03:03 -08008DEFINE_bool(print_logs, false,
9 "Print the log messages as they are being generated.");
10DEFINE_string(log_file, "",
11 "Print all log messages to FILE instead of standard output.");
12
Stephan Pleinesf63bde82024-01-13 15:59:33 -080013namespace aos::testing {
Brian Silverman9c72d7b2015-03-30 17:29:04 -040014
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050015// Actually declared/defined in //aos/testing:test_logging.
Austin Schuh60e77942022-05-16 17:48:24 -070016void SetLogFileName(const char *filename) __attribute__((weak));
Brian Silverman9c72d7b2015-03-30 17:29:04 -040017void ForcePrintLogsDuringTests() __attribute__((weak));
18
Stephan Pleinesf63bde82024-01-13 15:59:33 -080019} // namespace aos::testing
Philipp Schradere41ed9d2015-03-15 22:57:13 +000020
21GTEST_API_ int main(int argc, char **argv) {
Austin Schuh6b73f0d2019-01-07 17:03:03 -080022 ::testing::InitGoogleTest(&argc, argv);
Austin Schuhcb108412019-10-13 16:09:54 -070023 FLAGS_logtostderr = true;
Austin Schuh62288252020-11-18 23:26:04 -080024
25 aos::InitGoogle(&argc, &argv);
Philipp Schradere41ed9d2015-03-15 22:57:13 +000026
Austin Schuh6b73f0d2019-01-07 17:03:03 -080027 if (FLAGS_print_logs) {
28 if (::aos::testing::ForcePrintLogsDuringTests) {
29 ::aos::testing::ForcePrintLogsDuringTests();
Philipp Schradere41ed9d2015-03-15 22:57:13 +000030 }
Austin Schuh6b73f0d2019-01-07 17:03:03 -080031 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000032
Austin Schuh6b73f0d2019-01-07 17:03:03 -080033 if (!FLAGS_log_file.empty()) {
34 if (::aos::testing::ForcePrintLogsDuringTests) {
35 ::aos::testing::ForcePrintLogsDuringTests();
36 }
37 if (::aos::testing::SetLogFileName) {
38 ::aos::testing::SetLogFileName(FLAGS_log_file.c_str());
Philipp Schradere41ed9d2015-03-15 22:57:13 +000039 }
40 }
41
Austin Schuhcdab6192019-12-29 17:47:46 -080042 // Point shared memory away from /dev/shm if we are testing. We don't care
43 // about RT in this case, so if it is backed by disk, we are fine.
Adam Snaiderc8b7e752023-09-14 14:27:53 -070044 aos::testing::SetTestShmBase();
Austin Schuhcdab6192019-12-29 17:47:46 -080045
Philipp Schradere41ed9d2015-03-15 22:57:13 +000046 return RUN_ALL_TESTS();
47}