OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/multiprocess_test.h" | 12 #include "base/multiprocess_test.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/platform_thread.h" | 14 #include "base/platform_thread.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 #if defined(OS_LINUX) | 18 #if defined(OS_LINUX) |
19 #include <dlfcn.h> | 19 #include <dlfcn.h> |
20 #include <errno.h> | 20 #include <errno.h> |
21 #include <malloc.h> | 21 #include <malloc.h> |
| 22 #include <glib.h> |
22 #endif | 23 #endif |
23 #if defined(OS_POSIX) | 24 #if defined(OS_POSIX) |
24 #include <fcntl.h> | 25 #include <fcntl.h> |
25 #include <sys/resource.h> | 26 #include <sys/resource.h> |
26 #include <sys/socket.h> | 27 #include <sys/socket.h> |
27 #endif | 28 #endif |
28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
29 #include <windows.h> | 30 #include <windows.h> |
30 #endif | 31 #endif |
31 | 32 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 "0 0 0 0 " // <- No CPU, apparently. | 382 "0 0 0 0 " // <- No CPU, apparently. |
382 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " | 383 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " |
383 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; | 384 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; |
384 | 385 |
385 EXPECT_EQ(0, ParseProcStatCPU(kSelfStat)); | 386 EXPECT_EQ(0, ParseProcStatCPU(kSelfStat)); |
386 } | 387 } |
387 #endif | 388 #endif |
388 | 389 |
389 #endif // defined(OS_POSIX) | 390 #endif // defined(OS_POSIX) |
390 | 391 |
391 #if 0 | |
392 | |
393 // See comments in process_util_linux.cc about why these are removed for now. | |
394 | |
395 // TODO(vandebo) make this work on Windows and Mac too. | 392 // TODO(vandebo) make this work on Windows and Mac too. |
396 #if defined(OS_LINUX) | 393 #if defined(OS_LINUX) |
397 | 394 |
398 #if defined(LINUX_USE_TCMALLOC) | 395 #if defined(LINUX_USE_TCMALLOC) |
399 extern "C" { | 396 extern "C" { |
400 int tc_set_new_mode(int mode); | 397 int tc_set_new_mode(int mode); |
401 } | 398 } |
402 #endif // defined(LINUX_USE_TCMALLOC) | 399 #endif // defined(LINUX_USE_TCMALLOC) |
403 | 400 |
404 class OutOfMemoryTest : public testing::Test { | 401 class OutOfMemoryTest : public testing::Test { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 } | 445 } |
449 | 446 |
450 TEST_F(OutOfMemoryTest, Pvalloc) { | 447 TEST_F(OutOfMemoryTest, Pvalloc) { |
451 ASSERT_DEATH(value_ = pvalloc(test_size_), ""); | 448 ASSERT_DEATH(value_ = pvalloc(test_size_), ""); |
452 } | 449 } |
453 | 450 |
454 TEST_F(OutOfMemoryTest, Memalign) { | 451 TEST_F(OutOfMemoryTest, Memalign) { |
455 ASSERT_DEATH(value_ = memalign(4, test_size_), ""); | 452 ASSERT_DEATH(value_ = memalign(4, test_size_), ""); |
456 } | 453 } |
457 | 454 |
| 455 TEST_F(OutOfMemoryTest, ViaSharedLibraries) { |
| 456 // g_try_malloc is documented to return NULL on failure. (g_malloc is the |
| 457 // 'safe' default that crashes if allocation fails). However, since we have |
| 458 // hopefully overridden malloc, even g_try_malloc should fail. This tests |
| 459 // that the run-time symbol resolution is overriding malloc for shared |
| 460 // libraries as well as for our code. |
| 461 ASSERT_DEATH(value_ = g_try_malloc(test_size_), ""); |
| 462 } |
| 463 |
| 464 |
458 TEST_F(OutOfMemoryTest, Posix_memalign) { | 465 TEST_F(OutOfMemoryTest, Posix_memalign) { |
459 // Grab the return value of posix_memalign to silence a compiler warning | 466 // Grab the return value of posix_memalign to silence a compiler warning |
460 // about unused return values. We don't actually care about the return | 467 // about unused return values. We don't actually care about the return |
461 // value, since we're asserting death. | 468 // value, since we're asserting death. |
462 ASSERT_DEATH(EXPECT_EQ(ENOMEM, posix_memalign(&value_, 8, test_size_)), ""); | 469 ASSERT_DEATH(EXPECT_EQ(ENOMEM, posix_memalign(&value_, 8, test_size_)), ""); |
463 } | 470 } |
464 | 471 |
465 extern "C" { | |
466 | |
467 void* __libc_malloc(size_t size); | |
468 void* __libc_realloc(void* ptr, size_t size); | |
469 void* __libc_calloc(size_t nmemb, size_t size); | |
470 void* __libc_valloc(size_t size); | |
471 void* __libc_pvalloc(size_t size); | |
472 void* __libc_memalign(size_t alignment, size_t size); | |
473 | |
474 } // extern "C" | |
475 | |
476 TEST_F(OutOfMemoryTest, __libc_malloc) { | |
477 ASSERT_DEATH(value_ = __libc_malloc(test_size_), ""); | |
478 } | |
479 | |
480 TEST_F(OutOfMemoryTest, __libc_realloc) { | |
481 ASSERT_DEATH(value_ = __libc_realloc(NULL, test_size_), ""); | |
482 } | |
483 | |
484 TEST_F(OutOfMemoryTest, __libc_calloc) { | |
485 ASSERT_DEATH(value_ = __libc_calloc(1024, test_size_ / 1024L), ""); | |
486 } | |
487 | |
488 TEST_F(OutOfMemoryTest, __libc_valloc) { | |
489 ASSERT_DEATH(value_ = __libc_valloc(test_size_), ""); | |
490 } | |
491 | |
492 TEST_F(OutOfMemoryTest, __libc_pvalloc) { | |
493 ASSERT_DEATH(value_ = __libc_pvalloc(test_size_), ""); | |
494 } | |
495 | |
496 TEST_F(OutOfMemoryTest, __libc_memalign) { | |
497 ASSERT_DEATH(value_ = __libc_memalign(4, test_size_), ""); | |
498 } | |
499 | |
500 #endif // defined(OS_LINUX) | 472 #endif // defined(OS_LINUX) |
501 | 473 |
502 #endif | |
503 | |
504 } // namespace base | 474 } // namespace base |
OLD | NEW |