File: hard_rss_limit_mb_test.cpp

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 995,836 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (43 lines) | stat: -rw-r--r-- 1,356 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Check hard_rss_limit_mb. Not all sanitizers implement it yet.
// RUN: %clangxx -O2 %s -o %t
//
// Run with limit should fail:
// RUN: %env_tool_opts=hard_rss_limit_mb=100                           not %run %t 2>&1 | FileCheck %s
// This run uses getrusage:
// RUN: %env_tool_opts=hard_rss_limit_mb=100:can_use_proc_maps_statm=0 not %run %t 2>&1 | FileCheck %s
//
// Run w/o limit or with a large enough limit should pass:
// RUN: %env_tool_opts=hard_rss_limit_mb=1000 %run %t
// RUN: %run %t
//
// FIXME: make it work for other sanitizers.
// XFAIL: lsan
// XFAIL: tsan
// XFAIL: msan
// XFAIL: ubsan

// UNSUPPORTED: freebsd, solaris, darwin

#include <string.h>
#include <stdio.h>
#include <unistd.h>

const int kNumAllocs = 200 * 1000;
const int kAllocSize = 1000;
volatile char *sink[kNumAllocs];

int main(int argc, char **argv) {
  for (int i = 0; i < kNumAllocs; i++) {
    if ((i % 1000) == 0) {
      // Don't write to stderr! Doing that triggers a kernel race condition
      // between this thread and the rss-limit thread, and may lose part of the
      // output. See https://lkml.org/lkml/2014/2/17/324.
      printf("[%d]\n", i);
    }
    char *x = new char[kAllocSize];
    memset(x, 0, kAllocSize);
    sink[i] = x;
  }
  sleep(1);  // Make sure the background thread has time to kill the process.
// CHECK: hard rss limit exhausted
}