Verify that the OOM new handler causes an unhandled exception.
Bug: 749159
Change-Id: Ia677c3f22a22e4cfb1e30c8c3bcdef8c7203fa10
Reviewed-on: https://chromium-review.googlesource.com/587371
Commit-Queue: Sigurður Ásgeirsson <[email protected]>
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: Mark Mentovai <[email protected]>
Cr-Commit-Position: refs/heads/master@{#489945}
diff --git a/base/process/memory_unittest.cc b/base/process/memory_unittest.cc
index 03704c4..64ee0aaa6a 100644
--- a/base/process/memory_unittest.cc
+++ b/base/process/memory_unittest.cc
@@ -211,6 +211,29 @@
value_ = _aligned_realloc(NULL, test_size_, 8);
}, testing::ExitedWithCode(kExitCode), kOomRegex);
}
+
+namespace {
+
+constexpr uint32_t kUnhandledExceptionExitCode = 0xBADA55;
+
+// This unhandled exception filter exits the process with an exit code distinct
+// from the exception code. This is to verify that the out of memory new handler
+// causes an unhandled exception.
+LONG WINAPI ExitingUnhandledExceptionFilter(EXCEPTION_POINTERS* ExceptionInfo) {
+ _exit(kUnhandledExceptionExitCode);
+}
+
+} // namespace
+
+TEST_F(OutOfMemoryDeathTest, NewHandlerGeneratesUnhandledException) {
+ ASSERT_EXIT(
+ {
+ SetUpInDeathAssert();
+ SetUnhandledExceptionFilter(&ExitingUnhandledExceptionFilter);
+ value_ = new char[test_size_];
+ },
+ testing::ExitedWithCode(kUnhandledExceptionExitCode), kOomRegex);
+}
#endif // defined(OS_WIN)
// OS X and Android have no 2Gb allocation limit.