blob: 6071bdea8443d42745c73976c07a121296cf844f [file] [log] [blame]
Philipp Schradere41ed9d2015-03-15 22:57:13 +00001#include <getopt.h>
2
Austin Schuh60e77942022-05-16 17:48:24 -07003#include <iostream>
4
Austin Schuh6b73f0d2019-01-07 17:03:03 -08005#include "gflags/gflags.h"
Austin Schuhcb108412019-10-13 16:09:54 -07006#include "glog/logging.h"
Philipp Schradere41ed9d2015-03-15 22:57:13 +00007#include "gtest/gtest.h"
Brian Silverman9c72d7b2015-03-30 17:29:04 -04008
Philipp Schrader790cb542023-07-05 21:06:52 -07009#include "aos/init.h"
Adam Snaiderc8b7e752023-09-14 14:27:53 -070010#include "aos/testing/tmpdir.h"
Philipp Schrader790cb542023-07-05 21:06:52 -070011
Austin Schuh6b73f0d2019-01-07 17:03:03 -080012DEFINE_bool(print_logs, false,
13 "Print the log messages as they are being generated.");
14DEFINE_string(log_file, "",
15 "Print all log messages to FILE instead of standard output.");
16
Stephan Pleinesf63bde82024-01-13 15:59:33 -080017namespace aos::testing {
Brian Silverman9c72d7b2015-03-30 17:29:04 -040018
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050019// Actually declared/defined in //aos/testing:test_logging.
Austin Schuh60e77942022-05-16 17:48:24 -070020void SetLogFileName(const char *filename) __attribute__((weak));
Brian Silverman9c72d7b2015-03-30 17:29:04 -040021void ForcePrintLogsDuringTests() __attribute__((weak));
22
Stephan Pleinesf63bde82024-01-13 15:59:33 -080023} // namespace aos::testing
Philipp Schradere41ed9d2015-03-15 22:57:13 +000024
25GTEST_API_ int main(int argc, char **argv) {
Austin Schuh6b73f0d2019-01-07 17:03:03 -080026 ::testing::InitGoogleTest(&argc, argv);
Austin Schuhcb108412019-10-13 16:09:54 -070027 FLAGS_logtostderr = true;
Austin Schuh62288252020-11-18 23:26:04 -080028
29 aos::InitGoogle(&argc, &argv);
Philipp Schradere41ed9d2015-03-15 22:57:13 +000030
Austin Schuh6b73f0d2019-01-07 17:03:03 -080031 if (FLAGS_print_logs) {
32 if (::aos::testing::ForcePrintLogsDuringTests) {
33 ::aos::testing::ForcePrintLogsDuringTests();
Philipp Schradere41ed9d2015-03-15 22:57:13 +000034 }
Austin Schuh6b73f0d2019-01-07 17:03:03 -080035 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000036
Austin Schuh6b73f0d2019-01-07 17:03:03 -080037 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 Schradere41ed9d2015-03-15 22:57:13 +000043 }
44 }
45
Austin Schuhcdab6192019-12-29 17:47:46 -080046 // 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 Snaiderc8b7e752023-09-14 14:27:53 -070048 aos::testing::SetTestShmBase();
Austin Schuhcdab6192019-12-29 17:47:46 -080049
Philipp Schradere41ed9d2015-03-15 22:57:13 +000050 return RUN_ALL_TESTS();
51}