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

Unified Diff: third_party/tcmalloc/chromium/src/tests/system-alloc_unittest.cc

Issue 7050034: Merge google-perftools r109 (the current contents of third_party/tcmalloc/vendor) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/tcmalloc/chromium/src/tests/system-alloc_unittest.cc
===================================================================
--- third_party/tcmalloc/chromium/src/tests/system-alloc_unittest.cc (revision 88335)
+++ third_party/tcmalloc/chromium/src/tests/system-alloc_unittest.cc (working copy)
@@ -31,6 +31,7 @@
// Author: Arun Sharma
#include "config_for_unittests.h"
+#include "system-alloc.h"
#include <stdio.h>
#if defined HAVE_STDINT_H
#include <stdint.h> // to get uintptr_t
@@ -38,8 +39,10 @@
#include <inttypes.h> // another place uintptr_t might be defined
#endif
#include <sys/types.h>
-#include "base/logging.h"
-#include "system-alloc.h"
+#include <algorithm>
+#include "base/logging.h" // for Check_GEImpl, Check_LTImpl, etc
+#include <google/malloc_extension.h> // for MallocExtension::instance
+#include "common.h" // for kAddressBits
class ArraySysAllocator : public SysAllocator {
public:
@@ -53,6 +56,11 @@
void* Alloc(size_t size, size_t *actual_size, size_t alignment) {
invoked_ = true;
+
+ if (size > kArraySize) {
+ return NULL;
+ }
+
void *result = &array_[ptr_];
uintptr_t ptr = reinterpret_cast<uintptr_t>(result);
@@ -73,8 +81,9 @@
return reinterpret_cast<void *>(ptr);
}
- void DumpStats(TCMalloc_Printer* printer) {
+ void DumpStats() {
}
+ void FlagsInitialized() {}
private:
static const int kArraySize = 8 * 1024 * 1024;
@@ -87,7 +96,7 @@
ArraySysAllocator a;
static void TestBasicInvoked() {
- RegisterSystemAllocator(&a, 0);
+ MallocExtension::instance()->SetSystemAllocator(&a);
// An allocation size that is likely to trigger the system allocator.
// XXX: this is implementation specific.
@@ -98,8 +107,31 @@
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
+
+static void TestBasicRetryFailTest() {
+ // Check with the allocator still works after a failed allocation.
+ void* p = malloc(1ULL << 50); // Asking for 1P ram
+ CHECK(p == NULL);
+
+ char* q = new char[1024];
+ CHECK(q != NULL);
+ delete [] q;
+}
+
int main(int argc, char** argv) {
TestBasicInvoked();
+ TestBasicRetryFailTest();
printf("PASS\n");
return 0;

Powered by Google App Engine
This is Rietveld 408576698