]>
git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/scudo/rss.c
1 // RUN: %clang_scudo %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
3 // RUN: %env_scudo_opts="soft_rss_limit_mb=256" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
4 // RUN: %env_scudo_opts="hard_rss_limit_mb=256" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
5 // RUN: %env_scudo_opts="soft_rss_limit_mb=64:allocator_may_return_null=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit
6 // RUN: %env_scudo_opts="soft_rss_limit_mb=64:allocator_may_return_null=1" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit-returnnull
7 // RUN: %env_scudo_opts="soft_rss_limit_mb=64:allocator_may_return_null=0:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit
8 // RUN: %env_scudo_opts="soft_rss_limit_mb=64:allocator_may_return_null=1:can_use_proc_maps_statm=0" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit-returnnull
9 // RUN: %env_scudo_opts="hard_rss_limit_mb=64:allocator_may_return_null=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
10 // RUN: %env_scudo_opts="hard_rss_limit_mb=64:allocator_may_return_null=1" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
11 // RUN: %env_scudo_opts="hard_rss_limit_mb=64:allocator_may_return_null=0:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
12 // RUN: %env_scudo_opts="hard_rss_limit_mb=64:allocator_may_return_null=1:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
14 // Tests that the soft and hard RSS limits work as intended. Without limit or
15 // with a high limit, the test should pass without any malloc returning NULL or
17 // If a limit is specified, it should return some NULL or die depending on
18 // allocator_may_return_null. This should also work without statm.
25 static const size_t kNumAllocs
= 128;
26 static const size_t kAllocSize
= 1 << 20; // 1MB.
28 static void *allocs
[kNumAllocs
];
30 int main(int argc
, char *argv
[]) {
31 int returned_null
= 0;
32 for (int i
= 0; i
< kNumAllocs
; i
++) {
35 allocs
[i
] = malloc(kAllocSize
);
37 memset(allocs
[i
], 0xff, kAllocSize
); // Dirty the pages.
41 for (int i
= 0; i
< kNumAllocs
; i
++)
43 if (returned_null
== 0)
44 printf("All malloc calls succeeded\n");
46 printf("%d malloc calls returned NULL\n", returned_null
);
50 // CHECK-nolimit: All malloc calls succeeded
51 // CHECK-softlimit: soft RSS limit exhausted
52 // CHECK-softlimit-NOT: malloc calls
53 // CHECK-softlimit-returnnull: soft RSS limit exhausted
54 // CHECK-softlimit-returnnull: malloc calls returned NULL
55 // CHECK-hardlimit: hard RSS limit exhausted
56 // CHECK-hardlimit-NOT: malloc calls