1// Test the mmap_limit_mb flag.
2//
3// RUN: %clangxx_asan -O2 %s -o %t
4// RUN: %run %t 20 16
5// RUN: %run %t 30 1000000
6// RUN: env ASAN_OPTIONS=mmap_limit_mb=300 %run %t 20 16
7// RUN: env ASAN_OPTIONS=mmap_limit_mb=300 %run %t 20 1000000
8// RUN: env ASAN_OPTIONS=mmap_limit_mb=300 not %run %t 500 16 2>&1 | FileCheck %s
9// RUN: env ASAN_OPTIONS=mmap_limit_mb=300 not %run %t 500 1000000 2>&1 | FileCheck %s
10// XFAIL: arm-linux-gnueabi
11
12#include <assert.h>
13#include <stdlib.h>
14#include <stdio.h>
15
16#include <algorithm>
17#include <vector>
18
19int 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}
34