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

Side by Side Diff: base/process_util_unittest.cc

Issue 391044: For Linux, override malloc and friends so that we can detect and then stop on... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Readability & style. Fix new unittest on 32bit Linux Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/process_util_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/eintr_wrapper.h" 10 #include "base/eintr_wrapper.h"
9 #include "base/file_path.h" 11 #include "base/file_path.h"
10 #include "base/multiprocess_test.h" 12 #include "base/multiprocess_test.h"
11 #include "base/path_service.h" 13 #include "base/path_service.h"
12 #include "base/platform_thread.h" 14 #include "base/platform_thread.h"
13 #include "base/process_util.h" 15 #include "base/process_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 #if defined(OS_LINUX) 18 #if defined(OS_LINUX)
17 #include <dlfcn.h> 19 #include <dlfcn.h>
20 #include <malloc.h>
18 #endif 21 #endif
19 #if defined(OS_POSIX) 22 #if defined(OS_POSIX)
20 #include <fcntl.h> 23 #include <fcntl.h>
21 #include <sys/socket.h> 24 #include <sys/socket.h>
22 #endif 25 #endif
23 #if defined(OS_WIN) 26 #if defined(OS_WIN)
24 #include <windows.h> 27 #include <windows.h>
25 #endif 28 #endif
26 29
27 namespace base { 30 namespace base {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 "0 0 0 0 " // <- No CPU, apparently. 357 "0 0 0 0 " // <- No CPU, apparently.
355 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " 358 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 "
356 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; 359 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0";
357 360
358 EXPECT_EQ(0, ParseProcStatCPU(kSelfStat)); 361 EXPECT_EQ(0, ParseProcStatCPU(kSelfStat));
359 } 362 }
360 #endif 363 #endif
361 364
362 #endif // defined(OS_POSIX) 365 #endif // defined(OS_POSIX)
363 366
367 #if defined(OS_LINUX)
368 // TODO(vandebo) make this work on Windows and Mac too.
369
370 class OutOfMemoryTest : public testing::Test {
371 public:
372 OutOfMemoryTest()
373 : value_(NULL),
374 // Make test size as large as possible minus a few pages so
375 // that alignment or other rounding doesn't make it wrap.
376 test_size_(std::numeric_limits<std::size_t>::max() - 8192) {
377 }
378
379 virtual void SetUp() {
380 // Must call EnableTerminationOnOutOfMemory() because that is called from
381 // chrome's main function and therefore hasn't been called yet.
382 EnableTerminationOnOutOfMemory();
383 }
384
385 void* value_;
386 size_t test_size_;
387 };
388
389 TEST_F(OutOfMemoryTest, New) {
390 ASSERT_DEATH(value_ = new char[test_size_], "");
391 }
392
393 TEST_F(OutOfMemoryTest, Malloc) {
394 ASSERT_DEATH(value_ = malloc(test_size_), "");
395 }
396
397 TEST_F(OutOfMemoryTest, Realloc) {
398 ASSERT_DEATH(value_ = realloc(NULL, test_size_), "");
399 }
400
401 TEST_F(OutOfMemoryTest, Calloc) {
402 ASSERT_DEATH(value_ = calloc(1024, test_size_ / 1024L), "");
403 }
404
405 TEST_F(OutOfMemoryTest, Valloc) {
406 ASSERT_DEATH(value_ = valloc(test_size_), "");
407 }
408
409 TEST_F(OutOfMemoryTest, Pvalloc) {
410 ASSERT_DEATH(value_ = pvalloc(test_size_), "");
411 }
412
413 TEST_F(OutOfMemoryTest, Memalign) {
414 ASSERT_DEATH(value_ = memalign(4, test_size_), "");
415 }
416
417 TEST_F(OutOfMemoryTest, Posix_memalign) {
418 ASSERT_DEATH(posix_memalign(&value_, 8, test_size_), "");
419 }
420
421 extern "C" {
422
423 void* __libc_malloc(size_t size);
424 void* __libc_realloc(void* ptr, size_t size);
425 void* __libc_calloc(size_t nmemb, size_t size);
426 void* __libc_valloc(size_t size);
427 void* __libc_pvalloc(size_t size);
428 void* __libc_memalign(size_t alignment, size_t size);
429
430 } // extern "C"
431
432 TEST_F(OutOfMemoryTest, __libc_malloc) {
433 ASSERT_DEATH(value_ = __libc_malloc(test_size_), "");
434 }
435
436 TEST_F(OutOfMemoryTest, __libc_realloc) {
437 ASSERT_DEATH(value_ = __libc_realloc(NULL, test_size_), "");
438 }
439
440 TEST_F(OutOfMemoryTest, __libc_calloc) {
441 ASSERT_DEATH(value_ = __libc_calloc(1024, test_size_ / 1024L), "");
442 }
443
444 TEST_F(OutOfMemoryTest, __libc_valloc) {
445 ASSERT_DEATH(value_ = __libc_valloc(test_size_), "");
446 }
447
448 TEST_F(OutOfMemoryTest, __libc_pvalloc) {
449 ASSERT_DEATH(value_ = __libc_pvalloc(test_size_), "");
450 }
451
452 TEST_F(OutOfMemoryTest, __libc_memalign) {
453 ASSERT_DEATH(value_ = __libc_memalign(4, test_size_), "");
454 }
455
456 #endif // defined(OS_LINUX)
457
364 } // namespace base 458 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698