]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/esan/TestCases/workingset-simple.cpp
New upstream version 1.28.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / esan / TestCases / workingset-simple.cpp
1 // RUN: %clang_esan_wset -O0 %s -o %t 2>&1
2 // RUN: %run %t 2>&1 | FileCheck %s
3
4 // FIXME: Re-enable once PR33590 is fixed.
5 // UNSUPPORTED: x86_64
6
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/mman.h>
10 #include <assert.h>
11
12 const int size = 0x1 << 25; // 523288 cache lines
13 const int line_size = 64;
14
15 int main(int argc, char **argv) {
16 char *bufA = (char *)malloc(sizeof(char) * line_size);
17 char bufB[64];
18 char *bufC = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
19 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
20 bufA[0] = 0;
21 // This additional access to the same line should not increase the line
22 // count: but it's difficult to make a non-flaky test that measures the
23 // lines down to the ones digit so right now we're not really testing that.
24 // If we add a heap-only mode we may be able to be more precise.
25 bufA[1] = 0;
26 bufB[33] = 1;
27 for (int i = 0; i < size; i += line_size)
28 bufC[i] = 0;
29 free(bufA);
30 munmap(bufC, 0x4000);
31 // CHECK: {{.*}} EfficiencySanitizer: the total working set size: 32 MB (524{{[0-9][0-9][0-9]}} cache lines)
32 return 0;
33 }