blob: 0f6b60e2575c9f7b420e9a1d587e36a07ec2b487 [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 {
7namespace common {
8namespace testing {
9
10// Actually declared/defined in aos/common/queue_testutils.
11void SetLogFileName(const char* filename) __attribute__((weak));
12void ForcePrintLogsDuringTests() __attribute__((weak));
13
14} // namespace testing
15} // namespace common
16} // namespace aos
Philipp Schradere41ed9d2015-03-15 22:57:13 +000017
18GTEST_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 Silverman9c72d7b2015-03-30 17:29:04 -040050 if (::aos::common::testing::ForcePrintLogsDuringTests) {
51 ::aos::common::testing::ForcePrintLogsDuringTests();
52 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000053 break;
54
55 case 'o':
Brian Silverman9c72d7b2015-03-30 17:29:04 -040056 if (::aos::common::testing::SetLogFileName) {
57 ::aos::common::testing::SetLogFileName(optarg);
58 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000059 break;
60
61 case '?':
62 abort();
63 }
64 }
65
66 return RUN_ALL_TESTS();
67}