From 690bd6341c0ede1ff9edc30f8a8ce384fa936008 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Dejan=20Jovanovi=C4=87?= Date: Wed, 3 Feb 2010 00:49:38 +0000 Subject: [PATCH] context_mm testing --- test/unit/context/context_mm_black.h | 30 +++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/test/unit/context/context_mm_black.h b/test/unit/context/context_mm_black.h index 534f490f6..78c5a53ae 100644 --- a/test/unit/context/context_mm_black.h +++ b/test/unit/context/context_mm_black.h @@ -36,24 +36,40 @@ public: void testPushPop() { // Push, then allocate, then pop + // We make sure that we don't allocate too much so that all the regions + // should be reclaimed + int chunkSizeBytes = 16384; + int maxFreeChunks = 100; + int piecesPerChunk = 13; + int len = chunkSizeBytes / piecesPerChunk; // Length of the individual block + int N = maxFreeChunks*piecesPerChunk; for (int p = 0; p < 5; ++ p) { d_cmm->push(); - for (int i = 1; i < 16384/3; ++i) { - int len = i*3; + for (int i = 0; i < N; ++i) { char* newMem = (char*)d_cmm->newData(len); - for(int k = 0; k < len - 1; k ++) - newMem[k] = 'a'; - newMem[len-1] = 0; + // We only setup the memory in the first run, the others should + // reclaim the same memory + if (p == 0) { + for(int k = 0; k < len - 1; k ++) + newMem[k] = 'a'; + newMem[len-1] = 0; + } + if (strlen(newMem) != len - 1) { + cout << strlen(newMem) << " : " << len - 1 << endl; + } TS_ASSERT(strlen(newMem) == len - 1); } d_cmm->pop(); } + int factor = 3; + N = 16384/factor; + // Push, then allocate, then pop all at once for (int p = 0; p < 5; ++ p) { d_cmm->push(); - for (int i = 1; i < 16384/3; ++i) { - int len = i*3; + for (int i = 1; i < N; ++i) { + int len = i*factor; char* newMem = (char*)d_cmm->newData(len); for(int k = 0; k < len - 1; k ++) newMem[k] = 'a'; -- 2.30.2