blob: c8c50623c738e1bfffe883b47aad19479c2e77e3 [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"
Austin Schuhcb108412019-10-13 16:09:54 -07005#include "glog/logging.h"
Philipp Schradere41ed9d2015-03-15 22:57:13 +00006#include "gtest/gtest.h"
Brian Silverman9c72d7b2015-03-30 17:29:04 -04007
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
Brian Silverman9c72d7b2015-03-30 17:29:04 -040013namespace aos {
Brian Silverman9c72d7b2015-03-30 17:29:04 -040014namespace testing {
15
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050016// Actually declared/defined in //aos/testing:test_logging.
Brian Silverman9c72d7b2015-03-30 17:29:04 -040017void SetLogFileName(const char* filename) __attribute__((weak));
18void ForcePrintLogsDuringTests() __attribute__((weak));
19
20} // namespace testing
Brian Silverman9c72d7b2015-03-30 17:29:04 -040021} // namespace aos
Philipp Schradere41ed9d2015-03-15 22:57:13 +000022
23GTEST_API_ int main(int argc, char **argv) {
Austin Schuh6b73f0d2019-01-07 17:03:03 -080024 ::testing::InitGoogleTest(&argc, argv);
Austin Schuhcb108412019-10-13 16:09:54 -070025 FLAGS_logtostderr = true;
26 google::InitGoogleLogging(argv[0]);
Austin Schuh6b73f0d2019-01-07 17:03:03 -080027 ::gflags::ParseCommandLineFlags(&argc, &argv, false);
Philipp Schradere41ed9d2015-03-15 22:57:13 +000028
Austin Schuh6b73f0d2019-01-07 17:03:03 -080029 if (FLAGS_print_logs) {
30 if (::aos::testing::ForcePrintLogsDuringTests) {
31 ::aos::testing::ForcePrintLogsDuringTests();
Philipp Schradere41ed9d2015-03-15 22:57:13 +000032 }
Austin Schuh6b73f0d2019-01-07 17:03:03 -080033 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000034
Austin Schuh6b73f0d2019-01-07 17:03:03 -080035 if (!FLAGS_log_file.empty()) {
36 if (::aos::testing::ForcePrintLogsDuringTests) {
37 ::aos::testing::ForcePrintLogsDuringTests();
38 }
39 if (::aos::testing::SetLogFileName) {
40 ::aos::testing::SetLogFileName(FLAGS_log_file.c_str());
Philipp Schradere41ed9d2015-03-15 22:57:13 +000041 }
42 }
43
44 return RUN_ALL_TESTS();
45}