Changeset View
Changeset View
Standalone View
Standalone View
test/scudo/rss.c
Show All 14 Lines | |||||
// with a high limit, the test should pass without any malloc returning NULL or | // with a high limit, the test should pass without any malloc returning NULL or | ||||
// the program dying. | // the program dying. | ||||
// If a limit is specified, it should return some NULL or die depending on | // If a limit is specified, it should return some NULL or die depending on | ||||
// allocator_may_return_null. This should also work without statm. | // allocator_may_return_null. This should also work without statm. | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#if defined(_WIN32) | |||||
# include <windows.h> | |||||
#else | |||||
#include <unistd.h> | # include <unistd.h> | ||||
#endif | |||||
static const size_t kNumAllocs = 128; | static const size_t kNumAllocs = 128; | ||||
static const size_t kAllocSize = 1 << 20; // 1MB. | static const size_t kAllocSize = 1 << 20; // 1MB. | ||||
static void *allocs[kNumAllocs]; | static void *allocs[kNumAllocs]; | ||||
void sleep_ms(unsigned int ms) { | |||||
#if defined(_WIN32) | |||||
Sleep(ms); | |||||
#else | |||||
usleep(ms * 1000U); | |||||
#endif | |||||
} | |||||
int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||||
int returned_null = 0; | int returned_null = 0; | ||||
for (int i = 0; i < kNumAllocs; i++) { | for (int i = 0; i < kNumAllocs; i++) { | ||||
if ((i & 0xf) == 0) | if ((i & 0xf) == 0) | ||||
usleep(50000); | sleep_ms(50); | ||||
allocs[i] = malloc(kAllocSize); | allocs[i] = malloc(kAllocSize); | ||||
if (allocs[i]) | if (allocs[i]) | ||||
memset(allocs[i], 0xff, kAllocSize); // Dirty the pages. | memset(allocs[i], 0xff, kAllocSize); // Dirty the pages. | ||||
else | else | ||||
returned_null++; | returned_null++; | ||||
} | } | ||||
for (int i = 0; i < kNumAllocs; i++) | for (int i = 0; i < kNumAllocs; i++) | ||||
free(allocs[i]); | free(allocs[i]); | ||||
Show All 14 Lines |