OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "base/test/multiprocess_test.h" | 16 #include "base/test/multiprocess_test.h" |
17 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 18 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
19 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "testing/multiprocess_func_list.h" | 22 #include "testing/multiprocess_func_list.h" |
23 | 23 |
24 #if defined(OS_LINUX) | 24 #if defined(OS_LINUX) |
25 #include <errno.h> | |
26 #include <malloc.h> | 25 #include <malloc.h> |
27 #include <glib.h> | 26 #include <glib.h> |
28 #include <sched.h> | 27 #include <sched.h> |
29 #endif | 28 #endif |
30 #if defined(OS_POSIX) | 29 #if defined(OS_POSIX) |
30 #include <errno.h> | |
31 #include <dlfcn.h> | 31 #include <dlfcn.h> |
32 #include <fcntl.h> | 32 #include <fcntl.h> |
33 #include <signal.h> | 33 #include <signal.h> |
34 #include <sys/resource.h> | 34 #include <sys/resource.h> |
35 #include <sys/socket.h> | 35 #include <sys/socket.h> |
36 #include <sys/wait.h> | 36 #include <sys/wait.h> |
37 #endif | 37 #endif |
38 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
39 #include <windows.h> | 39 #include <windows.h> |
40 #endif | 40 #endif |
41 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
42 #include <cmath> | |
42 #include <malloc/malloc.h> | 43 #include <malloc/malloc.h> |
43 #include "base/process_util_unittest_mac.h" | 44 #include "base/process_util_unittest_mac.h" |
44 #endif | 45 #endif |
45 | 46 |
46 namespace { | 47 namespace { |
47 | 48 |
48 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
49 const wchar_t kProcessName[] = L"base_unittests.exe"; | 50 const wchar_t kProcessName[] = L"base_unittests.exe"; |
50 #else | 51 #else |
51 const wchar_t kProcessName[] = L"base_unittests"; | 52 const wchar_t kProcessName[] = L"base_unittests"; |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 | 448 |
448 #endif // defined(OS_WIN) | 449 #endif // defined(OS_WIN) |
449 | 450 |
450 #if defined(OS_MACOSX) | 451 #if defined(OS_MACOSX) |
451 | 452 |
452 TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) { | 453 TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) { |
453 // Note that base::EnableTerminationOnHeapCorruption() is called as part of | 454 // Note that base::EnableTerminationOnHeapCorruption() is called as part of |
454 // test suite setup and does not need to be done again, else mach_override | 455 // test suite setup and does not need to be done again, else mach_override |
455 // will fail. | 456 // will fail. |
456 | 457 |
457 char buf[3]; | 458 // Test that ENOMEM doesn't crash. "I just want to allocate 1 petabyte." |
458 ASSERT_DEATH(free(buf), "being freed.*" | 459 void* buf = malloc(pow(10, 15)); |
Scott Hess - ex-Googler
2012/03/05 20:34:20
This isn't really 32-bit safe, is it? It just hap
Robert Sesek
2012/03/06 01:16:27
Done in a C++ way.
| |
460 EXPECT_FALSE(buf); | |
461 EXPECT_EQ(ENOMEM, errno) << "Expected no memory error"; | |
Scott Hess - ex-Googler
2012/03/05 20:34:20
Is the death-test below considered proof enough th
Robert Sesek
2012/03/06 01:16:27
Yes.
| |
462 | |
463 char stack_buf[3]; | |
464 ASSERT_DEATH(free(stack_buf), "being freed.*" | |
459 "\\*\\*\\* set a breakpoint in malloc_error_break to debug.*" | 465 "\\*\\*\\* set a breakpoint in malloc_error_break to debug.*" |
460 "Terminating process due to a potential for future heap corruption"); | 466 "Terminating process due to a potential for future heap corruption"); |
461 } | 467 } |
462 | 468 |
463 #endif // defined(OS_MACOSX) | 469 #endif // defined(OS_MACOSX) |
464 | 470 |
465 #if defined(OS_POSIX) | 471 #if defined(OS_POSIX) |
466 | 472 |
467 namespace { | 473 namespace { |
468 | 474 |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1150 SetUpInDeathAssert(); | 1156 SetUpInDeathAssert(); |
1151 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 1157 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
1152 }, ""); | 1158 }, ""); |
1153 } | 1159 } |
1154 | 1160 |
1155 #endif // !ARCH_CPU_64_BITS | 1161 #endif // !ARCH_CPU_64_BITS |
1156 #endif // OS_MACOSX | 1162 #endif // OS_MACOSX |
1157 | 1163 |
1158 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && | 1164 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
1159 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) | 1165 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
OLD | NEW |