summaryrefslogtreecommitdiff
path: root/test/esan
diff options
context:
space:
mode:
authorDerek Bruening <bruening@google.com>2016-07-19 05:06:48 +0000
committerDerek Bruening <bruening@google.com>2016-07-19 05:06:48 +0000
commit818c1248e0128d9058e997db8a9003270fbf80c7 (patch)
tree8c0d69bc8cd201d6b9802f3def4080dc99004d99 /test/esan
parent189001e3bc9f050781628eba7da36f90725b04ba (diff)
[esan|wset] Fix flaky sampling tests
Adds a new esan public interface routine __esan_get_sample_count() and uses it to ensure that tests of sampling receive the minimum number of samples. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@275948 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/esan')
-rw-r--r--test/esan/TestCases/workingset-midreport.cpp18
-rw-r--r--test/esan/TestCases/workingset-samples.cpp19
2 files changed, 19 insertions, 18 deletions
diff --git a/test/esan/TestCases/workingset-midreport.cpp b/test/esan/TestCases/workingset-midreport.cpp
index 470e33ca3..2c29cf48c 100644
--- a/test/esan/TestCases/workingset-midreport.cpp
+++ b/test/esan/TestCases/workingset-midreport.cpp
@@ -17,15 +17,15 @@ 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();
+ // To avoid flakiness stemming from whether the sideline thread
+ // is scheduled enough on a loaded test machine, we coordinate
+ // with esan itself:
+ if (__esan_get_sample_count) {
+ while (__esan_get_sample_count() < 4) {
+ for (int i = 0; i < size; ++i)
+ buf[i] = i;
+ sched_yield();
+ }
}
// Ensure a non-esan build works without ifdefs:
if (__esan_report) {
diff --git a/test/esan/TestCases/workingset-samples.cpp b/test/esan/TestCases/workingset-samples.cpp
index 09efcd44f..cf198d2f3 100644
--- a/test/esan/TestCases/workingset-samples.cpp
+++ b/test/esan/TestCases/workingset-samples.cpp
@@ -1,6 +1,7 @@
// RUN: %clang_esan_wset -O0 %s -o %t 2>&1
// RUN: %run %t 2>&1 | FileCheck %s
+#include <sanitizer/esan_interface.h>
#include <sched.h>
#include <stdlib.h>
#include <string.h>
@@ -12,15 +13,15 @@ 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();
+ // To avoid flakiness stemming from whether the sideline thread
+ // is scheduled enough on a loaded test machine, we coordinate
+ // with esan itself:
+ if (__esan_get_sample_count) {
+ while (__esan_get_sample_count() < 4) {
+ for (int i = 0; i < size; ++i)
+ buf[i] = i;
+ sched_yield();
+ }
}
munmap(buf, size);
// We only check for a few samples here to reduce the chance of flakiness.