1// Check hard_rss_limit_mb. Not all sanitizers implement it yet. 2// RUN: %clangxx -O2 %s -o %t 3// 4// Run with limit should fail: 5// RUN: %env_tool_opts=hard_rss_limit_mb=100 not %run %t 2>&1 | FileCheck %s 6// This run uses getrusage: 7// RUN: %env_tool_opts=hard_rss_limit_mb=100:can_use_proc_maps_statm=0 not %run %t 2>&1 | FileCheck %s 8// 9// Run w/o limit or with a large enough limit should pass: 10// RUN: %env_tool_opts=hard_rss_limit_mb=1000 %run %t 11// RUN: %run %t 12// 13// FIXME: make it work for other sanitizers. 14// XFAIL: lsan 15// XFAIL: tsan 16// XFAIL: msan 17 18#include <string.h> 19#include <stdio.h> 20#include <unistd.h> 21 22const int kNumAllocs = 200 * 1000; 23const int kAllocSize = 1000; 24volatile char *sink[kNumAllocs]; 25 26int main(int argc, char **argv) { 27 for (int i = 0; i < kNumAllocs; i++) { 28 if ((i % 1000) == 0) { 29 fprintf(stderr, "[%d]\n", i); 30 } 31 char *x = new char[kAllocSize]; 32 memset(x, 0, kAllocSize); 33 sink[i] = x; 34 } 35 sleep(1); // Make sure the background thread has time to kill the process. 36// CHECK: hard rss limit exhausted 37} 38