]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/esan/TestCases/workingset-midreport.cpp
New upstream version 1.28.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / esan / TestCases / workingset-midreport.cpp
1 // RUN: %clang_esan_wset -O0 %s -o %t 2>&1
2 // RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN
3
4 // RUN: %clang -O0 %s -o %t 2>&1
5 // RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ESAN
6
7 // FIXME: Re-enable once PR33590 is fixed.
8 // UNSUPPORTED: x86_64
9
10 #include <sanitizer/esan_interface.h>
11 #include <sched.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/mman.h>
16
17 const int size = 0x1 << 25; // 523288 cache lines
18 const int iters = 6;
19
20 int main(int argc, char **argv) {
21 char *buf = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
22 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
23 // To avoid flakiness stemming from whether the sideline thread
24 // is scheduled enough on a loaded test machine, we coordinate
25 // with esan itself:
26 if (__esan_get_sample_count) {
27 while (__esan_get_sample_count() < 4) {
28 for (int i = 0; i < size; ++i)
29 buf[i] = i;
30 sched_yield();
31 }
32 }
33 // Ensure a non-esan build works without ifdefs:
34 if (__esan_report) {
35 // We should get 2 roughly identical reports:
36 __esan_report();
37 }
38 munmap(buf, size);
39 fprintf(stderr, "all done\n");
40 // CHECK-NO-ESAN: all done
41 // We only check for a few samples here to reduce the chance of flakiness:
42 // CHECK-ESAN: =={{[0-9]+}}== Total number of samples: {{[0-9]+}}
43 // CHECK-ESAN-NEXT: =={{[0-9]+}}== Samples array #0 at period 20 ms
44 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
45 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 1: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
46 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 2: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
47 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 3: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
48 // CHECK-ESAN: =={{[0-9]+}}== Samples array #1 at period 80 ms
49 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
50 // CHECK-ESAN: =={{[0-9]+}}== Samples array #2 at period 320 ms
51 // CHECK-ESAN: =={{[0-9]+}}== Samples array #3 at period 1280 ms
52 // CHECK-ESAN: =={{[0-9]+}}== Samples array #4 at period 5120 ms
53 // CHECK-ESAN: =={{[0-9]+}}== Samples array #5 at period 20 sec
54 // CHECK-ESAN: =={{[0-9]+}}== Samples array #6 at period 81 sec
55 // CHECK-ESAN: =={{[0-9]+}}== Samples array #7 at period 327 sec
56 // CHECK-ESAN: {{.*}} EfficiencySanitizer: the total working set size: 32 MB (5242{{[0-9][0-9]}} cache lines)
57 // CHECK-ESAN-NEXT: all done
58 // CHECK-ESAN-NEXT: =={{[0-9]+}}== Total number of samples: {{[0-9]+}}
59 // CHECK-ESAN-NEXT: =={{[0-9]+}}== Samples array #0 at period 20 ms
60 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
61 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 1: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
62 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 2: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
63 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 3: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
64 // CHECK-ESAN: =={{[0-9]+}}== Samples array #1 at period 80 ms
65 // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
66 // CHECK-ESAN: =={{[0-9]+}}== Samples array #2 at period 320 ms
67 // CHECK-ESAN: =={{[0-9]+}}== Samples array #3 at period 1280 ms
68 // CHECK-ESAN: =={{[0-9]+}}== Samples array #4 at period 5120 ms
69 // CHECK-ESAN: =={{[0-9]+}}== Samples array #5 at period 20 sec
70 // CHECK-ESAN: =={{[0-9]+}}== Samples array #6 at period 81 sec
71 // CHECK-ESAN: =={{[0-9]+}}== Samples array #7 at period 327 sec
72 // CHECK-ESAN: {{.*}} EfficiencySanitizer: the total working set size: 32 MB (5242{{[0-9][0-9]}} cache lines)
73 return 0;
74 }