From a0edacb8011998fd9afca18e12f26dc521267617 Mon Sep 17 00:00:00 2001 From: Henrik Rentz-Reichert Date: Mon, 5 Nov 2012 18:07:44 +0100 Subject: [runtime.c.tests] unit tests for base package --- tests/org.eclipse.etrice.runtime.c.tests/.cproject | 6 +- .../org.eclipse.etrice.runtime.c.tests/.gitignore | 3 +- .../src/runtime/RunCRuntimeTestcases.c | 8 + .../src/runtime/TestEtMemory.c | 184 +++++++++++++++++++++ .../src/runtime/TestEtMemory.h | 21 +++ .../src/runtime/TestEtQueue.c | 69 ++++++++ .../src/runtime/TestEtQueue.h | 21 +++ .../tmp/testlog/TestCRuntime.etu | 44 +++-- .../tmp/testlog/TestEtUnitSpecial.etu | 4 +- 9 files changed, 336 insertions(+), 24 deletions(-) create mode 100644 tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c create mode 100644 tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.h create mode 100644 tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtQueue.c create mode 100644 tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtQueue.h (limited to 'tests/org.eclipse.etrice.runtime.c.tests') diff --git a/tests/org.eclipse.etrice.runtime.c.tests/.cproject b/tests/org.eclipse.etrice.runtime.c.tests/.cproject index f5852fc5f..3588b07fc 100644 --- a/tests/org.eclipse.etrice.runtime.c.tests/.cproject +++ b/tests/org.eclipse.etrice.runtime.c.tests/.cproject @@ -20,7 +20,7 @@ - @@ -35,6 +35,7 @@ @@ -62,7 +63,7 @@ - + @@ -123,4 +124,5 @@ + diff --git a/tests/org.eclipse.etrice.runtime.c.tests/.gitignore b/tests/org.eclipse.etrice.runtime.c.tests/.gitignore index 68a1439f6..641b47de7 100644 --- a/tests/org.eclipse.etrice.runtime.c.tests/.gitignore +++ b/tests/org.eclipse.etrice.runtime.c.tests/.gitignore @@ -2,5 +2,4 @@ Debug Release src-gen/* !src-gen/readme.txt - - +tmp/testlog/*.seq diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c index f4ec67e96..253368937 100644 --- a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c +++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/RunCRuntimeTestcases.c @@ -26,14 +26,20 @@ #include "TestEtMessageQueue.h" #include "TestEtMessageService.h" #include "TestEtUnit.h" +#include "TestEtMemory.h" +#include "TestEtQueue.h" #include "etUnit/etUnit.h" +#include "debugging/etMSCLogger.h" void RunCRuntimeTestcases(void){ etInt16 id; + etMSCLogger_open("tmp/testlog", "test.log"); etUnit_open("tmp/testlog","TestCRuntime"); + TestEtQueue_runSuite(); + TestEtMemory_runSuite(); TestEtMessage_runSuite(); TestEtMessageQueue_runSuite(); TestEtMessageService_runSuite(); @@ -46,5 +52,7 @@ void RunCRuntimeTestcases(void){ id = etUnit_openAll("tmp/testlog","TestEtUnitSpecial", "etUnit", "openAll and closeAll"); EXPECT_TRUE(id, "Open and Close", TRUE); etUnit_closeAll(id); + + etMSCLogger_close(); } 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 new file mode 100644 index 000000000..da970c6fa --- /dev/null +++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.c @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2012 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +#include "TestEtMemory.h" + +#include +#include +#include "etUnit/etUnit.h" +#include "base/etMemory_FixedSize.h" +#include "base/etMemory_FreeList.h" + +#define BUF_SIZE (256*1024) +#define BLOCK_SIZE 128 +#define TEST_BLOCKS 1024 +#define TEST_BLOCK_SIZE 64 + +#define NOBJ 32 +#define NSLOTS 8 +#define SIZE0 64 +#define SIZE1 16 +#define SIZE2 32 +#define SIZE3 48 +#define SIZE4 (16*8) +#define SIZE5 112 +#define SIZE6 96 + + +static void TestEtMemory_testFixedSize(etInt16 id) { + etUInt8 buffer[BUF_SIZE]; + etUInt8* objects[TEST_BLOCKS]; + int i; + etMemory* mem = etMemory_FixedSize_init(buffer, BUF_SIZE, BLOCK_SIZE); + EXPECT_TRUE(id, "mem!=NULL", mem!=NULL); + + for (i=0; ialloc(mem, TEST_BLOCK_SIZE); + if (objects[i]==NULL) + EXPECT_TRUE(id, "objects[i]==NULL", FALSE); + + memset(objects[i], i%4, TEST_BLOCK_SIZE); + } + for (i=0; ifree(mem, objects[i*2], TEST_BLOCK_SIZE); + } + for (i=0; ialloc(mem, TEST_BLOCK_SIZE); + if (objects[i*2]==NULL) + EXPECT_TRUE(id, "objects[i*2]==NULL", FALSE); + } +} + +static void local_alloc(etInt16 id, etMemory* mem, etUInt8* objects[7][NOBJ], etUInt8 sizes[7]) { + int i; +#define KIND 0 + for (i=0; ialloc(mem, sizes[KIND]); + if (objects[KIND][i]==NULL) + EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE); + } + +#undef KIND +#define KIND 1 + for (i=0; ialloc(mem, sizes[KIND]); + if (objects[KIND][i]==NULL) + EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE); + } + +#undef KIND +#define KIND 2 + for (i=0; ialloc(mem, sizes[KIND]); + if (objects[KIND][i]==NULL) + EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE); + } + +#undef KIND +#define KIND 3 + for (i=0; ialloc(mem, sizes[KIND]); + if (objects[KIND][i]==NULL) + EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE); + } + +#undef KIND +#define KIND 4 + for (i=0; ialloc(mem, sizes[KIND]); + if (objects[KIND][i]==NULL) + EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE); + } + +#undef KIND +#define KIND 5 + for (i=0; ialloc(mem, sizes[KIND]); + if (objects[KIND][i]==NULL) + EXPECT_TRUE(id, "objects[KIND][i]==NULL", FALSE); + } + +#undef KIND +#define KIND 6 + for (i=0; ialloc(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; ifree(mem, objects[KIND][i], sizes[KIND]); + } + +#undef KIND +#define KIND 1 + for (i=0; ifree(mem, objects[KIND][i], sizes[KIND]); + } + +#undef KIND +#define KIND 2 + for (i=0; ifree(mem, objects[KIND][i], sizes[KIND]); + } + +#undef KIND +#define KIND 3 + for (i=0; ifree(mem, objects[KIND][i], sizes[KIND]); + } + +#undef KIND +#define KIND 4 + for (i=0; ifree(mem, objects[KIND][i], sizes[KIND]); + } + +#undef KIND +#define KIND 5 + for (i=0; ifree(mem, objects[KIND][i], sizes[KIND]); + } + +#undef KIND +#define KIND 6 + for (i=0; ifree(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]; + 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); + local_alloc(id, mem, objects, sizes); + local_free(id, mem, objects, sizes); +} + +void TestEtMemory_runSuite(void){ + etUnit_openTestSuite("TestMemory"); + ADD_TESTCASE(TestEtMemory_testFixedSize); + ADD_TESTCASE(TestEtMemory_testFreeList); + etUnit_closeTestSuite(); +} + diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.h b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.h new file mode 100644 index 000000000..107c6a504 --- /dev/null +++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtMemory.h @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2012 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +#ifndef _TEST_MEMORY_H_ +#define _TEST_MEMORY_H_ + +#include "base/etMemory.h" + +void TestEtMemory_runSuite(void); + + +#endif /* _TEST_MEMORY_H_ */ diff --git a/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtQueue.c b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtQueue.c new file mode 100644 index 000000000..8479ac93f --- /dev/null +++ b/tests/org.eclipse.etrice.runtime.c.tests/src/runtime/TestEtQueue.c @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2012 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +#include "TestEtQueue.h" + +#include +#include "etUnit/etUnit.h" +#include "base/etQueue.h" + +#define MAX 1000 + +typedef struct etTestObject { + etQueueObj base; + etInt16 a; + etInt16 b; +} etTestObject; + +static void TestEtQueue_test(etInt16 id){ + etTestObject objects[MAX]; + int16 i; + + etQueue queue; + etQueue_init(&queue); + + for(i=0; i