summaryrefslogtreecommitdiff
path: root/test/esan
diff options
context:
space:
mode:
authorDerek Bruening <bruening@google.com>2016-05-31 14:44:49 +0000
committerDerek Bruening <bruening@google.com>2016-05-31 14:44:49 +0000
commit78b34e592100750ad0c648740eb3c1a06f2721ac (patch)
treeaa43eac98a5ca40d38a7be44b6a3a16fa5eadffd /test/esan
parent53a14668413fab51e500cd3c26eea269e1f09749 (diff)
[esan] Add circular buffer data structure
Summary: Adds a new class, CircularBuffer, for holding a wrap-around fixed-size sequence of a primitive data type. This will be used initially by the working set tool. Adds a unit test for CircularBuffer, including infrastructure support to include esan headers and to link with the esan library by pretending to want the working set tool. Reviewers: aizatsky, filcab Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D20579 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/esan')
-rw-r--r--test/esan/Unit/circular_buffer.cpp61
-rw-r--r--test/esan/lit.cfg6
2 files changed, 67 insertions, 0 deletions
diff --git a/test/esan/Unit/circular_buffer.cpp b/test/esan/Unit/circular_buffer.cpp
new file mode 100644
index 000000000..a788418b7
--- /dev/null
+++ b/test/esan/Unit/circular_buffer.cpp
@@ -0,0 +1,61 @@
+// RUN: %clangxx_unit -O0 %s -o %t 2>&1
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include "esan/esan_circular_buffer.h"
+#include "sanitizer_common/sanitizer_placement_new.h"
+#include <assert.h>
+#include <stdio.h>
+
+static const int TestBufCapacity = 4;
+
+// The buffer should have a capacity of TestBufCapacity.
+void testBuffer(__esan::CircularBuffer<int> *Buf) {
+ assert(Buf->size() == 0);
+ assert(Buf->empty());
+
+ Buf->push_back(1);
+ assert(Buf->back() == 1);
+ assert((*Buf)[0] == 1);
+ assert(Buf->size() == 1);
+ assert(!Buf->empty());
+
+ Buf->push_back(2);
+ Buf->push_back(3);
+ Buf->push_back(4);
+ Buf->push_back(5);
+ assert((*Buf)[0] == 2);
+ assert(Buf->size() == 4);
+
+ Buf->pop_back();
+ assert((*Buf)[0] == 2);
+ assert(Buf->size() == 3);
+
+ Buf->pop_back();
+ Buf->pop_back();
+ assert((*Buf)[0] == 2);
+ assert(Buf->size() == 1);
+ assert(!Buf->empty());
+
+ Buf->pop_back();
+ assert(Buf->empty());
+}
+
+int main()
+{
+ // Test initialize/free.
+ __esan::CircularBuffer<int> GlobalBuf;
+ GlobalBuf.initialize(TestBufCapacity);
+ testBuffer(&GlobalBuf);
+ GlobalBuf.free();
+
+ // Test constructor/free.
+ __esan::CircularBuffer<int> *LocalBuf;
+ static char placeholder[sizeof(*LocalBuf)];
+ LocalBuf = new(placeholder) __esan::CircularBuffer<int>(TestBufCapacity);
+ testBuffer(LocalBuf);
+ LocalBuf->free();
+
+ fprintf(stderr, "All checks passed.\n");
+ // CHECK: All checks passed.
+ return 0;
+}
diff --git a/test/esan/lit.cfg b/test/esan/lit.cfg
index cc7492c88..9eb296d90 100644
--- a/test/esan/lit.cfg
+++ b/test/esan/lit.cfg
@@ -14,6 +14,10 @@ base_cxxflags = config.cxx_mode_flags + base_cflags
frag_cflags = (["-fsanitize=efficiency-cache-frag"] + base_cflags)
wset_cflags = (["-fsanitize=efficiency-working-set"] + base_cflags)
+esan_incdir = config.test_source_root + "/../../lib"
+unit_cxxflags = (["-I%s" % esan_incdir, "-std=c++11",
+ # We need to link with the esan runtime.
+ "-fsanitize=efficiency-working-set"] + base_cxxflags)
def build_invocation(compile_flags):
return " " + " ".join([config.clang] + compile_flags) + " "
@@ -22,6 +26,8 @@ config.substitutions.append( ("%clang_esan_frag ",
build_invocation(frag_cflags)) )
config.substitutions.append( ("%clang_esan_wset ",
build_invocation(wset_cflags)) )
+config.substitutions.append( ("%clangxx_unit",
+ build_invocation(unit_cxxflags)) )
default_esan_opts = ''
config.substitutions.append(('%env_esan_opts=',