Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-11-06 05:10:51 -0500
committerHenrik Rentz-Reichert2012-11-06 05:10:51 -0500
commit8f87e455a51de78a843cc74dc128279413d2ed8f (patch)
treeb9decc671bff226f8c256042ba850b1c09e20997
parenta0edacb8011998fd9afca18e12f26dc521267617 (diff)
downloadorg.eclipse.etrice-8f87e455a51de78a843cc74dc128279413d2ed8f.tar.gz
org.eclipse.etrice-8f87e455a51de78a843cc74dc128279413d2ed8f.tar.xz
org.eclipse.etrice-8f87e455a51de78a843cc74dc128279413d2ed8f.zip
[runtime.c] improved test depth of free lists
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c48
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h5
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c153
-rw-r--r--tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu8
4 files changed, 113 insertions, 101 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c
index 5281ec46e..4f23cb7bc 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c
@@ -15,6 +15,7 @@
#include "debugging/etMSCLogger.h"
#define UNUSED_LIST 0
+#define DEBUG_FREE_LISTS 1
typedef struct etFreeListObj {
struct etFreeListObj* next;
@@ -26,6 +27,11 @@ typedef struct etFreeListInfo {
/** the list head */
etFreeListObj* head;
+
+#if DEBUG_FREE_LISTS
+ etUInt16 nobjects;
+#endif
+
} etFreeListInfo;
typedef struct etFreeListMemory {
@@ -72,6 +78,9 @@ static void* etMemory_getFreeListMem(etFreeListMemory* self, etUInt16 size) {
etFreeListObj* obj = self->freelists[slot].head;
self->freelists[slot].head = obj->next;
mem = (void *) obj;
+#if DEBUG_FREE_LISTS
+ --self->freelists[slot].nobjects;
+#endif
}
break;
}
@@ -95,6 +104,9 @@ static void etMemory_putFreeListMem(etFreeListMemory* self, void* obj, etUInt16
/* we insert the object as new head */
((etFreeListObj*)obj)->next = self->freelists[slot].head;
self->freelists[slot].head = (etFreeListObj*)obj;
+#if DEBUG_FREE_LISTS
+ ++self->freelists[slot].nobjects;
+#endif
break;
}
else if (slot_size == UNUSED_LIST) {
@@ -102,6 +114,9 @@ static void etMemory_putFreeListMem(etFreeListMemory* self, void* obj, etUInt16
self->freelists[slot].objsize = size;
((etFreeListObj*)obj)->next = NULL;
self->freelists[slot].head = (etFreeListObj*)obj;
+#if DEBUG_FREE_LISTS
+ self->freelists[slot].nobjects = 1;
+#endif
break;
}
}
@@ -157,3 +172,36 @@ etMemory* etMemory_FreeList_init(void* heap, etUInt32 size, etUInt16 nslots) {
return &self->base;
}
+
+etUInt32 etMemory_FreeList_freeHeapMem(void* heap) {
+ etFreeListMemory* self = (etFreeListMemory*) heap;
+ return ((etUInt8*)self)+self->base.size - self->current;
+}
+
+etUInt16 etMemory_FreeList_freeSlots(void* heap) {
+ etFreeListMemory* self = (etFreeListMemory*) heap;
+ etUInt16 free = 0;
+ int slot;
+
+ for (slot=0; slot<self->nslots; ++slot)
+ if (self->freelists[slot].objsize==UNUSED_LIST)
+ ++free;
+
+ return free;
+}
+
+etUInt16 etMemory_FreeList_nObjects(void* heap, etUInt16 slot) {
+#if DEBUG_FREE_LISTS
+ etFreeListMemory* self = (etFreeListMemory*) heap;
+ if (slot<self->nslots)
+ return self->freelists[slot].nobjects;
+#endif
+ return 0;
+}
+
+etUInt16 etMemory_FreeList_sizeObjects(void* heap, etUInt16 slot) {
+ etFreeListMemory* self = (etFreeListMemory*) heap;
+ if (slot<self->nslots)
+ return self->freelists[slot].objsize;
+ return 0;
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h
index a9c018b72..fcf19d37e 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.h
@@ -26,4 +26,9 @@
*/
etMemory* etMemory_FreeList_init(void* heap, etUInt32 size, etUInt16 nslots);
+etUInt32 etMemory_FreeList_freeHeapMem(void* heap);
+etUInt16 etMemory_FreeList_nObjects(void* heap, etUInt16 slot);
+etUInt16 etMemory_FreeList_sizeObjects(void* heap, etUInt16 slot);
+etUInt16 etMemory_FreeList_freeSlots(void* heap);
+
#endif /* _ETMEMORY_FREE_LIST_H_ */
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 da970c6fa..636dbed84 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
@@ -25,6 +25,7 @@
#define NOBJ 32
#define NSLOTS 8
+#define NSIZES 7
#define SIZE0 64
#define SIZE1 16
#define SIZE2 32
@@ -58,121 +59,79 @@ static void TestEtMemory_testFixedSize(etInt16 id) {
}
}
-static void local_alloc(etInt16 id, etMemory* mem, etUInt8* objects[7][NOBJ], etUInt8 sizes[7]) {
- int i;
-#define KIND 0
- for (i=0; i<NOBJ; ++i) {
- objects[KIND][i] = mem->alloc(mem, sizes[KIND]);
- if (objects[KIND][i]==NULL)
- EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE);
- }
-
-#undef KIND
-#define KIND 1
- for (i=0; i<NOBJ; ++i) {
- objects[KIND][i] = mem->alloc(mem, sizes[KIND]);
- if (objects[KIND][i]==NULL)
- EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE);
- }
-
-#undef KIND
-#define KIND 2
- for (i=0; i<NOBJ; ++i) {
- objects[KIND][i] = mem->alloc(mem, sizes[KIND]);
- if (objects[KIND][i]==NULL)
- EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE);
- }
-
-#undef KIND
-#define KIND 3
- for (i=0; i<NOBJ; ++i) {
- objects[KIND][i] = mem->alloc(mem, sizes[KIND]);
- if (objects[KIND][i]==NULL)
- EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE);
- }
-
-#undef KIND
-#define KIND 4
- for (i=0; i<NOBJ; ++i) {
- objects[KIND][i] = mem->alloc(mem, sizes[KIND]);
- if (objects[KIND][i]==NULL)
- EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE);
- }
+static void local_alloc(etInt16 id, etMemory* mem, etUInt8* objects[NSIZES][NOBJ], etUInt8 sizes[NSIZES]) {
+ int i, kind;
-#undef KIND
-#define KIND 5
- for (i=0; i<NOBJ; ++i) {
- objects[KIND][i] = mem->alloc(mem, sizes[KIND]);
- if (objects[KIND][i]==NULL)
- EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE);
- }
-
-#undef KIND
-#define KIND 6
- for (i=0; i<NOBJ; ++i) {
- objects[KIND][i] = mem->alloc(mem, sizes[KIND]);
- if (objects[KIND][i]==NULL)
- EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE);
+ for (kind=0; kind<=6; ++kind) {
+ for (i=0; i<NOBJ; ++i) {
+ objects[kind][i] = mem->alloc(mem, sizes[kind]);
+ if (objects[kind][i]==NULL)
+ EXPECT_TRUE(id, "objects[kind][i]==NULL", FALSE);
+ }
}
}
-static void local_free(etInt16 id, etMemory* mem, etUInt8* objects[7][NOBJ], etUInt8 sizes[7]) {
- int i;
-#undef KIND
-#define KIND 0
- for (i=0; i<NOBJ; ++i) {
- mem->free(mem, objects[KIND][i], sizes[KIND]);
- }
+static void local_free(etInt16 id, etMemory* mem, etUInt8* objects[NSIZES][NOBJ], etUInt8 sizes[NSIZES]) {
+ int i, kind;
-#undef KIND
-#define KIND 1
- for (i=0; i<NOBJ; ++i) {
- mem->free(mem, objects[KIND][i], sizes[KIND]);
- }
-
-#undef KIND
-#define KIND 2
- for (i=0; i<NOBJ; ++i) {
- mem->free(mem, objects[KIND][i], sizes[KIND]);
- }
-
-#undef KIND
-#define KIND 3
- for (i=0; i<NOBJ; ++i) {
- mem->free(mem, objects[KIND][i], sizes[KIND]);
- }
-
-#undef KIND
-#define KIND 4
- for (i=0; i<NOBJ; ++i) {
- mem->free(mem, objects[KIND][i], sizes[KIND]);
- }
-
-#undef KIND
-#define KIND 5
- for (i=0; i<NOBJ; ++i) {
- mem->free(mem, objects[KIND][i], sizes[KIND]);
- }
-
-#undef KIND
-#define KIND 6
- for (i=0; i<NOBJ; ++i) {
- mem->free(mem, objects[KIND][i], sizes[KIND]);
+ for (kind=0; kind<=6; ++kind) {
+ for (i=0; i<NOBJ; ++i) {
+ mem->free(mem, objects[kind][i], sizes[kind]);
+ }
}
}
static void TestEtMemory_testFreeList(etInt16 id) {
static etUInt8 buffer[BUF_SIZE];
- static etUInt8 sizes[7] = { SIZE0, SIZE1, SIZE2, SIZE3, SIZE4, SIZE5, SIZE6 };
- etUInt8* objects[7][NOBJ];
+ static etUInt8 sizes[NSIZES] = { SIZE0, SIZE1, SIZE2, SIZE3, SIZE4, SIZE5, SIZE6 };
+ etUInt8* objects[NSIZES][NOBJ];
etMemory* mem = etMemory_FreeList_init(buffer, BUF_SIZE, NSLOTS);
EXPECT_TRUE(id, "mem!=NULL", mem!=NULL);
local_alloc(id, mem, objects, sizes);
local_free(id, mem, objects, sizes);
+
+ EXPECT_EQUAL_UINT32(id, "free heap memory", 246212, etMemory_FreeList_freeHeapMem(mem));
+
+ EXPECT_EQUAL_UINT16(id, "free slots", NSLOTS-NSIZES, etMemory_FreeList_freeSlots(mem));
+
+ EXPECT_EQUAL_UINT16(id, "slot 0 size", SIZE0, etMemory_FreeList_sizeObjects(mem, 0));
+ EXPECT_EQUAL_UINT16(id, "slot 0 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 0));
+ EXPECT_EQUAL_UINT16(id, "slot 1 size", SIZE2, etMemory_FreeList_sizeObjects(mem, 1));
+ EXPECT_EQUAL_UINT16(id, "slot 1 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 1));
+ EXPECT_EQUAL_UINT16(id, "slot 2 size", SIZE4, etMemory_FreeList_sizeObjects(mem, 2));
+ EXPECT_EQUAL_UINT16(id, "slot 2 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 2));
+ EXPECT_EQUAL_UINT16(id, "slot 3 size", SIZE6, etMemory_FreeList_sizeObjects(mem, 3));
+ EXPECT_EQUAL_UINT16(id, "slot 3 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 3));
+ EXPECT_EQUAL_UINT16(id, "slot 4 size", SIZE1, etMemory_FreeList_sizeObjects(mem, 4));
+ EXPECT_EQUAL_UINT16(id, "slot 4 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 4));
+ EXPECT_EQUAL_UINT16(id, "slot 5 size", SIZE3, etMemory_FreeList_sizeObjects(mem, 5));
+ EXPECT_EQUAL_UINT16(id, "slot 5 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 5));
+ EXPECT_EQUAL_UINT16(id, "slot 6 size", SIZE5, etMemory_FreeList_sizeObjects(mem, 6));
+ EXPECT_EQUAL_UINT16(id, "slot 6 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 6));
+
local_alloc(id, mem, objects, sizes);
local_free(id, mem, objects, sizes);
+
+ EXPECT_EQUAL_UINT32(id, "free heap memory", 246212, etMemory_FreeList_freeHeapMem(mem));
+
+ EXPECT_EQUAL_UINT16(id, "free slots", NSLOTS-NSIZES, etMemory_FreeList_freeSlots(mem));
+
+ EXPECT_EQUAL_UINT16(id, "slot 0 size", SIZE0, etMemory_FreeList_sizeObjects(mem, 0));
+ EXPECT_EQUAL_UINT16(id, "slot 0 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 0));
+ EXPECT_EQUAL_UINT16(id, "slot 1 size", SIZE2, etMemory_FreeList_sizeObjects(mem, 1));
+ EXPECT_EQUAL_UINT16(id, "slot 1 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 1));
+ EXPECT_EQUAL_UINT16(id, "slot 2 size", SIZE4, etMemory_FreeList_sizeObjects(mem, 2));
+ EXPECT_EQUAL_UINT16(id, "slot 2 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 2));
+ EXPECT_EQUAL_UINT16(id, "slot 3 size", SIZE6, etMemory_FreeList_sizeObjects(mem, 3));
+ EXPECT_EQUAL_UINT16(id, "slot 3 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 3));
+ EXPECT_EQUAL_UINT16(id, "slot 4 size", SIZE1, etMemory_FreeList_sizeObjects(mem, 4));
+ EXPECT_EQUAL_UINT16(id, "slot 4 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 4));
+ EXPECT_EQUAL_UINT16(id, "slot 5 size", SIZE3, etMemory_FreeList_sizeObjects(mem, 5));
+ EXPECT_EQUAL_UINT16(id, "slot 5 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 5));
+ EXPECT_EQUAL_UINT16(id, "slot 6 size", SIZE5, etMemory_FreeList_sizeObjects(mem, 6));
+ EXPECT_EQUAL_UINT16(id, "slot 6 nobj", NOBJ, etMemory_FreeList_nObjects(mem, 6));
}
void TestEtMemory_runSuite(void){
diff --git a/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu b/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu
index 7d9ae7f3f..332bc249c 100644
--- a/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu
+++ b/tests/org.eclipse.etrice.runtime.c.tests/tmp/testlog/TestCRuntime.etu
@@ -1,12 +1,12 @@
etUnit report
ts start: TestQueue
tc start 1: TestEtQueue_test
-tc end 1: 10
+tc end 1: 0
ts start: TestMemory
tc start 2: TestEtMemory_testFixedSize
-tc end 2: 20
+tc end 2: 15
tc start 3: TestEtMemory_testFreeList
-tc end 3: 89830
+tc end 3: 0
ts start: TestMessage
tc start 4: TestEtMessage_testBasicMessage
tc end 4: 0
@@ -14,7 +14,7 @@ ts start: TestEtMessageQueue
tc start 5: TestEtMessageQueue_testPushPop
tc end 5: 0
tc start 6: TestEtMessageQueue_testMassiveMessaging
-tc end 6: 15
+tc end 6: 16
ts start: TestEtMessageService
tc start 7: TestEtMessageService_init
tc end 7: 0

Back to the top