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 { |
| 7 | namespace common { |
| 8 | namespace testing { |
| 9 | |
| 10 | // Actually declared/defined in aos/common/queue_testutils. |
| 11 | void SetLogFileName(const char* filename) __attribute__((weak)); |
| 12 | void ForcePrintLogsDuringTests() __attribute__((weak)); |
| 13 | |
| 14 | } // namespace testing |
| 15 | } // namespace common |
| 16 | } // namespace aos |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 17 | |
| 18 | GTEST_API_ int main(int argc, char **argv) { |
| 19 | static const struct option long_options[] = { |
| 20 | {"help", no_argument, 0, 'h'}, |
| 21 | {"print-logs", no_argument, 0, 'p'}, |
| 22 | {"log-file", required_argument, 0, 'o'}, |
| 23 | {0, 0, 0, 0}, |
| 24 | }; |
| 25 | |
| 26 | testing::InitGoogleTest(&argc, argv); |
| 27 | |
| 28 | // The gtest library modifies argc and argv to remove all of its own command |
| 29 | // line switches etc. So after calling InitGoogleTest() we can parse our own |
| 30 | // command line options. |
| 31 | while (true) { |
| 32 | int c = getopt_long(argc, argv, "po:", long_options, nullptr); |
| 33 | |
| 34 | if (c == -1) { |
| 35 | break; |
| 36 | } |
| 37 | |
| 38 | switch (c) { |
| 39 | case 'h': |
| 40 | printf( |
| 41 | "\nFRC971 options:\n" |
| 42 | " -p, --print-logs\n" |
| 43 | " Print the log messages as they are being generated.\n" |
| 44 | " -o, --log-file=FILE\n" |
| 45 | " Print all log messages to FILE instead of standard output\n" |
| 46 | ); |
| 47 | break; |
| 48 | |
| 49 | case 'p': |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame^] | 50 | if (::aos::common::testing::ForcePrintLogsDuringTests) { |
| 51 | ::aos::common::testing::ForcePrintLogsDuringTests(); |
| 52 | } |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 53 | break; |
| 54 | |
| 55 | case 'o': |
Brian Silverman | 9c72d7b | 2015-03-30 17:29:04 -0400 | [diff] [blame^] | 56 | if (::aos::common::testing::SetLogFileName) { |
| 57 | ::aos::common::testing::SetLogFileName(optarg); |
| 58 | } |
Philipp Schrader | e41ed9d | 2015-03-15 22:57:13 +0000 | [diff] [blame] | 59 | break; |
| 60 | |
| 61 | case '?': |
| 62 | abort(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return RUN_ALL_TESTS(); |
| 67 | } |