Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: base/process/memory_unittest.cc

Issue 2130293003: Change OOMs to raise custom exception rather than breakpoint on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/memory.h ('k') | base/process/memory_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/memory_unittest.cc
diff --git a/base/process/memory_unittest.cc b/base/process/memory_unittest.cc
index d070b5484301fb7b3a47da04023de23e2a31b5de..52777165a374d4cb1162ed4ef3a1e125c07fe2fa 100644
--- a/base/process/memory_unittest.cc
+++ b/base/process/memory_unittest.cc
@@ -92,7 +92,15 @@ TEST(MemoryTest, AllocatorShimWorking) {
!defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
namespace {
-const char *kOomRegex = "Out of memory";
+#if defined(OS_WIN)
+// Windows raises an exception rather than using LOG(FATAL) in order to make the
+// exit code unique to OOM.
+const char* kOomRegex = "";
+const int kExitCode = base::win::kOomExceptionCode;
+#else
+const char* kOomRegex = "Out of memory";
+const int kExitCode = 1;
+#endif
} // namespace
class OutOfMemoryTest : public testing::Test {
@@ -128,54 +136,54 @@ class OutOfMemoryDeathTest : public OutOfMemoryTest {
};
TEST_F(OutOfMemoryDeathTest, New) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = operator new(test_size_);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, NewArray) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = new char[test_size_];
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, Malloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = malloc(test_size_);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, Realloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = realloc(NULL, test_size_);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, Calloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = calloc(1024, test_size_ / 1024L);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, AlignedAlloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = base::AlignedAlloc(test_size_, 8);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
// POSIX does not define an aligned realloc function.
#if defined(OS_WIN)
TEST_F(OutOfMemoryDeathTest, AlignedRealloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = _aligned_realloc(NULL, test_size_, 8);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
#endif // defined(OS_WIN)
@@ -183,54 +191,54 @@ TEST_F(OutOfMemoryDeathTest, AlignedRealloc) {
// See https://crbug.com/169327.
#if !defined(OS_MACOSX)
TEST_F(OutOfMemoryDeathTest, SecurityNew) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = operator new(insecure_test_size_);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, SecurityNewArray) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = new char[insecure_test_size_];
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, SecurityMalloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = malloc(insecure_test_size_);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, SecurityRealloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = realloc(NULL, insecure_test_size_);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, SecurityCalloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = calloc(1024, insecure_test_size_ / 1024L);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
TEST_F(OutOfMemoryDeathTest, SecurityAlignedAlloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = base::AlignedAlloc(insecure_test_size_, 8);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
// POSIX does not define an aligned realloc function.
#if defined(OS_WIN)
TEST_F(OutOfMemoryDeathTest, SecurityAlignedRealloc) {
- ASSERT_DEATH({
+ ASSERT_EXIT({
SetUpInDeathAssert();
value_ = _aligned_realloc(NULL, insecure_test_size_, 8);
- }, kOomRegex);
+ }, testing::ExitedWithCode(kExitCode), kOomRegex);
}
#endif // defined(OS_WIN)
#endif // !defined(OS_MACOSX)
« no previous file with comments | « base/process/memory.h ('k') | base/process/memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698