summaryrefslogtreecommitdiff
path: root/src/tests/system-alloc_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/system-alloc_unittest.cc')
-rw-r--r--src/tests/system-alloc_unittest.cc24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/tests/system-alloc_unittest.cc b/src/tests/system-alloc_unittest.cc
index c006425..8e4eb36 100644
--- a/src/tests/system-alloc_unittest.cc
+++ b/src/tests/system-alloc_unittest.cc
@@ -40,6 +40,7 @@
#endif
#include <sys/types.h>
#include <algorithm>
+#include <limits>
#include "base/logging.h" // for Check_GEImpl, Check_LTImpl, etc
#include <google/malloc_extension.h> // for MallocExtension::instance
#include "common.h" // for kAddressBits
@@ -83,7 +84,6 @@ public:
void DumpStats() {
}
- void FlagsInitialized() {}
private:
static const int kArraySize = 8 * 1024 * 1024;
@@ -115,14 +115,30 @@ TEST(AddressBits, CpuVirtualBits) {
const int kPointerBits = 8 * sizeof(void*);
const int kImplementedVirtualBits = NumImplementedVirtualBits();
- CHECK_GE(kAddressBits, min(kImplementedVirtualBits, kPointerBits));
+ CHECK_GE(kAddressBits, std::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);
+ //
+ // There is no way to call malloc and guarantee it will fail. malloc takes a
+ // size_t parameter and the C++ standard does not constrain the size of
+ // size_t. For example, consider an implementation where size_t is 32 bits
+ // and pointers are 64 bits.
+ //
+ // It is likely, though, that sizeof(size_t) == sizeof(void*). In that case,
+ // the first allocation here might succeed but the second allocation must
+ // fail.
+ //
+ // If the second allocation succeeds, you will have to rewrite or
+ // disable this test.
+ // The weird parens are to avoid macro-expansion of 'max' on windows.
+ const size_t kHugeSize = (std::numeric_limits<size_t>::max)() / 2;
+ void* p1 = malloc(kHugeSize);
+ void* p2 = malloc(kHugeSize);
+ CHECK(p2 == NULL);
+ if (p1 != NULL) free(p1);
char* q = new char[1024];
CHECK(q != NULL);