1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Test launcher that runs all the tests in a test suite with a large timeout.
16 : //
17 : // By default the unittests run with a timeout of 45 seconds, it's not enough
18 : // for some more intensive tests (like the integration tests). This code is
19 : // pretty much a copy-paste of base/test/run_all_unittests.cc, it just add an
20 : // argument line to the process command line to increase the timeout of the
21 : // unittests.
22 :
23 : #include "base/bind.h"
24 : #include "base/command_line.h"
25 : #include "base/test/test_suite.h"
26 : #include "base/test/test_switches.h"
27 : #include "base/test/launcher/unit_test_launcher.h"
28 : #include "syzygy/testing/laa.h"
29 :
30 : namespace {
31 :
32 E : void AddOrSuffixGTestFilter(const char* filter) {
33 : static const char kGTestFilter[] = "gtest_filter";
34 E : base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
35 E : std::string s = command_line->GetSwitchValueASCII(kGTestFilter);
36 E : if (s.empty()) {
37 E : s = filter;
38 E : } else {
39 i : s.append(":");
40 i : s.append(filter);
41 : }
42 :
43 : // Only the last switch matters, so simply add another.
44 E : command_line->AppendSwitchASCII(kGTestFilter, s);
45 E : }
46 :
47 : } // namespace
48 :
49 E : int main(int argc, char** argv) {
50 E : base::TestSuite test_suite(argc, argv);
51 :
52 : // We can't use the value from test_timeouts.h as they require
53 : // TestTimeouts::Initialize to have been called; this function can only be
54 : // called once, however, and gtest calls it later on.
55 :
56 : #ifdef SYZYGY_UNITTESTS_USE_LONG_TIMEOUT
57 : // Set the timeout value to five minutes.
58 E : std::string test_timeout_val = "300000";
59 : base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
60 E : switches::kTestLauncherTimeout, test_timeout_val);
61 : #endif
62 :
63 : // No retry on failures.
64 : base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
65 E : switches::kTestLauncherRetryLimit, "0");
66 :
67 : #ifdef SYZYGY_UNITTESTS_CHECK_MEMORY_MODEL
68 : // Depending on the memory model, eliminate tests that can't run in that
69 : // memory model.
70 E : if (testing::GetAddressSpaceSize() == 2) {
71 i : AddOrSuffixGTestFilter("-*_4G");
72 i : } else {
73 E : CHECK_EQ(4u, testing::GetAddressSpaceSize());
74 E : AddOrSuffixGTestFilter("-*_2G");
75 : }
76 : #endif
77 :
78 : // We don't need to update |argc| and |argv|, gtest read the value from
79 : // base::CommandLine::ForCurrentProcess().
80 : return base::LaunchUnitTests(
81 : argc, argv,
82 E : base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
83 E : }
|