mirror of
https://github.com/gperftools/gperftools
synced 2025-03-11 07:17:38 +00:00
use more noopt in various unit tests
Many our unit tests require specific stack traces or that allocation/deallocation is not elimininated. As compilation gets more aggressive (such as when cross-object optimization is enabled during LTO), we break more of those cases. This commit extends noopt usage that disables inlining optimization in specific cases. This fixes github issue #1358.
This commit is contained in:
parent
6bdeec0ecb
commit
246782e1d6
@ -38,11 +38,14 @@
|
||||
// argv[1].heap and argv[1].growth
|
||||
|
||||
#include "config_for_unittests.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include <gperftools/malloc_extension.h>
|
||||
#include "gperftools/malloc_extension.h"
|
||||
#include "tests/testutil.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
@ -51,7 +54,7 @@ extern "C" void* AllocateAllocate() ATTRIBUTE_NOINLINE;
|
||||
extern "C" void* AllocateAllocate() {
|
||||
// The VLOG's are mostly to discourage inlining
|
||||
VLOG(1, "Allocating some more");
|
||||
void* p = malloc(10000);
|
||||
void* p = (noopt(malloc))(10000);
|
||||
VLOG(1, "Done allocating");
|
||||
return p;
|
||||
}
|
||||
|
@ -50,13 +50,13 @@ using std::set;
|
||||
// Alloc a size that should always fail.
|
||||
|
||||
void TryAllocExpectFail(size_t size) {
|
||||
void* p1 = noopt(malloc(size));
|
||||
void* p1 = noopt(malloc)(size);
|
||||
CHECK(p1 == NULL);
|
||||
|
||||
void* p2 = noopt(malloc(1));
|
||||
void* p2 = noopt(malloc)(1);
|
||||
CHECK(p2 != NULL);
|
||||
|
||||
void* p3 = noopt(realloc(p2, size));
|
||||
void* p3 = noopt(realloc)(p2, size);
|
||||
CHECK(p3 == NULL);
|
||||
|
||||
free(p2);
|
||||
@ -66,7 +66,7 @@ void TryAllocExpectFail(size_t size) {
|
||||
// If it does work, touch some pages.
|
||||
|
||||
void TryAllocMightFail(size_t size) {
|
||||
unsigned char* p = static_cast<unsigned char*>(noopt(malloc(size)));
|
||||
unsigned char* p = static_cast<unsigned char*>(noopt(malloc)(size));
|
||||
if (p != NULL) {
|
||||
static const size_t kPoints = 1024;
|
||||
|
||||
|
@ -665,12 +665,12 @@ static void TestRealloc() {
|
||||
CHECK(p);
|
||||
// The larger the start-size, the larger the non-reallocing delta.
|
||||
for (int d = 0; d < (s+1) * 2; ++d) {
|
||||
void* new_p = noopt(realloc(p, start_sizes[s] + deltas[d]));
|
||||
void* new_p = noopt(realloc)(p, start_sizes[s] + deltas[d]);
|
||||
CHECK(p == new_p); // realloc should not allocate new memory
|
||||
}
|
||||
// Test again, but this time reallocing smaller first.
|
||||
for (int d = 0; d < s*2; ++d) {
|
||||
void* new_p = noopt(realloc(p, start_sizes[s] - deltas[d]));
|
||||
void* new_p = noopt(realloc)(p, start_sizes[s] - deltas[d]);
|
||||
CHECK(p == new_p); // realloc should not allocate new memory
|
||||
}
|
||||
free(p);
|
||||
@ -906,13 +906,13 @@ static void TestRanges() {
|
||||
|
||||
CheckRangeCallback(a, base::MallocRange::INUSE, MB);
|
||||
CheckRangeCallback(b, base::MallocRange::INUSE, MB);
|
||||
free(a);
|
||||
(noopt(free))(a);
|
||||
CheckRangeCallback(a, base::MallocRange::FREE, MB);
|
||||
CheckRangeCallback(b, base::MallocRange::INUSE, MB);
|
||||
MallocExtension::instance()->ReleaseFreeMemory();
|
||||
CheckRangeCallback(a, releasedType, MB);
|
||||
CheckRangeCallback(b, base::MallocRange::INUSE, MB);
|
||||
free(b);
|
||||
(noopt(free))(b);
|
||||
CheckRangeCallback(a, releasedType, MB);
|
||||
CheckRangeCallback(b, base::MallocRange::FREE, MB);
|
||||
}
|
||||
@ -1293,7 +1293,7 @@ static int RunAllTests(int argc, char** argv) {
|
||||
SetNewHook(); // defined as part of MAKE_HOOK_CALLBACK, above
|
||||
SetDeleteHook(); // ditto
|
||||
|
||||
void* p1 = malloc(10);
|
||||
void* p1 = noopt(malloc)(10);
|
||||
CHECK(p1 != NULL); // force use of this variable
|
||||
VerifyNewHookWasCalled();
|
||||
// Also test the non-standard tc_malloc_size
|
||||
@ -1309,13 +1309,13 @@ static int RunAllTests(int argc, char** argv) {
|
||||
free(p1);
|
||||
VerifyDeleteHookWasCalled();
|
||||
|
||||
p1 = calloc(10, 2);
|
||||
p1 = noopt(calloc)(10, 2);
|
||||
CHECK(p1 != NULL);
|
||||
VerifyNewHookWasCalled();
|
||||
// We make sure we realloc to a big size, since some systems (OS
|
||||
// X) will notice if the realloced size continues to fit into the
|
||||
// malloc-block and make this a noop if so.
|
||||
p1 = realloc(p1, 30000);
|
||||
p1 = noopt(realloc)(p1, 30000);
|
||||
CHECK(p1 != NULL);
|
||||
VerifyNewHookWasCalled();
|
||||
VerifyDeleteHookWasCalled();
|
||||
@ -1323,13 +1323,13 @@ static int RunAllTests(int argc, char** argv) {
|
||||
VerifyDeleteHookWasCalled();
|
||||
|
||||
if (kOSSupportsMemalign) {
|
||||
CHECK_EQ(PosixMemalign(&p1, sizeof(p1), 40), 0);
|
||||
CHECK_EQ(noopt(PosixMemalign)(&p1, sizeof(p1), 40), 0);
|
||||
CHECK(p1 != NULL);
|
||||
VerifyNewHookWasCalled();
|
||||
free(p1);
|
||||
VerifyDeleteHookWasCalled();
|
||||
|
||||
p1 = Memalign(sizeof(p1) * 2, 50);
|
||||
p1 = noopt(Memalign)(sizeof(p1) * 2, 50);
|
||||
CHECK(p1 != NULL);
|
||||
VerifyNewHookWasCalled();
|
||||
free(p1);
|
||||
@ -1338,7 +1338,7 @@ static int RunAllTests(int argc, char** argv) {
|
||||
|
||||
// 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);
|
||||
p1 = noopt(_aligned_malloc)(sizeof(p1) * 2, 64);
|
||||
CHECK(p1 != NULL);
|
||||
VerifyNewHookWasCalled();
|
||||
_aligned_free(p1);
|
||||
|
@ -59,7 +59,7 @@ extern "C" void RunManyThreadsWithId(void (*fn)(int), int count, int stacksize);
|
||||
// out job limits.
|
||||
void SetTestResourceLimit();
|
||||
|
||||
static void (* volatile noopt_helper)(void *) = +[] (void* dummy) {};
|
||||
static void (* volatile noopt_helper)(void *) = [] (void* dummy) {};
|
||||
|
||||
// This function forces compiler to forget specific knowledge about
|
||||
// value of 'val'. This is useful to avoid compiler optimizing out
|
||||
|
Loading…
Reference in New Issue
Block a user