blob: ef632932470d19613bea10b17f67688caca1df53 [file] [log] [blame]
Philipp Schradere41ed9d2015-03-15 22:57:13 +00001#include <iostream>
2#include <getopt.h>
3
4#include "gtest/gtest.h"
Brian Silverman9c72d7b2015-03-30 17:29:04 -04005
6namespace aos {
Brian Silverman9c72d7b2015-03-30 17:29:04 -04007namespace testing {
8
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -05009// Actually declared/defined in //aos/testing:test_logging.
Brian Silverman9c72d7b2015-03-30 17:29:04 -040010void SetLogFileName(const char* filename) __attribute__((weak));
11void ForcePrintLogsDuringTests() __attribute__((weak));
12
13} // namespace testing
Brian Silverman9c72d7b2015-03-30 17:29:04 -040014} // namespace aos
Philipp Schradere41ed9d2015-03-15 22:57:13 +000015
16GTEST_API_ int main(int argc, char **argv) {
17 static const struct option long_options[] = {
18 {"help", no_argument, 0, 'h'},
19 {"print-logs", no_argument, 0, 'p'},
20 {"log-file", required_argument, 0, 'o'},
21 {0, 0, 0, 0},
22 };
23
24 testing::InitGoogleTest(&argc, argv);
25
26 // The gtest library modifies argc and argv to remove all of its own command
27 // line switches etc. So after calling InitGoogleTest() we can parse our own
28 // command line options.
29 while (true) {
Debby Sillman98662682015-07-09 04:20:07 +000030 int c = getopt_long(argc, argv, "pho:", long_options, nullptr);
Philipp Schradere41ed9d2015-03-15 22:57:13 +000031
32 if (c == -1) {
33 break;
34 }
35
36 switch (c) {
37 case 'h':
38 printf(
39 "\nFRC971 options:\n"
40 " -p, --print-logs\n"
41 " Print the log messages as they are being generated.\n"
42 " -o, --log-file=FILE\n"
43 " Print all log messages to FILE instead of standard output\n"
44 );
45 break;
46
47 case 'p':
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050048 if (::aos::testing::ForcePrintLogsDuringTests) {
49 ::aos::testing::ForcePrintLogsDuringTests();
Brian Silverman9c72d7b2015-03-30 17:29:04 -040050 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000051 break;
52
53 case 'o':
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050054 if (::aos::testing::SetLogFileName) {
55 ::aos::testing::SetLogFileName(optarg);
Brian Silverman9c72d7b2015-03-30 17:29:04 -040056 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000057 break;
58
59 case '?':
60 abort();
61 }
62 }
63
64 return RUN_ALL_TESTS();
65}