39 lines · cpp
1// Test the mmap_limit_mb flag.2//3// Unstable on watchOS devices under memory pressure.4// UNSUPPORTED: watchos5//6// RUN: %clangxx_asan -O2 %s -o %t7// RUN: %run %t 20 168// RUN: %run %t 30 10000009// RUN: %env_asan_opts=mmap_limit_mb=300 %run %t 20 1610// RUN: %env_asan_opts=mmap_limit_mb=300 %run %t 20 100000011// RUN: %env_asan_opts=mmap_limit_mb=300 not %run %t 500 16 2>&1 | FileCheck %s12// RUN: %env_asan_opts=mmap_limit_mb=300 not %run %t 500 1000000 2>&1 | FileCheck %s13//14// FIXME: Windows doesn't implement mmap_limit_mb.15// XFAIL: target={{.*windows-msvc.*}}16 17#include <assert.h>18#include <stdlib.h>19#include <stdio.h>20 21#include <algorithm>22#include <vector>23 24int main(int argc, char **argv) {25 assert(argc == 3);26 long total_mb = atoi(argv[1]);27 long allocation_size = atoi(argv[2]);28 fprintf(stderr, "total_mb: %zd allocation_size: %zd\n", total_mb,29 allocation_size);30 std::vector<char *> v;31 for (long total = total_mb << 20; total > 0; total -= allocation_size)32 v.push_back(new char[allocation_size]);33 for (std::vector<char *>::const_iterator it = v.begin(); it != v.end(); ++it)34 delete[](*it);35 fprintf(stderr, "PASS\n");36 // CHECK: total_mmaped{{.*}}mmap_limit_mb37 return 0;38}39