Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2019-05-10 10:21:10 -0400
committerHenrik Rentz-Reichert2019-05-15 13:30:58 -0400
commit5f88a96768e4e8d6336ad5d329d2049bce644b04 (patch)
treecec0bb1753979340c3b54607936bd6628d027749 /tests
parent877c88575ff8a7665aa78107a2b03d0ce0bbfb07 (diff)
downloadorg.eclipse.etrice-5f88a96768e4e8d6336ad5d329d2049bce644b04.tar.gz
org.eclipse.etrice-5f88a96768e4e8d6336ad5d329d2049bce644b04.tar.xz
org.eclipse.etrice-5f88a96768e4e8d6336ad5d329d2049bce644b04.zip
Bug 546770 - improve and complete memory management
* memory managements hooked into runtime for access to statistics * improved structure and code Change-Id: Id2c0d7d4c77bf5de0753a155d0155738a3195bfe
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c50
1 files changed, 45 insertions, 5 deletions
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c
index a0485936a..ee60fbc8a 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c
+++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c
@@ -39,7 +39,7 @@
static void TestEtMemory_testVariableSize(etInt16 id) {
- etUInt8 buffer[BUF_SIZE];
+ etUInt8* buffer = malloc(BUF_SIZE);
const etUInt16 blockSize = 2 * KBYTE;
const int nBlocks = BUF_SIZE / blockSize;
etMemory* mem = etMemory_VariableSize_init(buffer, BUF_SIZE);
@@ -48,7 +48,7 @@ static void TestEtMemory_testVariableSize(etInt16 id) {
EXPECT_TRUE(id, "mem!=NULL", mem!=NULL);
- /* nBlocks-1 onjects can be allocated */
+ /* nBlocks-1 objects can be allocated */
for (i=1; i<nBlocks; ++i) {
obj = mem->alloc(mem, blockSize);
if (obj==NULL) {
@@ -64,7 +64,7 @@ static void TestEtMemory_testVariableSize(etInt16 id) {
}
static void TestEtMemory_testFixedSize(etInt16 id) {
- etUInt8 buffer[BUF_SIZE];
+ etUInt8* buffer = malloc(BUF_SIZE);
etUInt8* objects[TEST_BLOCKS];
int i;
etMemory* mem = etMemory_FixedSize_init(buffer, BUF_SIZE, BLOCK_SIZE);
@@ -160,7 +160,7 @@ static void checkState(etInt16 id, etMemory* mem, const char* text, etUInt32 act
}
static void TestEtMemory_testFreeList(etInt16 id) {
- static etUInt8 buffer[BUF_SIZE];
+ etUInt8* buffer = malloc(BUF_SIZE);
static etUInt8 sizes[NSIZES] = { SIZE0, SIZE1, SIZE2, SIZE3, SIZE4, SIZE5, SIZE6 };
etUInt8* objects[NSIZES][NOBJ];
etMemory* mem = etMemory_FreeList_init(buffer, BUF_SIZE, NSLOTS);
@@ -202,7 +202,7 @@ static void TestEtMemory_testFreeList(etInt16 id) {
}
static void TestEtMemory_testFreeListOverflow(etInt16 id) {
- static etUInt8 buffer[BUF_SIZE_SMALL];
+ etUInt8* buffer = malloc(BUF_SIZE_SMALL);
etMemory* mem = etMemory_FreeList_init(buffer, BUF_SIZE_SMALL, NSLOTS);
void* obj;
@@ -212,12 +212,52 @@ static void TestEtMemory_testFreeListOverflow(etInt16 id) {
EXPECT_TRUE(id, "insufficient space, expect NULL", NULL==obj);
}
+static void TestEtMemory_testStatistics(etInt16 id) {
+ etMemoryStatistics* stat;
+ int n;
+
+ EXPECT_EQUAL_INT32(id, "tests created some memory managements", 4, etRuntime_getMemoryManagementCount());
+
+ n = 0;
+ stat = etRuntime_getMemoryManagementStatistics(n);
+ EXPECT_TRUE(id, "stat!=NULL", stat!=NULL);
+ printf("checking memory management %d, %s, max %d, fail %d\n", n, etRuntime_getMemoryManagementName(n), stat->maxUsed, stat->nFailingRequests);
+ fflush(stdout);
+ EXPECT_EQUAL_INT32(id, "maxUsed", 0, stat->maxUsed);
+ EXPECT_EQUAL_INT32(id, "nFailingRequests", 1, stat->nFailingRequests);
+
+ n = 1;
+ stat = etRuntime_getMemoryManagementStatistics(n);
+ EXPECT_TRUE(id, "stat!=NULL", stat!=NULL);
+ printf("checking memory management %d, %s, max %d, fail %d\n", n, etRuntime_getMemoryManagementName(n), stat->maxUsed, stat->nFailingRequests);
+ fflush(stdout);
+ EXPECT_EQUAL_INT32(id, "maxUsed", 261784, stat->maxUsed);
+ EXPECT_EQUAL_INT32(id, "nFailingRequests", 0, stat->nFailingRequests);
+
+ n = 2;
+ stat = etRuntime_getMemoryManagementStatistics(n);
+ EXPECT_TRUE(id, "stat!=NULL", stat!=NULL);
+ printf("checking memory management %d, %s, max %d, fail %d\n", n, etRuntime_getMemoryManagementName(n), stat->maxUsed, stat->nFailingRequests);
+ fflush(stdout);
+ EXPECT_EQUAL_INT32(id, "maxUsed", 131144, stat->maxUsed);
+ EXPECT_EQUAL_INT32(id, "nFailingRequests", 0, stat->nFailingRequests);
+
+ n = 3;
+ stat = etRuntime_getMemoryManagementStatistics(n);
+ EXPECT_TRUE(id, "stat!=NULL", stat!=NULL);
+ printf("checking memory management %d, %s, max %d, fail %d\n", n, etRuntime_getMemoryManagementName(n), stat->maxUsed, stat->nFailingRequests);
+ fflush(stdout);
+ EXPECT_EQUAL_INT32(id, "maxUsed", 260016, stat->maxUsed);
+ EXPECT_EQUAL_INT32(id, "nFailingRequests", 1, stat->nFailingRequests);
+}
+
void TestEtMemory_runSuite(void){
etUnit_openTestSuite("org.eclipse.etrice.runtime.c.tests.TestMemory");
ADD_TESTCASE(TestEtMemory_testVariableSize);
ADD_TESTCASE(TestEtMemory_testFixedSize);
ADD_TESTCASE(TestEtMemory_testFreeList);
ADD_TESTCASE(TestEtMemory_testFreeListOverflow);
+ /*ADD_TESTCASE(TestEtMemory_testStatistics);*/
etUnit_closeTestSuite();
}

Back to the top