blob: 7ba6b98ad76811b6ba88275023eeed3488a9534d [file] [log] [blame]
[email protected]dca629c2012-03-22 03:40:381// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d82abb92010-05-04 17:21:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]4d9bdfaf2008-08-26 05:53:574
eromanada220072016-11-23 21:49:315#include "base/build_time.h"
[email protected]567d30e2012-07-13 21:48:296#include "base/metrics/statistics_recorder.h"
[email protected]ee881f402013-10-04 21:51:507#include "base/test/launcher/unit_test_launcher.h"
[email protected]331c2512010-05-04 18:15:568#include "build/build_config.h"
[email protected]4b559b4d2011-04-14 17:37:149#include "crypto/nss_util.h"
[email protected]636b8252011-04-08 19:56:5410#include "net/socket/client_socket_pool_base.h"
[email protected]8efa4ba42013-03-18 21:14:1411#include "net/test/net_test_suite.h"
kapishnikovabe280e2016-04-14 19:07:1612#include "url/url_features.h"
[email protected]636b8252011-04-08 19:56:5413
mmenkee2ad9922017-06-08 20:27:3614#if !defined(OS_IOS)
brettw25ca8922016-03-18 22:59:5815#include "mojo/edk/embedder/embedder.h" // nogncheck
amistry7e6ebfdc82015-02-13 04:19:1116#endif
17
[email protected]636b8252011-04-08 19:56:5418using net::internal::ClientSocketPoolBaseHelper;
[email protected]4d9bdfaf2008-08-26 05:53:5719
eromanada220072016-11-23 21:49:3120namespace {
21
22bool VerifyBuildIsTimely() {
23 // This lines up with various //net security features, like Certificate
24 // Transparency or HPKP, in that they require the build time be less than 70
25 // days old. Moreover, operating on the assumption that tests are run against
26 // recently compiled builds, this also serves as a sanity check for the
27 // system clock, which should be close to the build date.
28 base::TimeDelta kMaxAge = base::TimeDelta::FromDays(70);
29
30 base::Time build_time = base::GetBuildTime();
31 base::Time now = base::Time::Now();
32
33 if ((now - build_time).magnitude() <= kMaxAge)
34 return true;
35
36 std::cerr
37 << "ERROR: This build is more than " << kMaxAge.InDays()
38 << " days out of date.\n"
39 "This could indicate a problem with the device's clock, or the build "
40 "is simply too old.\n"
41 "See crbug.com/666821 for why this is a problem\n"
42 << " base::Time::Now() --> " << now << " (" << now.ToInternalValue()
43 << ")\n"
44 << " base::GetBuildTime() --> " << build_time << " ("
45 << build_time.ToInternalValue() << ")\n";
46
47 return false;
48}
49
50} // namespace
51
[email protected]4d9bdfaf2008-08-26 05:53:5752int main(int argc, char** argv) {
[email protected]26a64592009-12-15 08:04:4053 // Record histograms, so we can get histograms data in tests.
[email protected]fce44c12012-07-19 19:17:3254 base::StatisticsRecorder::Initialize();
[email protected]6e4cc8f2012-06-27 02:21:0255
eromanada220072016-11-23 21:49:3156 if (!VerifyBuildIsTimely())
57 return 1;
58
[email protected]47c196b2009-12-02 20:04:2759 NetTestSuite test_suite(argc, argv);
[email protected]636b8252011-04-08 19:56:5460 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
[email protected]d82abb92010-05-04 17:21:3261
mmenkee2ad9922017-06-08 20:27:3662#if !defined(OS_IOS)
rockotc637caf9b2016-02-10 09:57:0863 mojo::edk::Init();
amistry7e6ebfdc82015-02-13 04:19:1164#endif
65
[email protected]d85fe1e2013-09-05 18:20:3666 return base::LaunchUnitTests(
67 argc, argv, base::Bind(&NetTestSuite::Run,
68 base::Unretained(&test_suite)));
[email protected]4d9bdfaf2008-08-26 05:53:5769}