Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // Test the mmap_limit_mb flag. |
| 2 | // |
| 3 | // RUN: %clangxx_asan -O2 %s -o %t |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 4 | // RUN: %run %t 20 16 |
| 5 | // RUN: %run %t 30 1000000 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 6 | // RUN: %env_asan_opts=mmap_limit_mb=300 %run %t 20 16 |
| 7 | // RUN: %env_asan_opts=mmap_limit_mb=300 %run %t 20 1000000 |
| 8 | // RUN: %env_asan_opts=mmap_limit_mb=300 not %run %t 500 16 2>&1 | FileCheck %s |
| 9 | // RUN: %env_asan_opts=mmap_limit_mb=300 not %run %t 500 1000000 2>&1 | FileCheck %s |
| 10 | // |
| 11 | // FIXME: Windows doesn't implement mmap_limit_mb. |
| 12 | // XFAIL: arm-linux-gnueabi,win32 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 13 | |
| 14 | #include <assert.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <stdio.h> |
| 17 | |
| 18 | #include <algorithm> |
| 19 | #include <vector> |
| 20 | |
| 21 | int main(int argc, char **argv) { |
| 22 | assert(argc == 3); |
| 23 | long total_mb = atoi(argv[1]); |
| 24 | long allocation_size = atoi(argv[2]); |
| 25 | fprintf(stderr, "total_mb: %zd allocation_size: %zd\n", total_mb, |
| 26 | allocation_size); |
| 27 | std::vector<char *> v; |
| 28 | for (long total = total_mb << 20; total > 0; total -= allocation_size) |
| 29 | v.push_back(new char[allocation_size]); |
| 30 | for (std::vector<char *>::const_iterator it = v.begin(); it != v.end(); ++it) |
| 31 | delete[](*it); |
| 32 | fprintf(stderr, "PASS\n"); |
| 33 | // CHECK: total_mmaped{{.*}}mmap_limit_mb |
| 34 | return 0; |
| 35 | } |