blob: c8e31729341c4cab8984453721d0c16caf61133b [file] [log] [blame]
Philipp Schradere41ed9d2015-03-15 22:57:13 +00001#include <iostream>
2#include <getopt.h>
3
Austin Schuh62288252020-11-18 23:26:04 -08004#include "aos/init.h"
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
Austin Schuh6b73f0d2019-01-07 17:03:03 -08009DEFINE_bool(print_logs, false,
10 "Print the log messages as they are being generated.");
11DEFINE_string(log_file, "",
12 "Print all log messages to FILE instead of standard output.");
13
Brian Silverman9c72d7b2015-03-30 17:29:04 -040014namespace aos {
Austin Schuhcdab6192019-12-29 17:47:46 -080015void SetShmBase(const std::string_view base) __attribute__((weak));
16
Brian Silverman9c72d7b2015-03-30 17:29:04 -040017namespace testing {
18
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050019// Actually declared/defined in //aos/testing:test_logging.
Brian Silverman9c72d7b2015-03-30 17:29:04 -040020void SetLogFileName(const char* filename) __attribute__((weak));
21void ForcePrintLogsDuringTests() __attribute__((weak));
22
23} // namespace testing
Brian Silverman9c72d7b2015-03-30 17:29:04 -040024} // namespace aos
Philipp Schradere41ed9d2015-03-15 22:57:13 +000025
26GTEST_API_ int main(int argc, char **argv) {
Austin Schuh6b73f0d2019-01-07 17:03:03 -080027 ::testing::InitGoogleTest(&argc, argv);
Austin Schuhcb108412019-10-13 16:09:54 -070028 FLAGS_logtostderr = true;
Austin Schuh62288252020-11-18 23:26:04 -080029
30 aos::InitGoogle(&argc, &argv);
Philipp Schradere41ed9d2015-03-15 22:57:13 +000031
Austin Schuh6b73f0d2019-01-07 17:03:03 -080032 if (FLAGS_print_logs) {
33 if (::aos::testing::ForcePrintLogsDuringTests) {
34 ::aos::testing::ForcePrintLogsDuringTests();
Philipp Schradere41ed9d2015-03-15 22:57:13 +000035 }
Austin Schuh6b73f0d2019-01-07 17:03:03 -080036 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000037
Austin Schuh6b73f0d2019-01-07 17:03:03 -080038 if (!FLAGS_log_file.empty()) {
39 if (::aos::testing::ForcePrintLogsDuringTests) {
40 ::aos::testing::ForcePrintLogsDuringTests();
41 }
42 if (::aos::testing::SetLogFileName) {
43 ::aos::testing::SetLogFileName(FLAGS_log_file.c_str());
Philipp Schradere41ed9d2015-03-15 22:57:13 +000044 }
45 }
46
Austin Schuhcdab6192019-12-29 17:47:46 -080047 // Point shared memory away from /dev/shm if we are testing. We don't care
48 // about RT in this case, so if it is backed by disk, we are fine.
49 if (::aos::SetShmBase) {
50 const char *tmpdir_c_str = getenv("TEST_TMPDIR");
51 if (tmpdir_c_str != nullptr) {
52 aos::SetShmBase(tmpdir_c_str);
53 }
54 }
55
Philipp Schradere41ed9d2015-03-15 22:57:13 +000056 return RUN_ALL_TESTS();
57}