blob: 02410525b2d642eba5a8df0222fd4dd9c415e4fa [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 Nainarcdce50b2015-07-01 12:26:56 -07006// 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 Hines6a211c52014-07-21 00:49:56 -070010// XFAIL: arm-linux-gnueabi
Stephen Hines2d1fdb22014-05-28 23:58:16 -070011
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}