summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorcsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2010-11-18 01:07:25 +0000
committercsilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2010-11-18 01:07:25 +0000
commit3014cf142e5a2409c88ab4559f3274434ed9a29b (patch)
tree13c2dc85e8800116c4c7d3ef5f27ea0edc37d20f /src/tests
parent682ff7da1205398376ee725b4ce3219c107b3f8a (diff)
downloadgperftools-3014cf142e5a2409c88ab4559f3274434ed9a29b.tar.gz
* Suppress all large allocs when report threshold==0
* Clarified meaning of various malloc stats * Change from ATTRIBUTED_DEPRECATED to comments * Make array-size a var to compile under clang * Reduce page map key size under x86_64 by 4.4MB * Added full qualification to MemoryBarrier * Support systems that capitalize /proc weirdly * Avoid gcc warning: exporting type in unnamed ns * Add some dynamic annotations for gcc attributes * Add support for census profiler in pprof * Speed up pprof's ExtractSymbols * Speed up GoogleOnce * Add pkg-config (.pc) files * Detect when __environ exists but is NULL * Improve spinlock contention performance * Add GetFreeListSizes * Improve sampling_test, eg by adding no-inline * Relax malloc_extension test-check for big pages * Add proper library version number information * Update from autoconf 2.64 to 2.65 * Better document how to write a server that works with pprof * Change FillProcSelfMaps to better handle out-of-space * No longer hook _aligned_malloc/free in windows * Handle function-forwarding in DLLs when patching (in windows) * Update .vcproj files that had wrong .cc files in them (!) * get rid of unnecessary 'size < 0' * fix comments a bit in sysinfo.cc * another go at improving malloc-stats output * fix comment typo in profiler.cc * Add a few more thread annotations * Try to read TSC frequency from 'tsc_freq_khz' * Fix annotalysis/TSAN incompatibility * Add pprof --evince to go along with --gv * Document need for sampling to use GetHeapSample * Fix flakiness in malloc_extension_test * Separate out synchronization profiling routines git-svn-id: http://gperftools.googlecode.com/svn/trunk@99 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/debugallocation_test.cc10
-rw-r--r--src/tests/malloc_extension_test.cc26
-rw-r--r--src/tests/sampling_test.cc2
-rwxr-xr-xsrc/tests/sampling_test.sh4
-rw-r--r--src/tests/system-alloc_unittest.cc14
-rw-r--r--src/tests/tcmalloc_unittest.cc23
6 files changed, 64 insertions, 15 deletions
diff --git a/src/tests/debugallocation_test.cc b/src/tests/debugallocation_test.cc
index c482187..f10e2dc 100644
--- a/src/tests/debugallocation_test.cc
+++ b/src/tests/debugallocation_test.cc
@@ -259,7 +259,10 @@ TEST(DebugAllocationTest, GetAllocatedSizeTest) {
}
TEST(DebugAllocationTest, HugeAlloc) {
- const size_t kTooBig = ~static_cast<size_t>(0);
+ // This must not be a const variable so it doesn't form an
+ // integral-constant-expression which can be *statically* rejected by the
+ // compiler as too large for the allocation.
+ size_t kTooBig = ~static_cast<size_t>(0);
void* a = NULL;
char* b = NULL;
@@ -273,8 +276,9 @@ TEST(DebugAllocationTest, HugeAlloc) {
EXPECT_EQ(NULL, b);
// kAlsoTooBig is small enough not to get caught by debugallocation's check,
- // but will still fall through to tcmalloc's check.
- const size_t kAlsoTooBig = kTooBig - 1024;
+ // but will still fall through to tcmalloc's check. This must also be
+ // a non-const variable. See kTooBig for more details.
+ size_t kAlsoTooBig = kTooBig - 1024;
a = malloc(kAlsoTooBig);
EXPECT_EQ(NULL, a);
diff --git a/src/tests/malloc_extension_test.cc b/src/tests/malloc_extension_test.cc
index ef76766..60f4919 100644
--- a/src/tests/malloc_extension_test.cc
+++ b/src/tests/malloc_extension_test.cc
@@ -39,6 +39,8 @@
#include <google/malloc_extension.h>
#include <google/malloc_extension_c.h>
+using STL_NAMESPACE::vector;
+
int main(int argc, char** argv) {
void* a = malloc(1000);
@@ -70,6 +72,30 @@ int main(int argc, char** argv) {
ASSERT_LE(MallocExtension_GetAllocatedSize(a), 5000);
ASSERT_GE(MallocExtension_GetEstimatedAllocatedSize(1000), 1000);
+ // test invariant: size of freelist = heap_size - allocated_bytes
+ free(malloc(32000));
+ size_t heap_size = 0;
+ size_t allocated = 0;
+ ASSERT_TRUE(MallocExtension::instance()->GetNumericProperty(
+ "generic.current_allocated_bytes", &allocated));
+ ASSERT_TRUE(MallocExtension::instance()->GetNumericProperty(
+ "generic.heap_size", &heap_size));
+ vector<MallocExtension::FreeListInfo> info;
+ MallocExtension::instance()->GetFreeListSizes(&info);
+
+ ASSERT_GE(info.size(), 0);
+ int64 free_bytes = 0;
+ for (vector<MallocExtension::FreeListInfo>::const_iterator it = info.begin();
+ it != info.end();
+ ++it) {
+ free_bytes += it->total_bytes_free;
+ }
+
+ // don't expect an exact equality since the calls to query the heap
+ // themselves free and allocate memory
+ size_t error = abs((heap_size - allocated) - free_bytes);
+ ASSERT_LT(error, 0.15 * heap_size);
+
free(a);
printf("DONE\n");
diff --git a/src/tests/sampling_test.cc b/src/tests/sampling_test.cc
index b75e70e..c1bd693 100644
--- a/src/tests/sampling_test.cc
+++ b/src/tests/sampling_test.cc
@@ -45,6 +45,8 @@
using std::string;
+extern "C" void* AllocateAllocate() ATTRIBUTE_NOINLINE;
+
extern "C" void* AllocateAllocate() {
// The VLOG's are mostly to discourage inlining
VLOG(1, "Allocating some more");
diff --git a/src/tests/sampling_test.sh b/src/tests/sampling_test.sh
index 8c96bc1..2a58426 100755
--- a/src/tests/sampling_test.sh
+++ b/src/tests/sampling_test.sh
@@ -81,13 +81,13 @@ mkdir "$OUTDIR" || die "Unable to create $OUTDIR"
echo "Testing heap output..."
"$PPROF" --text "$SAMPLING_TEST_BINARY" "$OUTDIR/out.heap" \
- | grep '^ *[5-9][0-9]\.[0-9][ 0-9.%]*_*AllocateAllocate' >/dev/null \
+ | grep '[5-9][0-9]\.[0-9][ 0-9.%]*_*AllocateAllocate' >/dev/null \
|| die "$PPROF" --text "$SAMPLING_TEST_BINARY" "$OUTDIR/out.heap"
echo "OK"
echo "Testing growth output..."
"$PPROF" --text "$SAMPLING_TEST_BINARY" "$OUTDIR/out.growth" \
- | grep '^ *[5-9][0-9]\.[0-9][ 0-9.%]*_*AllocateAllocate' >/dev/null \
+ | grep '[5-9][0-9]\.[0-9][ 0-9.%]*_*AllocateAllocate' >/dev/null \
|| die "$PPROF" --text "$SAMPLING_TEST_BINARY" "$OUTDIR/out.growth"
echo "OK"
diff --git a/src/tests/system-alloc_unittest.cc b/src/tests/system-alloc_unittest.cc
index a160a34..da76285 100644
--- a/src/tests/system-alloc_unittest.cc
+++ b/src/tests/system-alloc_unittest.cc
@@ -38,7 +38,9 @@
#include <inttypes.h> // another place uintptr_t might be defined
#endif
#include <sys/types.h>
+#include <algorithm>
#include "base/logging.h"
+#include "common.h"
#include "system-alloc.h"
class ArraySysAllocator : public SysAllocator {
@@ -98,6 +100,18 @@ static void TestBasicInvoked() {
CHECK(a.invoked_);
}
+#if 0 // could port this to various OSs, but won't bother for now
+TEST(AddressBits, CpuVirtualBits) {
+ // Check that kAddressBits is as least as large as either the number of bits
+ // in a pointer or as the number of virtual bits handled by the processor.
+ // To be effective this test must be run on each processor model.
+ const int kPointerBits = 8 * sizeof(void*);
+ const int kImplementedVirtualBits = NumImplementedVirtualBits();
+
+ CHECK_GE(kAddressBits, min(kImplementedVirtualBits, kPointerBits));
+}
+#endif
+
int main(int argc, char** argv) {
TestBasicInvoked();
diff --git a/src/tests/tcmalloc_unittest.cc b/src/tests/tcmalloc_unittest.cc
index 522c0d9..c528846 100644
--- a/src/tests/tcmalloc_unittest.cc
+++ b/src/tests/tcmalloc_unittest.cc
@@ -100,17 +100,12 @@
# define cfree free // don't bother to try to test these obsolete fns
# define valloc malloc
# define pvalloc malloc
-# ifdef PERFTOOLS_NO_ALIGNED_MALLOC
-# define _aligned_malloc(size, alignment) malloc(size)
-# else
-# include <malloc.h> // for _aligned_malloc
-# endif
-# define memalign(alignment, size) _aligned_malloc(size, alignment)
-// Assume if we fail, it's because of out-of-memory.
-// Note, this isn't a perfect analogue: we don't enforce constraints on "align"
+// I'd like to map posix_memalign to _aligned_malloc, but _aligned_malloc
+// must be paired with _aligned_free (not normal free), which is too
+// invasive a change to how we allocate memory here. So just bail
# include <errno.h>
-# define posix_memalign(pptr, align, size) \
- ((*(pptr)=_aligned_malloc(size, align)) ? 0 : ENOMEM)
+# define memalign(alignment, size) malloc(size)
+# define posix_memalign(pptr, align, size) ((*(pptr)=malloc(size)) ? 0 : ENOMEM)
#endif
// On systems (like freebsd) that don't define MAP_ANONYMOUS, use the old
@@ -1033,6 +1028,14 @@ static int RunAllTests(int argc, char** argv) {
free(p1);
VerifyDeleteHookWasCalled();
+ // Windows has _aligned_malloc. Let's test that that's captured too.
+#if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(PERFTOOLS_NO_ALIGNED_MALLOC)
+ p1 = _aligned_malloc(sizeof(p1) * 2, 64);
+ VerifyNewHookWasCalled();
+ _aligned_free(p1);
+ VerifyDeleteHookWasCalled();
+#endif
+
p1 = valloc(60);
VerifyNewHookWasCalled();
free(p1);