summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorcsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2010-03-23 20:39:55 +0000
committercsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2010-03-23 20:39:55 +0000
commit92beff88437b31f4a618640b88487e0f8dfb7017 (patch)
treed15e670fdc74a690d012c25e16a2d6efa4ab7d26 /src/tests
parent23dd124970bc11636feaa240394063ba5889ca54 (diff)
downloadgperftools-92beff88437b31f4a618640b88487e0f8dfb7017.tar.gz
* Add new (std::nothrow) to debugallocation (corrado)
* Add a flag to ingore unaligned-ptr leaks (archanakannan) * PORTING: Add get-pc capabilities for a new OS (csilvers) * Don't register malloc extension under valgrind (csilvers) * Fix throw specs for our global operator new (chandlerc) * PORTING: link to instructions on windows static overrides (mbelshe) * Fix prototype differences in debugalloc (chandlerc, csilvers, wan) * Change pprof to handle big-endian input files (csilvers) * Properly align allocation sizes on Windows (antonm) * Improve IsRunningOnValgrind, using valgrind.h (csilvers, kcc) * Improve the accuracy of system_alloc actual_size (csilvers) * Add interactive callgrind support to pprof (weidenri...) * Fix off-by-one problems when symbolizing in pprof (dpeng) * Be more permissive in allowed library names, in pprof (csilvers) * PORTING: Fix pc_from_ucontext to handle cygwin and redhat7 (csilvers) * Fix stacktrace to avoid inlining (ppluzhnikov) git-svn-id: http://gperftools.googlecode.com/svn/trunk@91 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/debugallocation_test.cc31
-rwxr-xr-xsrc/tests/heap-checker-death_unittest.sh10
-rw-r--r--src/tests/profiler_unittest.cc6
-rwxr-xr-xsrc/tests/profiler_unittest.sh25
-rw-r--r--src/tests/tcmalloc_unittest.cc2
5 files changed, 51 insertions, 23 deletions
diff --git a/src/tests/debugallocation_test.cc b/src/tests/debugallocation_test.cc
index ca00e36..c482187 100644
--- a/src/tests/debugallocation_test.cc
+++ b/src/tests/debugallocation_test.cc
@@ -75,7 +75,14 @@ static int test_counter = 0; // incremented every time the macro is called
// This flag won't be compiled in in opt mode.
DECLARE_int32(max_free_queue_size);
+// Test match as well as mismatch rules:
TEST(DebugAllocationTest, DeallocMismatch) {
+ // malloc can be matched only by free
+ // new can be matched only by delete and delete(nothrow)
+ // new[] can be matched only by delete[] and delete[](nothrow)
+ // new(nothrow) can be matched only by delete and delete(nothrow)
+ // new(nothrow)[] can be matched only by delete[] and delete[](nothrow)
+
// Allocate with malloc.
{
int* x = static_cast<int*>(malloc(sizeof(*x)));
@@ -88,17 +95,41 @@ TEST(DebugAllocationTest, DeallocMismatch) {
// Allocate with new.
{
int* x = new int;
+ int* y = new int;
IF_DEBUG_EXPECT_DEATH(free(x), "mismatch.*being dealloc.*free");
IF_DEBUG_EXPECT_DEATH(delete [] x, "mismatch.*being dealloc.*delete *[[]");
delete x;
+ ::operator delete(y, std::nothrow);
}
// Allocate with new[].
{
int* x = new int[1];
+ int* y = new int[1];
+ IF_DEBUG_EXPECT_DEATH(free(x), "mismatch.*being dealloc.*free");
+ IF_DEBUG_EXPECT_DEATH(delete x, "mismatch.*being dealloc.*delete");
+ delete [] x;
+ ::operator delete[](y, std::nothrow);
+ }
+
+ // Allocate with new(nothrow).
+ {
+ int* x = new(std::nothrow) int;
+ int* y = new(std::nothrow) int;
+ IF_DEBUG_EXPECT_DEATH(free(x), "mismatch.*being dealloc.*free");
+ IF_DEBUG_EXPECT_DEATH(delete [] x, "mismatch.*being dealloc.*delete *[[]");
+ delete x;
+ ::operator delete(y, std::nothrow);
+ }
+
+ // Allocate with new(nothrow)[].
+ {
+ int* x = new(std::nothrow) int[1];
+ int* y = new(std::nothrow) int[1];
IF_DEBUG_EXPECT_DEATH(free(x), "mismatch.*being dealloc.*free");
IF_DEBUG_EXPECT_DEATH(delete x, "mismatch.*being dealloc.*delete");
delete [] x;
+ ::operator delete[](y, std::nothrow);
}
}
diff --git a/src/tests/heap-checker-death_unittest.sh b/src/tests/heap-checker-death_unittest.sh
index 9f0c08c..4a83fc2 100755
--- a/src/tests/heap-checker-death_unittest.sh
+++ b/src/tests/heap-checker-death_unittest.sh
@@ -139,13 +139,13 @@ EARLY_MSG="Starting tracking the heap$"
Test 60 0 "$EARLY_MSG" "" \
HEAPCHECK="" HEAP_CHECKER_TEST_TEST_LEAK=1 HEAP_CHECKER_TEST_NO_THREADS=1 \
- PERFTOOLS_VERBOSE=1 || exit 5
+ PERFTOOLS_VERBOSE=10 || exit 5
Test 60 0 "MemoryRegionMap Init$" "" \
HEAPCHECK="" HEAP_CHECKER_TEST_TEST_LEAK=1 HEAP_CHECKER_TEST_NO_THREADS=1 \
- PERFTOOLS_VERBOSE=2 || exit 6
+ PERFTOOLS_VERBOSE=11 || exit 6
Test 60 0 "" "$EARLY_MSG" \
HEAPCHECK="" HEAP_CHECKER_TEST_TEST_LEAK=1 HEAP_CHECKER_TEST_NO_THREADS=1 \
- PERFTOOLS_VERBOSE=-2 || exit 7
+ PERFTOOLS_VERBOSE=-11 || exit 7
# These invocations should fail with very high probability,
# rather than return 0 or hang (1 == exit(1), 134 == abort(), 139 = SIGSEGV):
@@ -162,10 +162,10 @@ Test 60 1 "MakeALeak" "" \
# Test that very early log messages are present and controllable:
Test 60 1 "Starting tracking the heap$" "" \
- HEAP_CHECKER_TEST_TEST_LEAK=1 HEAP_CHECKER_TEST_NO_THREADS=1 PERFTOOLS_VERBOSE=1 \
+ HEAP_CHECKER_TEST_TEST_LEAK=1 HEAP_CHECKER_TEST_NO_THREADS=1 PERFTOOLS_VERBOSE=10 \
|| exit 11
Test 60 1 "" "Starting tracking the heap" \
- HEAP_CHECKER_TEST_TEST_LEAK=1 HEAP_CHECKER_TEST_NO_THREADS=1 PERFTOOLS_VERBOSE=-1 \
+ HEAP_CHECKER_TEST_TEST_LEAK=1 HEAP_CHECKER_TEST_NO_THREADS=1 PERFTOOLS_VERBOSE=-10 \
|| exit 12
cd / # so we're not in TMPDIR when we delete it
diff --git a/src/tests/profiler_unittest.cc b/src/tests/profiler_unittest.cc
index 1908b03..19371b7 100644
--- a/src/tests/profiler_unittest.cc
+++ b/src/tests/profiler_unittest.cc
@@ -56,12 +56,11 @@ static void test_other_thread() {
int i, m;
char b[128];
+ MutexLock ml(&mutex);
for (m = 0; m < 1000000; ++m) { // run millions of times
for (i = 0; i < g_iters; ++i ) {
- MutexLock ml(&mutex);
result ^= i;
}
- MutexLock ml(&mutex);
snprintf(b, sizeof(b), "%d", result); // get some libc action
}
#endif
@@ -70,12 +69,11 @@ static void test_other_thread() {
static void test_main_thread() {
int i, m;
char b[128];
+ MutexLock ml(&mutex);
for (m = 0; m < 1000000; ++m) { // run millions of times
for (i = 0; i < g_iters; ++i ) {
- MutexLock ml(&mutex);
result ^= i;
}
- MutexLock ml(&mutex);
snprintf(b, sizeof(b), "%d", result); // get some libc action
}
}
diff --git a/src/tests/profiler_unittest.sh b/src/tests/profiler_unittest.sh
index 5766f2e..4668fa7 100755
--- a/src/tests/profiler_unittest.sh
+++ b/src/tests/profiler_unittest.sh
@@ -206,28 +206,27 @@ CPUPROFILE="$TMPDIR/p5" "$PROFILER2" 50 || RegisterFailure
CPUPROFILE="$TMPDIR/p6" "$PROFILER2" 100 || RegisterFailure
VerifySimilar p5 "$PROFILER2_REALNAME" p6 "$PROFILER2_REALNAME" 2
-# When we compile with threads, things take a lot longer even when we only use 1
-CPUPROFILE="$TMPDIR/p5b" "$PROFILER3" 10 || RegisterFailure
-CPUPROFILE="$TMPDIR/p5c" "$PROFILER3" 20 || RegisterFailure
+CPUPROFILE="$TMPDIR/p5b" "$PROFILER3" 30 || RegisterFailure
+CPUPROFILE="$TMPDIR/p5c" "$PROFILER3" 60 || RegisterFailure
VerifySimilar p5b "$PROFILER3_REALNAME" p5c "$PROFILER3_REALNAME" 2
# Now try what happens when we use threads
-"$PROFILER3" 5 2 "$TMPDIR/p7" || RegisterFailure
-"$PROFILER3" 10 2 "$TMPDIR/p8" || RegisterFailure
+"$PROFILER3" 30 2 "$TMPDIR/p7" || RegisterFailure
+"$PROFILER3" 60 2 "$TMPDIR/p8" || RegisterFailure
VerifySimilar p7 "$PROFILER3_REALNAME" p8 "$PROFILER3_REALNAME" 2
-"$PROFILER4" 5 2 "$TMPDIR/p9" || RegisterFailure
-"$PROFILER4" 10 2 "$TMPDIR/p10" || RegisterFailure
+"$PROFILER4" 30 2 "$TMPDIR/p9" || RegisterFailure
+"$PROFILER4" 60 2 "$TMPDIR/p10" || RegisterFailure
VerifySimilar p9 "$PROFILER4_REALNAME" p10 "$PROFILER4_REALNAME" 2
# More threads!
-"$PROFILER4" 2 3 "$TMPDIR/p9" || RegisterFailure
-"$PROFILER4" 4 3 "$TMPDIR/p10" || RegisterFailure
+"$PROFILER4" 25 3 "$TMPDIR/p9" || RegisterFailure
+"$PROFILER4" 50 3 "$TMPDIR/p10" || RegisterFailure
VerifySimilar p9 "$PROFILER4_REALNAME" p10 "$PROFILER4_REALNAME" 2
# Compare how much time the main thread takes compared to the other threads
# Recall the main thread runs twice as long as the other threads, by design.
-"$PROFILER4" 2 4 "$TMPDIR/p11" || RegisterFailure
+"$PROFILER4" 20 4 "$TMPDIR/p11" || RegisterFailure
VerifyAcrossThreads p11 "$PROFILER4_REALNAME" 2
# Test symbol save and restore
@@ -236,14 +235,14 @@ VerifyAcrossThreads p11 "$PROFILER4_REALNAME" 2
>"$TMPDIR/p13" 2>/dev/null || RegisterFailure
VerifyIdentical p12 "$PROFILER1_REALNAME" p13 "" || RegisterFailure
-"$PROFILER3" 5 2 "$TMPDIR/p14" || RegisterFailure
+"$PROFILER3" 30 2 "$TMPDIR/p14" || RegisterFailure
"$PPROF" $PPROF_FLAGS "$PROFILER3_REALNAME" "$TMPDIR/p14" --raw \
>"$TMPDIR/p15" 2>/dev/null || RegisterFailure
VerifyIdentical p14 "$PROFILER3_REALNAME" p15 "" || RegisterFailure
# Test using ITIMER_REAL instead of ITIMER_PROF.
-env CPUPROFILE_REALTIME=1 "$PROFILER3" 5 2 "$TMPDIR/p16" || RegisterFailure
-env CPUPROFILE_REALTIME=1 "$PROFILER3" 10 2 "$TMPDIR/p17" || RegisterFailure
+env CPUPROFILE_REALTIME=1 "$PROFILER3" 30 2 "$TMPDIR/p16" || RegisterFailure
+env CPUPROFILE_REALTIME=1 "$PROFILER3" 60 2 "$TMPDIR/p17" || RegisterFailure
VerifySimilar p16 "$PROFILER3_REALNAME" p17 "$PROFILER3_REALNAME" 2
diff --git a/src/tests/tcmalloc_unittest.cc b/src/tests/tcmalloc_unittest.cc
index 25bfd6a..6b2ec26 100644
--- a/src/tests/tcmalloc_unittest.cc
+++ b/src/tests/tcmalloc_unittest.cc
@@ -977,7 +977,7 @@ static int RunAllTests(int argc, char** argv) {
}
// This code stresses some of the memory allocation via STL.
- // In particular, it calls operator delete(void*, nothrow_t).
+ // It may call operator delete(void*, nothrow_t).
fprintf(LOGSTREAM, "Testing STL use\n");
{
std::vector<int> v;