run_all_unittests.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <iostream>
  5. #include "base/bind.h"
  6. #include "base/build_time.h"
  7. #include "base/test/launcher/unit_test_launcher.h"
  8. #include "build/build_config.h"
  9. #include "crypto/nss_util.h"
  10. #include "net/socket/transport_client_socket_pool.h"
  11. #include "net/test/net_test_suite.h"
  12. #include "url/buildflags.h"
  13. namespace {
  14. bool VerifyBuildIsTimely() {
  15. // This lines up with various //net security features, like Certificate
  16. // Transparency or HPKP, in that they require the build time be less than 70
  17. // days old. Moreover, operating on the assumption that tests are run against
  18. // recently compiled builds, this also serves as a sanity check for the
  19. // system clock, which should be close to the build date.
  20. base::TimeDelta kMaxAge = base::Days(70);
  21. base::Time build_time = base::GetBuildTime();
  22. base::Time now = base::Time::Now();
  23. if ((now - build_time).magnitude() <= kMaxAge)
  24. return true;
  25. std::cerr
  26. << "ERROR: This build is more than " << kMaxAge.InDays()
  27. << " days out of date.\n"
  28. "This could indicate a problem with the device's clock, or the build "
  29. "is simply too old.\n"
  30. "See crbug.com/666821 for why this is a problem\n"
  31. << " base::Time::Now() --> " << now << " (" << now.ToInternalValue()
  32. << ")\n"
  33. << " base::GetBuildTime() --> " << build_time << " ("
  34. << build_time.ToInternalValue() << ")\n";
  35. return false;
  36. }
  37. } // namespace
  38. int main(int argc, char** argv) {
  39. if (!VerifyBuildIsTimely())
  40. return 1;
  41. NetTestSuite test_suite(argc, argv);
  42. net::TransportClientSocketPool::set_connect_backup_jobs_enabled(false);
  43. return base::LaunchUnitTests(
  44. argc, argv,
  45. base::BindOnce(&NetTestSuite::Run, base::Unretained(&test_suite)));
  46. }