1 // RUN: %clang_esan_wset -O0 %s -o %t 2>&1
2 // RUN: %run %t 2>&1 | FileCheck %s
3
4 #include <sched.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <sys/mman.h>
8
9 const int size = 0x1 << 25; // 523288 cache lines
10 const int iters = 6;
11
main(int argc,char ** argv)12 int main(int argc, char **argv) {
13 char *buf = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
14 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
15 // Try to increase the probability that the sideline thread is
16 // scheduled. Unfortunately we can't do proper synchronization
17 // without some form of annotation or something.
18 sched_yield();
19 // Do enough work to get at least 4 samples.
20 for (int j = 0; j < iters; ++j) {
21 for (int i = 0; i < size; ++i)
22 buf[i] = i;
23 sched_yield();
24 }
25 munmap(buf, size);
26 // We only check for a few samples here to reduce the chance of flakiness.
27 // CHECK: =={{[0-9]+}}== Total number of samples: {{[0-9]+}}
28 // CHECK-NEXT: =={{[0-9]+}}== Samples array #0 at period 20 ms
29 // CHECK-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
30 // CHECK-NEXT: =={{[0-9]+}}==# 1: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
31 // CHECK-NEXT: =={{[0-9]+}}==# 2: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
32 // CHECK-NEXT: =={{[0-9]+}}==# 3: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
33 // CHECK: =={{[0-9]+}}== Samples array #1 at period 80 ms
34 // CHECK-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
35 // CHECK: =={{[0-9]+}}== Samples array #2 at period 320 ms
36 // CHECK: =={{[0-9]+}}== Samples array #3 at period 1280 ms
37 // CHECK: =={{[0-9]+}}== Samples array #4 at period 5120 ms
38 // CHECK: =={{[0-9]+}}== Samples array #5 at period 20 sec
39 // CHECK: =={{[0-9]+}}== Samples array #6 at period 81 sec
40 // CHECK: =={{[0-9]+}}== Samples array #7 at period 327 sec
41 // CHECK: {{.*}} EfficiencySanitizer: the total working set size: 32 MB (5242{{[0-9][0-9]}} cache lines)
42 return 0;
43 }
44