blob: 7acfe5afab7062b20d55dc3d4c642766259970ca [file] [log] [blame]
Philipp Schradere41ed9d2015-03-15 22:57:13 +00001#include <iostream>
2#include <getopt.h>
3
Austin Schuh6b73f0d2019-01-07 17:03:03 -08004#include "gflags/gflags.h"
Philipp Schradere41ed9d2015-03-15 22:57:13 +00005#include "gtest/gtest.h"
Brian Silverman9c72d7b2015-03-30 17:29:04 -04006
Austin Schuh6b73f0d2019-01-07 17:03:03 -08007DEFINE_bool(print_logs, false,
8 "Print the log messages as they are being generated.");
9DEFINE_string(log_file, "",
10 "Print all log messages to FILE instead of standard output.");
11
Brian Silverman9c72d7b2015-03-30 17:29:04 -040012namespace aos {
Brian Silverman9c72d7b2015-03-30 17:29:04 -040013namespace testing {
14
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050015// Actually declared/defined in //aos/testing:test_logging.
Brian Silverman9c72d7b2015-03-30 17:29:04 -040016void SetLogFileName(const char* filename) __attribute__((weak));
17void ForcePrintLogsDuringTests() __attribute__((weak));
18
19} // namespace testing
Brian Silverman9c72d7b2015-03-30 17:29:04 -040020} // namespace aos
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);
24 ::gflags::ParseCommandLineFlags(&argc, &argv, false);
Philipp Schradere41ed9d2015-03-15 22:57:13 +000025
Austin Schuh6b73f0d2019-01-07 17:03:03 -080026 if (FLAGS_print_logs) {
27 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 Schuh6b73f0d2019-01-07 17:03:03 -080032 if (!FLAGS_log_file.empty()) {
33 if (::aos::testing::ForcePrintLogsDuringTests) {
34 ::aos::testing::ForcePrintLogsDuringTests();
35 }
36 if (::aos::testing::SetLogFileName) {
37 ::aos::testing::SetLogFileName(FLAGS_log_file.c_str());
Philipp Schradere41ed9d2015-03-15 22:57:13 +000038 }
39 }
40
41 return RUN_ALL_TESTS();
42}