blob: bbaff5e848aacb428dd5f3d465831b0b1e3d088a (
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// REQUIRES: not-msan && not-asan
// RUN: %clang %s -emit-llvm -g -c -o %t.bc
// RUN: rm -rf %t.klee-out %t.log
// RUN: %klee -kdalloc -kdalloc-quarantine=-1 -output-dir=%t.klee-out %t.bc -exit-on-error 2>&1 | tee %t.log
// RUN: FileCheck %s -input-file=%t.log
// This test is disabled for asan and msan because they create additional page faults
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/resource.h>
#include "klee/klee.h"
size_t maxrss() {
struct rusage usage;
int res = getrusage(RUSAGE_SELF, &usage);
assert(!res && "getrusage succeeded");
return usage.ru_maxrss;
}
int main(void) {
size_t baseline = maxrss();
#if defined(__APPLE__)
size_t limit = baseline + 100 * 1024 * 1024; // limit is 100 MiB above baseline
#else
size_t limit = baseline + 100 * 1024; // limit is 100 MiB above baseline
#endif
// CHECK: Deterministic allocator: Using unlimited quarantine
size_t bins[] = {1, 4, 8, 16, 32, 64, 256, 2048};
for (int i = 0; i < 1000; ++i) {
for (size_t j = 0; j < sizeof(bins) / sizeof(*bins); ++j) {
void *volatile p = malloc(bins[j]);
void *volatile p2 = malloc(4096); // for faster growth
// CHECK: calling external: getrusage
// CHECK-NOT: ASSERTION FAIL
assert(maxrss() < limit && "MaxRSS is below limit");
free(p);
free(p2);
}
}
return 0;
}
|