1 | // Test the mmap_limit_mb flag. |
2 | // |
3 | // Unstable on watchOS devices under memory pressure. |
4 | // UNSUPPORTED: watchos |
5 | // |
6 | // RUN: %clangxx_asan -O2 %s -o %t |
7 | // RUN: %run %t 20 16 |
8 | // RUN: %run %t 30 1000000 |
9 | // RUN: %env_asan_opts=mmap_limit_mb=300 %run %t 20 16 |
10 | // RUN: %env_asan_opts=mmap_limit_mb=300 %run %t 20 1000000 |
11 | // RUN: %env_asan_opts=mmap_limit_mb=300 not %run %t 500 16 2>&1 | FileCheck %s |
12 | // RUN: %env_asan_opts=mmap_limit_mb=300 not %run %t 500 1000000 2>&1 | FileCheck %s |
13 | // |
14 | // FIXME: Windows doesn't implement mmap_limit_mb. |
15 | // XFAIL: target={{.*windows-msvc.*}} |
16 | |
17 | #include <assert.h> |
18 | #include <stdlib.h> |
19 | #include <stdio.h> |
20 | |
21 | #include <algorithm> |
22 | #include <vector> |
23 | |
24 | int main(int argc, char **argv) { |
25 | assert(argc == 3); |
26 | long total_mb = atoi(nptr: argv[1]); |
27 | long allocation_size = atoi(nptr: argv[2]); |
28 | fprintf(stderr, format: "total_mb: %zd allocation_size: %zd\n" , total_mb, |
29 | allocation_size); |
30 | std::vector<char *> v; |
31 | for (long total = total_mb << 20; total > 0; total -= allocation_size) |
32 | v.push_back(x: new char[allocation_size]); |
33 | for (std::vector<char *>::const_iterator it = v.begin(); it != v.end(); ++it) |
34 | delete[](*it); |
35 | fprintf(stderr, format: "PASS\n" ); |
36 | // CHECK: total_mmaped{{.*}}mmap_limit_mb |
37 | return 0; |
38 | } |
39 | |