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