OLD | NEW |
1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 #include <memory> | 94 #include <memory> |
95 #include <set> | 95 #include <set> |
96 #include <string> | 96 #include <string> |
97 #include <vector> | 97 #include <vector> |
98 | 98 |
99 #include "base/commandlineflags.h" | 99 #include "base/commandlineflags.h" |
100 #include "base/googleinit.h" | 100 #include "base/googleinit.h" |
101 #include "base/logging.h" | 101 #include "base/logging.h" |
102 #include "base/commandlineflags.h" | 102 #include "base/commandlineflags.h" |
103 #include "base/thread_lister.h" | 103 #include "base/thread_lister.h" |
104 #include <gperftools/heap-checker.h> | 104 #include <google/heap-checker.h> |
105 #include "memory_region_map.h" | 105 #include "memory_region_map.h" |
106 #include <gperftools/malloc_extension.h> | 106 #include <google/malloc_extension.h> |
107 #include <gperftools/stacktrace.h> | 107 #include <google/stacktrace.h> |
108 | 108 |
109 // On systems (like freebsd) that don't define MAP_ANONYMOUS, use the old | 109 // On systems (like freebsd) that don't define MAP_ANONYMOUS, use the old |
110 // form of the name instead. | 110 // form of the name instead. |
111 #ifndef MAP_ANONYMOUS | 111 #ifndef MAP_ANONYMOUS |
112 # define MAP_ANONYMOUS MAP_ANON | 112 # define MAP_ANONYMOUS MAP_ANON |
113 #endif | 113 #endif |
114 | 114 |
115 using namespace std; | 115 using namespace std; |
116 | 116 |
117 // ========================================================================= // | 117 // ========================================================================= // |
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 | 1374 |
1375 LOGF << "In main(): heap_check=" << FLAGS_heap_check << endl; | 1375 LOGF << "In main(): heap_check=" << FLAGS_heap_check << endl; |
1376 | 1376 |
1377 CHECK(HeapLeakChecker::NoGlobalLeaks()); // so far, so good | 1377 CHECK(HeapLeakChecker::NoGlobalLeaks()); // so far, so good |
1378 | 1378 |
1379 if (FLAGS_test_leak) { | 1379 if (FLAGS_test_leak) { |
1380 void* arr; | 1380 void* arr; |
1381 RunHidden(NewCallback(MakeALeak, &arr)); | 1381 RunHidden(NewCallback(MakeALeak, &arr)); |
1382 Use(&arr); | 1382 Use(&arr); |
1383 LogHidden("Leaking", arr); | 1383 LogHidden("Leaking", arr); |
1384 if (FLAGS_test_cancel_global_check) { | 1384 if (FLAGS_test_cancel_global_check) HeapLeakChecker::CancelGlobalCheck(); |
1385 HeapLeakChecker::CancelGlobalCheck(); | |
1386 } else { | |
1387 // Verify we can call NoGlobalLeaks repeatedly without deadlocking | |
1388 HeapLeakChecker::NoGlobalLeaks(); | |
1389 HeapLeakChecker::NoGlobalLeaks(); | |
1390 } | |
1391 return Pass(); | 1385 return Pass(); |
1392 // whole-program leak-check should (with very high probability) | 1386 // whole-program leak-check should (with very high probability) |
1393 // catch the leak of arr (10 * sizeof(int) bytes) | 1387 // catch the leak of arr (10 * sizeof(int) bytes) |
1394 // (when !FLAGS_test_cancel_global_check) | 1388 // (when !FLAGS_test_cancel_global_check) |
1395 } | 1389 } |
1396 | 1390 |
1397 if (FLAGS_test_loop_leak) { | 1391 if (FLAGS_test_loop_leak) { |
1398 void* arr1; | 1392 void* arr1; |
1399 void* arr2; | 1393 void* arr2; |
1400 RunHidden(NewCallback(MakeDeathLoop, &arr1, &arr2)); | 1394 RunHidden(NewCallback(MakeDeathLoop, &arr1, &arr2)); |
1401 Use(&arr1); | 1395 Use(&arr1); |
1402 Use(&arr2); | 1396 Use(&arr2); |
1403 LogHidden("Loop leaking", arr1); | 1397 LogHidden("Loop leaking", arr1); |
1404 LogHidden("Loop leaking", arr2); | 1398 LogHidden("Loop leaking", arr2); |
1405 if (FLAGS_test_cancel_global_check) { | 1399 if (FLAGS_test_cancel_global_check) HeapLeakChecker::CancelGlobalCheck(); |
1406 HeapLeakChecker::CancelGlobalCheck(); | |
1407 } else { | |
1408 // Verify we can call NoGlobalLeaks repeatedly without deadlocking | |
1409 HeapLeakChecker::NoGlobalLeaks(); | |
1410 HeapLeakChecker::NoGlobalLeaks(); | |
1411 } | |
1412 return Pass(); | 1400 return Pass(); |
1413 // whole-program leak-check should (with very high probability) | 1401 // whole-program leak-check should (with very high probability) |
1414 // catch the leak of arr1 and arr2 (4 * sizeof(void*) bytes) | 1402 // catch the leak of arr1 and arr2 (4 * sizeof(void*) bytes) |
1415 // (when !FLAGS_test_cancel_global_check) | 1403 // (when !FLAGS_test_cancel_global_check) |
1416 } | 1404 } |
1417 | 1405 |
1418 if (FLAGS_test_register_leak) { | 1406 if (FLAGS_test_register_leak) { |
1419 // make us fail only where the .sh test expects: | 1407 // make us fail only where the .sh test expects: |
1420 Pause(); | 1408 Pause(); |
1421 for (int i = 0; i < 100; ++i) { // give it some time to crash | 1409 for (int i = 0; i < 100; ++i) { // give it some time to crash |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 CHECK(heap_check.SameHeap()); | 1482 CHECK(heap_check.SameHeap()); |
1495 } else { | 1483 } else { |
1496 WARN_IF(heap_check.SameHeap() != true, | 1484 WARN_IF(heap_check.SameHeap() != true, |
1497 "overall leaks are caught; we must be using a stripped binary"); | 1485 "overall leaks are caught; we must be using a stripped binary"); |
1498 } | 1486 } |
1499 | 1487 |
1500 CHECK(HeapLeakChecker::NoGlobalLeaks()); // so far, so good | 1488 CHECK(HeapLeakChecker::NoGlobalLeaks()); // so far, so good |
1501 | 1489 |
1502 return Pass(); | 1490 return Pass(); |
1503 } | 1491 } |
OLD | NEW |