]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/esan/TestCases/workingset-samples.cpp
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / esan / TestCases / workingset-samples.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 // Stucks at init and no clone feature equivalent.
7 // UNSUPPORTED: freebsd
8
9 #include <sanitizer/esan_interface.h>
10 #include <sched.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/mman.h>
14
15 const int size = 0x1 << 25; // 523288 cache lines
16
17 int main(int argc, char **argv) {
18   char *buf = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
19                            MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
20   // To avoid flakiness stemming from whether the sideline thread
21   // is scheduled enough on a loaded test machine, we coordinate
22   // with esan itself:
23   if (__esan_get_sample_count) {
24     while (__esan_get_sample_count() < 4) {
25       for (int i = 0; i < size; ++i)
26         buf[i] = i;
27       sched_yield();
28     }
29   }
30   munmap(buf, size);
31   // We only check for a few samples here to reduce the chance of flakiness.
32   // CHECK:      =={{[0-9]+}}== Total number of samples: {{[0-9]+}}
33   // CHECK-NEXT: =={{[0-9]+}}== Samples array #0 at period 20 ms
34   // CHECK-NEXT: =={{[0-9]+}}==#   0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
35   // CHECK-NEXT: =={{[0-9]+}}==#   1: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
36   // CHECK-NEXT: =={{[0-9]+}}==#   2: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
37   // CHECK-NEXT: =={{[0-9]+}}==#   3: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
38   // CHECK:      =={{[0-9]+}}== Samples array #1 at period 80 ms
39   // CHECK-NEXT: =={{[0-9]+}}==#   0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
40   // CHECK:      =={{[0-9]+}}== Samples array #2 at period 320 ms
41   // CHECK:      =={{[0-9]+}}== Samples array #3 at period 1280 ms
42   // CHECK:      =={{[0-9]+}}== Samples array #4 at period 5120 ms
43   // CHECK:      =={{[0-9]+}}== Samples array #5 at period 20 sec
44   // CHECK:      =={{[0-9]+}}== Samples array #6 at period 81 sec
45   // CHECK:      =={{[0-9]+}}== Samples array #7 at period 327 sec
46   // CHECK: {{.*}} EfficiencySanitizer: the total working set size: 32 MB (5242{{[0-9][0-9]}} cache lines)
47   return 0;
48 }