blob: 379524121a8893ad6f73a697939022cf174e7301 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// Test the mmap_limit_mb flag.
2//
3// RUN: %clangxx_asan -O2 %s -o %t
Stephen Hines6d186232014-11-26 17:56:19 -08004// RUN: %run %t 20 16
5// RUN: %run %t 30 1000000
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08006// 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 Hines2d1fdb22014-05-28 23:58:16 -070013
14#include <assert.h>
15#include <stdlib.h>
16#include <stdio.h>
17
18#include <algorithm>
19#include <vector>
20
21int 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}