Files
llvm-project/compiler-rt/test/esan/Unit/circular_buffer.cpp
Derek Bruening 07814769a8 [esan] Add sideline itimer support
Summary:
Adds support for creating a separate thread for performing "sideline"
actions on a periodic basis via an itimer.  A new class SidelineThread
implements this feature, exposing a sampling callback to the caller.

Adds initial usage of sideline sampling to the working set tool.  For now
it simply prints the usage at each snapshot at verbosity level 1.  Adds a
test of this behavior.  Adds a new option -record_snapshots to control
whether we sample and a new option -sample_freq to control the periodicity
of the sampling.

Reviewers: aizatsky

Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka

Differential Revision: http://reviews.llvm.org/D20751

llvm-svn: 271682
2016-06-03 16:14:07 +00:00

62 lines
1.4 KiB
C++

// RUN: %clangxx_unit -O0 %s -o %t 2>&1
// RUN: %env_esan_opts="record_snapshots=0" %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;
}