blob: e2ba564deb792828cb52aa3149db9692a49d8e16 [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"
Tyler Chatoweaa8e1c2017-01-14 21:55:35 +000043 " Print all log messages to FILE instead of standard output.\n"
44 " This implies -p.\n"
Philipp Schradere41ed9d2015-03-15 22:57:13 +000045 );
46 break;
47
48 case 'p':
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050049 if (::aos::testing::ForcePrintLogsDuringTests) {
50 ::aos::testing::ForcePrintLogsDuringTests();
Brian Silverman9c72d7b2015-03-30 17:29:04 -040051 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000052 break;
53
54 case 'o':
Tyler Chatoweaa8e1c2017-01-14 21:55:35 +000055 if (::aos::testing::ForcePrintLogsDuringTests) {
56 ::aos::testing::ForcePrintLogsDuringTests();
57 }
Brian Silvermanf5f8d8e2015-12-06 18:39:12 -050058 if (::aos::testing::SetLogFileName) {
59 ::aos::testing::SetLogFileName(optarg);
Brian Silverman9c72d7b2015-03-30 17:29:04 -040060 }
Philipp Schradere41ed9d2015-03-15 22:57:13 +000061 break;
62
63 case '?':
64 abort();
65 }
66 }
67
68 return RUN_ALL_TESTS();
69}