summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/exception_classes/mmap.cpp
blob: 8cc36c725fd92fbdd1cbc075691e0200dc4e9121 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <vespa/vespalib/util/alloc.h>
#include <vector>
#include <assert.h>
#include <string.h>
#include <sys/resource.h>

using namespace vespalib::alloc;

int main(int argc, char *argv[]) {
    if (argc != 4) {
        return 77;
    }
    size_t virt = strtoul(argv[1], nullptr, 0);
    size_t blockSize = strtoul(argv[2], nullptr, 0);
    size_t numBlocks = strtoul(argv[3], nullptr, 0);
    rlimit virtualLimit;
    virtualLimit.rlim_cur = virt;
    virtualLimit.rlim_max = virt;
    assert(setrlimit(RLIMIT_AS, &virtualLimit) == 0);
    std::vector<Alloc> mappings;
    for (size_t i(0); i < numBlocks; i++) {
        mappings.emplace_back(Alloc::allocMMap(blockSize));
        memset(mappings.back().get(), 0xa5, mappings.back().size());
    }
    return 0;
}