blob: 52159c3805b2760e1e6900a26a6b14f575cd53fd [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);
Alex Perrycb7da4b2019-08-28 19:35:56 -070028 google::InstallFailureSignalHandler();
Philipp Schradere41ed9d2015-03-15 22:57:13 +000029
Austin Schuh6b73f0d2019-01-07 17:03:03 -080030 if (FLAGS_print_logs) {
31 if (::aos::testing::ForcePrintLogsDuringTests) {
32 ::aos::testing::ForcePrintLogsDuringTests();
Philipp Schradere41ed9d2015-03-15 22:57:13 +000033 }
Austin Schuh6b73f0d2019-01-07 17:03:03 -080034 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000035
Austin Schuh6b73f0d2019-01-07 17:03:03 -080036 if (!FLAGS_log_file.empty()) {
37 if (::aos::testing::ForcePrintLogsDuringTests) {
38 ::aos::testing::ForcePrintLogsDuringTests();
39 }
40 if (::aos::testing::SetLogFileName) {
41 ::aos::testing::SetLogFileName(FLAGS_log_file.c_str());
Philipp Schradere41ed9d2015-03-15 22:57:13 +000042 }
43 }
44
45 return RUN_ALL_TESTS();
46}