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 | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 6 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:mmap_limit_mb=300 %run %t 20 16 |
| 7 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:mmap_limit_mb=300 %run %t 20 1000000 |
| 8 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:mmap_limit_mb=300 not %run %t 500 16 2>&1 | FileCheck %s |
| 9 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:mmap_limit_mb=300 not %run %t 500 1000000 2>&1 | FileCheck %s |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 10 | // XFAIL: arm-linux-gnueabi |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 11 | |
| 12 | #include <assert.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <stdio.h> |
| 15 | |
| 16 | #include <algorithm> |
| 17 | #include <vector> |
| 18 | |
| 19 | int main(int argc, char **argv) { |
| 20 | assert(argc == 3); |
| 21 | long total_mb = atoi(argv[1]); |
| 22 | long allocation_size = atoi(argv[2]); |
| 23 | fprintf(stderr, "total_mb: %zd allocation_size: %zd\n", total_mb, |
| 24 | allocation_size); |
| 25 | std::vector<char *> v; |
| 26 | for (long total = total_mb << 20; total > 0; total -= allocation_size) |
| 27 | v.push_back(new char[allocation_size]); |
| 28 | for (std::vector<char *>::const_iterator it = v.begin(); it != v.end(); ++it) |
| 29 | delete[](*it); |
| 30 | fprintf(stderr, "PASS\n"); |
| 31 | // CHECK: total_mmaped{{.*}}mmap_limit_mb |
| 32 | return 0; |
| 33 | } |