summaryrefslogtreecommitdiff
path: root/test/esan
diff options
context:
space:
mode:
authorDerek Bruening <bruening@google.com>2016-07-09 04:13:25 +0000
committerDerek Bruening <bruening@google.com>2016-07-09 04:13:25 +0000
commitbcdfb408444c657422499a2274eb377879588e89 (patch)
treeaedcaccf6e02afc9348c1680cddf2df18aecc29e /test/esan
parent87110b4eb106dc2ccaaa74647293fe6e05cabb96 (diff)
[esan] Add __esan_report for mid-run data
Summary: Adds a new public interface routine __esan_report() which can be used to request profiling results prior to abnormal termination (e.g., for a server process killed by its parent where the normal exit does not allow for normal result reporting). Implements this for the working-set tool. The cache frag tool is left unimplemented as it requires missing iteration capabilities. Adds a new test. Reviewers: aizatsky Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D22098 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274964 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/esan')
-rw-r--r--test/esan/TestCases/workingset-midreport.cpp71
-rw-r--r--test/esan/lit.cfg2
2 files changed, 73 insertions, 0 deletions
diff --git a/test/esan/TestCases/workingset-midreport.cpp b/test/esan/TestCases/workingset-midreport.cpp
new file mode 100644
index 000000000..470e33ca3
--- /dev/null
+++ b/test/esan/TestCases/workingset-midreport.cpp
@@ -0,0 +1,71 @@
+// RUN: %clang_esan_wset -O0 %s -o %t 2>&1
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN
+
+// RUN: %clang -O0 %s -o %t 2>&1
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ESAN
+
+#include <sanitizer/esan_interface.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+
+const int size = 0x1 << 25; // 523288 cache lines
+const int iters = 6;
+
+int main(int argc, char **argv) {
+ char *buf = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ // Try to increase the probability that the sideline thread is
+ // scheduled. Unfortunately we can't do proper synchronization
+ // without some form of annotation or something.
+ sched_yield();
+ // Do enough work to get at least 4 samples.
+ for (int j = 0; j < iters; ++j) {
+ for (int i = 0; i < size; ++i)
+ buf[i] = i;
+ sched_yield();
+ }
+ // Ensure a non-esan build works without ifdefs:
+ if (__esan_report) {
+ // We should get 2 roughly identical reports:
+ __esan_report();
+ }
+ munmap(buf, size);
+ fprintf(stderr, "all done\n");
+ // CHECK-NO-ESAN: all done
+ // We only check for a few samples here to reduce the chance of flakiness:
+ // CHECK-ESAN: =={{[0-9]+}}== Total number of samples: {{[0-9]+}}
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}== Samples array #0 at period 20 ms
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 1: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 2: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 3: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #1 at period 80 ms
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #2 at period 320 ms
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #3 at period 1280 ms
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #4 at period 5120 ms
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #5 at period 20 sec
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #6 at period 81 sec
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #7 at period 327 sec
+ // CHECK-ESAN: {{.*}} EfficiencySanitizer: the total working set size: 32 MB (5242{{[0-9][0-9]}} cache lines)
+ // CHECK-ESAN-NEXT: all done
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}== Total number of samples: {{[0-9]+}}
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}== Samples array #0 at period 20 ms
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 1: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 2: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 3: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #1 at period 80 ms
+ // CHECK-ESAN-NEXT: =={{[0-9]+}}==# 0: {{[ 0-9]+}} {{KB|MB|Bytes}} ({{[ 0-9]+}} cache lines)
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #2 at period 320 ms
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #3 at period 1280 ms
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #4 at period 5120 ms
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #5 at period 20 sec
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #6 at period 81 sec
+ // CHECK-ESAN: =={{[0-9]+}}== Samples array #7 at period 327 sec
+ // CHECK-ESAN: {{.*}} EfficiencySanitizer: the total working set size: 32 MB (5242{{[0-9][0-9]}} cache lines)
+ return 0;
+}
diff --git a/test/esan/lit.cfg b/test/esan/lit.cfg
index 5f7ba16dc..cf16a6b5d 100644
--- a/test/esan/lit.cfg
+++ b/test/esan/lit.cfg
@@ -23,6 +23,8 @@ unit_cxxflags = (["-I%s" % esan_incdir, "-std=c++11",
def build_invocation(compile_flags):
return " " + " ".join([config.clang] + compile_flags) + " "
+config.substitutions.append( ("%clang ",
+ build_invocation(base_cflags)) )
config.substitutions.append( ("%clang_esan_frag ",
build_invocation(frag_cflags)) )
config.substitutions.append( ("%clang_esan_wset ",