Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 1 | #include <iostream> |
| 2 | #include <getopt.h> |
| 3 | |
| 4 | #include "gtest/gtest.h" |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 5 | |
| 6 | namespace aos { |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 7 | namespace testing { |
| 8 | |
Brian Silverman | f5f8d8e | 2015-12-06 18:39:12 -0500 | [diff] [blame] | 9 | // Actually declared/defined in //aos/testing:test_logging. |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 10 | void SetLogFileName(const char* filename) __attribute__((weak)); |
| 11 | void ForcePrintLogsDuringTests() __attribute__((weak)); |
| 12 | |
| 13 | } // namespace testing |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 14 | } // namespace aos |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 15 | |
| 16 | GTEST_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 Sillman | 9866268 | 2015-07-09 04:20:07 +0000 | [diff] [blame] | 30 | int c = getopt_long(argc, argv, "pho:", long_options, nullptr); |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 31 | |
| 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 Silverman | f5f8d8e | 2015-12-06 18:39:12 -0500 | [diff] [blame] | 48 | if (::aos::testing::ForcePrintLogsDuringTests) { |
| 49 | ::aos::testing::ForcePrintLogsDuringTests(); |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 50 | } |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 51 | break; |
| 52 | |
| 53 | case 'o': |
Brian Silverman | f5f8d8e | 2015-12-06 18:39:12 -0500 | [diff] [blame] | 54 | if (::aos::testing::SetLogFileName) { |
| 55 | ::aos::testing::SetLogFileName(optarg); |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame] | 56 | } |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 57 | break; |
| 58 | |
| 59 | case '?': |
| 60 | abort(); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return RUN_ALL_TESTS(); |
| 65 | } |