8#ifndef INCLUDED_BSLMA_TESTALLOCATOR
9#define INCLUDED_BSLMA_TESTALLOCATOR
339#include <bslscm_version.h>
353# pragma bde_verify -AQK01
360struct TestAllocator_BlockHeader;
390 k_INT64_MAXDIGITS = 20,
391 k_LABLETEXT_LEN = 51,
392 k_NUM_STATLINES = 11,
394 k_NUM_STATLINES * (k_LABLETEXT_LEN + 2 * k_INT64_MAXDIGITS) + 1,
398 k_BLOCKID_LINE_SZ = 8 * (k_INT64_MAXDIGITS + 1) + 1 + 1
405 const char *d_name_p;
479 d_lastAllocatedNumBytes;
483 d_lastDeallocatedNumBytes;
488 d_lastAllocatedAddress_p;
492 d_lastDeallocatedAddress_p;
498 TestAllocator_BlockHeader
501 TestAllocator_BlockHeader
523 formatEightBlockIds(
const TestAllocator_BlockHeader** blockList,
524 char* output )
const;
531 std::size_t formatStats(
char *output)
const;
537 template <
class t_OS>
538 t_OS& printToStream(t_OS& stream)
const;
688 const
char *
name() const;
748#ifndef BDE_OPENSOURCE_PUBLICATION
804 template <
class t_OS>
806 {
return ta.printToStream(stream); }
815#ifdef BDE_BUILD_TARGET_EXC
825class TestAllocator_ProxyBase {
829 virtual ~TestAllocator_ProxyBase()
843template <
class BSLMA_ALLOC_TYPE>
844class TestAllocator_Proxy :
public TestAllocator_ProxyBase {
847 BSLMA_ALLOC_TYPE *d_allocator_p;
852 explicit TestAllocator_Proxy(BSLMA_ALLOC_TYPE *allocator)
853 : d_allocator_p(allocator)
865 d_allocator_p->setAllocationLimit(limit);
871template <
class BSLMA_ALLOC_TYPE>
873TestAllocator_Proxy<BSLMA_ALLOC_TYPE>
874TestAllocator_getProxy(BSLMA_ALLOC_TYPE *allocator)
876 return TestAllocator_Proxy<BSLMA_ALLOC_TYPE>(allocator);
881#ifndef BSLMA_TESTALLOCATOR_EXCEPTION_TEST_BEGIN
887#define BSLMA_TESTALLOCATOR_EXCEPTION_TEST_BEGIN(BSLMA_TESTALLOCATOR) { \
889 static int firstTime = 1; \
890 if (veryVerbose && firstTime) { \
891 std::puts("\t\tBSLMA EXCEPTION TEST -- (ENABLED) --"); \
895 if (veryVeryVerbose) { \
896 std::puts("\t\tBegin bslma exception test."); \
898 int bslmaExceptionCounter = 0; \
899 const BloombergLP::bslma::TestAllocator_ProxyBase& \
900 bslmaExceptionTestAllocator = \
901 BloombergLP::bslma::TestAllocator_getProxy(&BSLMA_TESTALLOCATOR); \
902 bslmaExceptionTestAllocator.setAllocationLimit(bslmaExceptionCounter); \
903 bool bslmaKeepLoopingInTestAllocatorExceptionTest = true; \
904 while(bslmaKeepLoopingInTestAllocatorExceptionTest) { \
905 bslmaKeepLoopingInTestAllocatorExceptionTest = false; \
911#ifndef BSLMA_TESTALLOCATOR_EXCEPTION_TEST_BEGIN
912#define BSLMA_TESTALLOCATOR_EXCEPTION_TEST_BEGIN(BSLMA_TESTALLOCATOR) \
914 static int firstTime = 1; \
915 if (verbose && firstTime) { \
916 std::puts("\t\tBSLMA EXCEPTION TEST -- (NOT ENABLED) --"); \
928#ifdef BDE_BUILD_TARGET_EXC
930#ifndef BSLMA_TESTALLOCATOR_EXCEPTION_TEST_END
931#define BSLMA_TESTALLOCATOR_EXCEPTION_TEST_END \
932 } catch (BloombergLP::bslma::TestAllocatorException& e) { \
933 if (veryVeryVerbose) { \
934 std::printf("\t*** BSLMA_EXCEPTION: " \
935 "alloc limit = %d, last alloc size = %d ***\n", \
936 bslmaExceptionCounter, \
937 static_cast<int>(e.numBytes())); \
939 bslmaExceptionTestAllocator.setAllocationLimit( \
940 ++bslmaExceptionCounter); \
941 bslmaKeepLoopingInTestAllocatorExceptionTest = true; \
944 bslmaExceptionTestAllocator.setAllocationLimit(-1); \
945 if (veryVeryVerbose) { \
946 std::puts("\t\tEnd bslma exception test."); \
954#ifndef BSLMA_TESTALLOCATOR_EXCEPTION_TEST_END
955#define BSLMA_TESTALLOCATOR_EXCEPTION_TEST_END
972t_OS& TestAllocator::printToStream(t_OS& stream)
const
976 char buffer[k_PRINTED_STATS_SZ];
977 std::size_t cnt = formatStats(buffer);
978 stream.write(buffer, cnt);
980 static const char k_ID_STR[] =
981 " Indices of Outstanding Memory Allocations:\n";
982 static const std::size_t k_ID_STR_LEN =
sizeof(k_ID_STR) - 1;
984 if (d_blockListHead_p) {
985 stream.write(k_ID_STR, k_ID_STR_LEN);
989 const TestAllocator_BlockHeader *next_p = d_blockListHead_p;
991 cnt = formatEightBlockIds(&next_p, buffer);
992 stream.write(buffer, cnt);
1053 return reinterpret_cast<void *
>(d_lastAllocatedAddress_p.
loadRelaxed());
1065 return reinterpret_cast<void *
>(d_lastDeallocatedAddress_p.
loadRelaxed());
1140#ifndef BDE_OPENSOURCE_PUBLICATION
1183#ifndef BDE_OPENSOURCE_PUBLICATION
1194#ifndef BEGIN_BSLMA_EXCEPTION_TEST
1195#define BEGIN_BSLMA_EXCEPTION_TEST \
1196 BSLMA_TESTALLOCATOR_EXCEPTION_TEST_BEGIN(testAllocator)
1199#ifndef END_BSLMA_EXCEPTION_TEST
1200#define END_BSLMA_EXCEPTION_TEST BSLMA_TESTALLOCATOR_EXCEPTION_TEST_END
Definition bslma_allocator.h:457
std::size_t size_type
Definition bslma_allocator.h:499
Definition bslma_testallocator.h:384
TestAllocator(const char *name, Allocator *basicAllocator=0)
void deallocate(void *address) BSLS_KEYWORD_OVERRIDE
TestAllocator(Allocator *basicAllocator=0)
void setAllocationLimit(bsls::Types::Int64 limit)
Definition bslma_testallocator.h:1002
bsls::Types::Int64 numAllocation() const
Definition bslma_testallocator.h:1168
bsls::Types::Int64 numDeallocations() const
Definition bslma_testallocator.h:1129
bsls::Types::Int64 numBlocksInUse() const
Definition bslma_testallocator.h:1087
bsls::Types::Int64 numDeallocation() const
Definition bslma_testallocator.h:1174
bsls::Types::Int64 numBlocksMax() const
Definition bslma_testallocator.h:1093
void * lastAllocatedAddress() const
Definition bslma_testallocator.h:1051
void print(std::FILE *f=stdout) const
bsls::Types::Int64 allocationLimit() const
Definition bslma_testallocator.h:1027
size_type lastAllocatedNumBytes() const
Return the number of bytes of the most recent allocation request.
Definition bslma_testallocator.h:1057
bsls::Types::Int64 numBytesInUse() const
Definition bslma_testallocator.h:1111
bool isNoAbort() const
Definition bslma_testallocator.h:1033
TestAllocator(const char *name, bool verboseFlag, Allocator *basicAllocator=0)
size_type lastDeallocatedNumBytes() const
Definition bslma_testallocator.h:1069
~TestAllocator() BSLS_KEYWORD_OVERRIDE
bsls::Types::Int64 numBlocksTotal() const
Definition bslma_testallocator.h:1099
bsls::Types::Int64 numBytesTotal() const
Definition bslma_testallocator.h:1123
void * lastAllocateAddress() const
Definition bslma_testallocator.h:1142
friend t_OS & operator<<(t_OS &stream, const TestAllocator &ta)
Definition bslma_testallocator.h:805
size_type lastDeallocateNumBytes() const
Definition bslma_testallocator.h:1162
void setQuiet(bool flagValue)
Definition bslma_testallocator.h:1014
bsls::Types::Int64 numMismatches() const
Definition bslma_testallocator.h:1135
bool isQuiet() const
Definition bslma_testallocator.h:1039
void * lastDeallocatedAddress() const
Definition bslma_testallocator.h:1063
void * allocate(size_type size) BSLS_KEYWORD_OVERRIDE
TestAllocator(bool verboseFlag, Allocator *basicAllocator=0)
void setNoAbort(bool flagValue)
Definition bslma_testallocator.h:1008
void setVerbose(bool flagValue)
Definition bslma_testallocator.h:1020
bsls::Types::Int64 numBoundsErrors() const
Definition bslma_testallocator.h:1105
size_type lastAllocateNumBytes() const
Definition bslma_testallocator.h:1149
void * lastDeallocateAddress() const
Definition bslma_testallocator.h:1155
const char * name() const
Definition bslma_testallocator.h:1075
bsls::Types::Int64 numAllocations() const
Definition bslma_testallocator.h:1081
bool isVerbose() const
Definition bslma_testallocator.h:1045
bsls::Types::Int64 numBytesMax() const
Definition bslma_testallocator.h:1117
Definition bsls_atomic.h:892
Types::Int64 loadRelaxed() const
Definition bsls_atomic.h:1914
void storeRelaxed(Types::Int64 value)
Definition bsls_atomic.h:1833
Definition bsls_atomic.h:743
int loadRelaxed() const
Definition bsls_atomic.h:1738
void storeRelaxed(int value)
Definition bsls_atomic.h:1660
Definition bsls_atomic.h:1349
TYPE * loadRelaxed() const
Definition bsls_atomic.h:2402
Definition bsls_bsllock.h:227
Definition bsls_bsllock.h:175
bslma::TestAllocator bslma_TestAllocator
This alias is defined for backward compatibility.
Definition bslma_testallocator.h:1189
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition balxml_encoderoptions.h:68
Definition bdlt_iso8601util.h:691
Definition bdldfp_decimal.h:5188
long long Int64
Definition bsls_types.h:132