-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path903e7eb582c9d33cda07069fee6eb569c152de63.diff
161 lines (139 loc) · 5.95 KB
/
903e7eb582c9d33cda07069fee6eb569c152de63.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
diff --git a/base/debug/invalid_access_win.cc b/base/debug/invalid_access_win.cc
index dc0d54bbc67ec..246e8e4775a43 100644
--- a/base/debug/invalid_access_win.cc
+++ b/base/debug/invalid_access_win.cc
@@ -9,4 +9,5 @@
#include "base/notreached.h"
+#include "base/win/windows_version.h"
#include "build/build_config.h"
namespace base {
@@ -41,10 +42,21 @@ void IndirectCall(FuncType* func) {
(*func)();
}
+void CreateSyntheticHeapCorruption() {
+ EXCEPTION_RECORD record = {};
+ record.ExceptionCode = STATUS_HEAP_CORRUPTION;
+ RaiseFailFastException(&record, nullptr,
+ FAIL_FAST_GENERATE_EXCEPTION_ADDRESS);
+}
+
} // namespace
void TerminateWithHeapCorruption() {
__try {
+ // Pre-Windows 10, it's hard to trigger a heap corruption fast fail, so
+ // artificially create one instead.
+ if (base::win::GetVersion() < base::win::Version::WIN10)
+ CreateSyntheticHeapCorruption();
HANDLE heap = ::HeapCreate(0, 0, 0);
CHECK(heap);
CHECK(HeapSetInformation(heap, HeapEnableTerminationOnCorruption, nullptr,
diff --git a/base/test/launcher/test_launcher.cc b/base/test/launcher/test_launcher.cc
index 6ea8e086aa67a..26b4b53c1fa49 100644
--- a/base/test/launcher/test_launcher.cc
+++ b/base/test/launcher/test_launcher.cc
@@ -80,6 +80,7 @@
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "base/strings/string_util_win.h"
+#include "base/win/windows_version.h"
@@ -103,8 +104,7 @@
namespace base {
-// See
-// https://groups.google.com/a/chromium.org/d/msg/chromium-dev/nkdTP7sstSc/uT3FaE_sgkAJ
+// See https://groups.google.com/a/chromium.org/d/msg/chromium-dev/nkdTP7sstSc/uT3FaE_sgkAJ .
using ::operator<<;
// The environment variable name for the total number of test shards.
@@ -434,6 +434,13 @@ int LaunchChildTestProcessWithOptions(const CommandLine& command_line,
DWORD job_flags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+ // Allow break-away from job since sandbox and few other places rely on it
+ // on Windows versions prior to Windows 8 (which supports nested jobs).
+ if (win::GetVersion() < win::Version::WIN8 &&
+ flags & TestLauncher::ALLOW_BREAKAWAY_FROM_JOB) {
+ job_flags |= JOB_OBJECT_LIMIT_BREAKAWAY_OK;
+ }
+
if (!SetJobObjectLimitFlags(job_handle.get(), job_flags)) {
LOG(ERROR) << "Could not SetJobObjectLimitFlags.";
return -1;
diff --git a/base/test/launcher/test_launcher_unittest.cc b/base/test/launcher/test_launcher_unittest.cc
index 770004956774f..a741e6eec9287 100644
--- a/base/test/launcher/test_launcher_unittest.cc
+++ b/base/test/launcher/test_launcher_unittest.cc
@@ -34,6 +34,10 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
+#if BUILDFLAG(IS_WIN)
+#include "base/win/windows_version.h"
+#endif
+
namespace base {
namespace {
@@ -1215,6 +1219,13 @@ TEST_F(UnitTestLauncherDelegateTester, RunMockTests) {
command_line.AppendSwitchPath("test-launcher-summary-output", path);
command_line.AppendSwitch("gtest_also_run_disabled_tests");
command_line.AppendSwitchASCII("test-launcher-retry-limit", "0");
+#if BUILDFLAG(IS_WIN)
+ // In Windows versions prior to Windows 8, nested job objects are
+ // not allowed and cause this test to fail.
+ if (win::GetVersion() < win::Version::WIN8) {
+ command_line.AppendSwitch(kDontUseJobObjectFlag);
+ }
+#endif // BUILDFLAG(IS_WIN)
std::string output;
GetAppOutputAndError(command_line, &output);
@@ -1384,6 +1395,13 @@ TEST_F(UnitTestLauncherDelegateTester, LeakedChildProcess) {
command_line.AppendSwitchPath("test-launcher-summary-output", path);
command_line.AppendSwitch("gtest_also_run_disabled_tests");
command_line.AppendSwitchASCII("test-launcher-retry-limit", "0");
+#if BUILDFLAG(IS_WIN)
+ // In Windows versions prior to Windows 8, nested job objects are
+ // not allowed and cause this test to fail.
+ if (win::GetVersion() < win::Version::WIN8) {
+ command_line.AppendSwitch(kDontUseJobObjectFlag);
+ }
+#endif // BUILDFLAG(IS_WIN)
std::string output;
int exit_code = 0;
diff --git a/base/test/launcher/unit_test_launcher.cc b/base/test/launcher/unit_test_launcher.cc
index dbea146e9e4f8..a3f1c8b34dfd4 100644
--- a/base/test/launcher/unit_test_launcher.cc
+++ b/base/test/launcher/unit_test_launcher.cc
@@ -129,6 +129,9 @@ void PrintUsage() {
" --test-launcher-shard-index=N\n"
" Sets the shard index to run to N (from 0 to TOTAL - 1).\n"
"\n"
+ " --dont-use-job-objects\n"
+ " Avoids using job objects in Windows.\n"
+ "\n"
" --test-launcher-print-temp-leaks\n"
" Prints information about leaked files and/or directories in\n"
" child process's temporary directories (Windows and macOS).\n");
@@ -210,6 +213,10 @@ int RunTestSuite(RunTestSuiteCallback run_test_suite,
#if BUILDFLAG(IS_POSIX)
FileDescriptorWatcher file_descriptor_watcher(executor.task_runner());
#endif
+ use_job_objects =
+ use_job_objects &&
+ !CommandLine::ForCurrentProcess()->HasSwitch(kDontUseJobObjectFlag);
+
DefaultUnitTestPlatformDelegate platform_delegate;
UnitTestLauncherDelegate delegate(&platform_delegate, batch_limit,
use_job_objects, timeout_callback);
@@ -277,6 +284,9 @@ void InitGoogleTestWChar(int* argc, wchar_t** argv) {
} // namespace
+// Flag to avoid using job objects
+const char kDontUseJobObjectFlag[] = "dont-use-job-objects";
+
MergeTestFilterSwitchHandler::~MergeTestFilterSwitchHandler() = default;
void MergeTestFilterSwitchHandler::ResolveDuplicate(
std::string_view key,
diff --git a/base/test/launcher/unit_test_launcher.h b/base/test/launcher/unit_test_launcher.h
index b8d052cbde21b..ea658a5e4a857 100644
--- a/base/test/launcher/unit_test_launcher.h
+++ b/base/test/launcher/unit_test_launcher.h
@@ -23,6 +23,8 @@
namespace base {
+extern const char kDontUseJobObjectFlag[];
+
// Callback that runs a test suite and returns exit code.
using RunTestSuiteCallback = OnceCallback<int(void)>;