Files
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
cmake
docs
include
lib
test
BlocksRuntime
asan
builtins
cfi
dfsan
esan
TestCases
Unit
circular_buffer.cpp
hashtable.cpp
CMakeLists.txt
lit.cfg
lit.site.cfg.in
fuzzer
hwasan
interception
lsan
msan
profile
safestack
sanitizer_common
scudo
tsan
ubsan
ubsan_minimal
xray
CMakeLists.txt
lit.common.cfg
lit.common.configured.in
unittests
www
.arcconfig
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
README.txt
libcxx
libcxxabi
libunwind
lld
lldb
llvm
openmp
polly
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mk
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/llvm-project/compiler-rt/test/esan/Unit/circular_buffer.cpp

62 lines
1.4 KiB
C++
Raw Normal View History

// 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;
}