blob: 21f141fa1494d07643ff2ff9e34fccf72a13bb22 [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"
10
Austin Schuh6b73f0d2019-01-07 17:03:03 -080011DEFINE_bool(print_logs, false,
12 "Print the log messages as they are being generated.");
13DEFINE_string(log_file, "",
14 "Print all log messages to FILE instead of standard output.");
15
Brian Silverman9c72d7b2015-03-30 17:29:04 -040016namespace aos {
Austin Schuhcdab6192019-12-29 17:47:46 -080017void SetShmBase(const std::string_view base) __attribute__((weak));
18
Brian Silverman9c72d7b2015-03-30 17:29:04 -040019namespace testing {
20
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050021// Actually declared/defined in //aos/testing:test_logging.
Austin Schuh60e77942022-05-16 17:48:24 -070022void SetLogFileName(const char *filename) __attribute__((weak));
Brian Silverman9c72d7b2015-03-30 17:29:04 -040023void ForcePrintLogsDuringTests() __attribute__((weak));
24
25} // namespace testing
Brian Silverman9c72d7b2015-03-30 17:29:04 -040026} // namespace aos
Philipp Schradere41ed9d2015-03-15 22:57:13 +000027
28GTEST_API_ int main(int argc, char **argv) {
Austin Schuh6b73f0d2019-01-07 17:03:03 -080029 ::testing::InitGoogleTest(&argc, argv);
Austin Schuhcb108412019-10-13 16:09:54 -070030 FLAGS_logtostderr = true;
Austin Schuh62288252020-11-18 23:26:04 -080031
32 aos::InitGoogle(&argc, &argv);
Philipp Schradere41ed9d2015-03-15 22:57:13 +000033
Austin Schuh6b73f0d2019-01-07 17:03:03 -080034 if (FLAGS_print_logs) {
35 if (::aos::testing::ForcePrintLogsDuringTests) {
36 ::aos::testing::ForcePrintLogsDuringTests();
Philipp Schradere41ed9d2015-03-15 22:57:13 +000037 }
Austin Schuh6b73f0d2019-01-07 17:03:03 -080038 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000039
Austin Schuh6b73f0d2019-01-07 17:03:03 -080040 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 Schradere41ed9d2015-03-15 22:57:13 +000046 }
47 }
48
Austin Schuhcdab6192019-12-29 17:47:46 -080049 // 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 Schradere41ed9d2015-03-15 22:57:13 +000058 return RUN_ALL_TESTS();
59}