1 
2 #include <gmock/gmock.h>
3 #include <gtest/gtest.h>
4 
5 #include <iostream>
6 #include <sstream>
7 
8 #include "nugget_tools.h"
9 
10 #ifdef ANDROID
11 #define FLAGS_list_slow_tests false
12 #define FLAGS_disable_slow_tests false
13 // TODO: how does FLAGS_release_tests feature here?
14 #define FLAGS_release_tests true
15 #else
16 #include <gflags/gflags.h>
17 DEFINE_bool(list_slow_tests, false, "List tests included in the set of slow tests.");
18 DEFINE_bool(disable_slow_tests, false, "Enables a filter to disable a set of slow tests.");
19 DEFINE_bool(release_tests, false, "Disables tests that would fail for firmware images built with TEST_IMAGE=0");
20 #endif  // ANDROID
21 
generate_disabled_test_list(const std::vector<std::string> & tests,std::stringstream * ss)22 static void generate_disabled_test_list(
23     const std::vector<std::string>& tests,
24     std::stringstream *ss) {
25     for (const auto& test : tests) {
26       if (ss->tellp() == 0) {
27         *ss << "-";
28       } else {
29         *ss << ":";
30       }
31       *ss << test;
32     }
33 }
34 
main(int argc,char ** argv)35 int main(int argc, char** argv) {
36   const std::vector<std::string> slow_tests{
37       "AvbTest.*",
38       "ImportKeyTest.RSASuccess",
39       "NuggetCoreTest.EnterDeepSleep",
40       "NuggetCoreTest.HardRebootTest",
41       "WeaverTest.ReadAttemptCounterPersistsDeepSleep",
42       "WeaverTest.ReadAttemptCounterPersistsHardReboot",
43       "WeaverTest.ReadThrottleAfterDeepSleep",
44       "WeaverTest.ReadThrottleAfterHardReboot",
45       "WeaverTest.ReadThrottleAfterSleep",
46       "WeaverTest.WriteDeepSleepRead",
47       "WeaverTest.WriteHardRebootRead",
48   };
49 
50   const std::vector<std::string> disabled_for_release_tests{
51       "DcryptoTest.AesCmacRfc4493Test",
52       "KeymasterProvisionTest.ProvisionDeviceIdsSuccess",
53       "KeymasterProvisionTest.ReProvisionDeviceIdsSuccess",
54       "KeymasterProvisionTest.ProductionModeProvisionFails",
55       "KeymasterProvisionTest.InvalidDeviceIdFails",
56       "KeymasterProvisionTest.MaxDeviceIdSuccess",
57       "KeymasterProvisionTest.NoMeidSuccess",
58       "NuggetCoreTest.GetUartPassthruInBootloader",
59       "NuggetCoreTest.EnableUartPassthruInBootloader",
60       "NuggetCoreTest.DisableUartPassthruInBootloader",
61       "NuggetOsTest.NoticePing",
62       "NuggetOsTest.InvalidMessageType",
63       "NuggetOsTest.Sequence",
64       "NuggetOsTest.Echo",
65       "NuggetOsTest.AesCbc",
66       "NuggetOsTest.Trng",
67       "WeaverTest.ProductionResetWipesUserData",
68       "AvbTest.*",
69       "ImportKeyTest.*",
70       "ImportWrappedKeyTest.ImportSuccess",
71   };
72 
73   const std::vector<std::string> disabled_for_non_direct_device_tests{
74       "TransportTest.*",
75   };
76 
77   testing::InitGoogleMock(&argc, argv);
78 #ifndef ANDROID
79   google::ParseCommandLineFlags(&argc, &argv, true);
80 #endif  // ANDROID
81 
82   if (FLAGS_list_slow_tests) {
83     std::cout << "Slow tests:\n";
84     for (const auto& test : slow_tests) {
85       std::cout << "  " << test << "\n";
86     }
87     std::cout.flush();
88     exit(0);
89   }
90 
91   std::stringstream ss;
92   if (FLAGS_disable_slow_tests) {
93     generate_disabled_test_list(slow_tests, &ss);
94   }
95   if (FLAGS_release_tests) {
96     generate_disabled_test_list(disabled_for_release_tests, &ss);
97   }
98   if (!nugget_tools::IsDirectDeviceClient()) {
99     generate_disabled_test_list(disabled_for_non_direct_device_tests, &ss);
100   }
101 
102   if (FLAGS_disable_slow_tests || FLAGS_release_tests) {
103     ::testing::GTEST_FLAG(filter) = ss.str();
104   }
105 
106   return RUN_ALL_TESTS();
107 }
108