]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc
Vendor import of compiler-rt trunk r338536:
[FreeBSD/FreeBSD.git] / test / sanitizer_common / TestCases / hard_rss_limit_mb_test.cc
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 // XFAIL: ubsan
18
19 // UNSUPPORTED: freebsd, solaris, darwin
20
21 #include <string.h>
22 #include <stdio.h>
23 #include <unistd.h>
24
25 const int kNumAllocs = 200 * 1000;
26 const int kAllocSize = 1000;
27 volatile char *sink[kNumAllocs];
28
29 int main(int argc, char **argv) {
30   for (int i = 0; i < kNumAllocs; i++) {
31     if ((i % 1000) == 0) {
32       // Don't write to stderr! Doing that triggers a kernel race condition
33       // between this thread and the rss-limit thread, and may lose part of the
34       // output. See https://lkml.org/lkml/2014/2/17/324.
35       printf("[%d]\n", i);
36     }
37     char *x = new char[kAllocSize];
38     memset(x, 0, kAllocSize);
39     sink[i] = x;
40   }
41   sleep(1);  // Make sure the background thread has time to kill the process.
42 // CHECK: hard rss limit exhausted
43 }