From 0544bfe97b6a530687d9b492221a3dc6b924d98e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 23 Sep 2008 15:04:14 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@438 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- readme.txt | 3 +- test/test.c | 7 +++ test/test.mk | 2 +- test/testdyn.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++ test/testdyn.h | 25 +++++++++ test/testheap.c | 1 - 6 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 test/testdyn.c create mode 100644 test/testdyn.h diff --git a/readme.txt b/readme.txt index 446995854..12ca52795 100644 --- a/readme.txt +++ b/readme.txt @@ -76,7 +76,7 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process, *** 0.7.1 *** - NEW: New chThdInit() and chThdCreateStatic() APIs now replace the old - chThdCreate() and chThdCreateFast() that are marked as deprecated. + chThdCreate() and chThdCreateFast() that are thus marked as deprecated. The new APIs use one less parameter and are faster. - NEW: New dynamic chThdCreateFromHeap() and chthdCreateFromMemoryPool() APIs. The dynamic APIs are only included if the CH_USE_DYNAMIC option is specified @@ -85,6 +85,7 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process, ignored. Note that in this version the API is deprecated and the bug documented as correct behavior. If you need to create a suspended thread please use the new chThdInit() API. +- Added new test cases to the test suite for the new dynamic APIs. *** 0.7.0 *** - NEW: Memory Heap Allocator functionality added. The allocator implements a diff --git a/test/test.c b/test/test.c index 5712f7bb2..fa2625215 100644 --- a/test/test.c +++ b/test/test.c @@ -26,6 +26,7 @@ #include "testmsg.h" #include "testheap.h" #include "testpools.h" +#include "testdyn.h" #include "testbmk.h" /* @@ -47,6 +48,12 @@ static const struct testcase *tests[] = { #endif #ifdef CH_USE_MEMPOOLS &testpools1, +#endif +#if defined(CH_USE_DYNAMIC) && defined(CH_USE_HEAP) + &testdyn1, +#endif +#if defined(CH_USE_DYNAMIC) && defined(CH_USE_MEMPOOLS) + &testdyn2, #endif &testbmk1, &testbmk2, diff --git a/test/test.mk b/test/test.mk index 10b86d4eb..9ea33e412 100644 --- a/test/test.mk +++ b/test/test.mk @@ -1,4 +1,4 @@ # List of all the ChibiOS/RT test files. TESTSRC = ../../test/test.c ../../test/testrdy.c ../../test/testsem.c \ ../../test/testmtx.c ../../test/testmsg.c ../../test/testheap.c \ - ../../test/testpools.c ../../test/testbmk.c + ../../test/testpools.c ../../test/testdyn.c ../../test/testbmk.c diff --git a/test/testdyn.c b/test/testdyn.c new file mode 100644 index 000000000..1f952b6ac --- /dev/null +++ b/test/testdyn.c @@ -0,0 +1,135 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +#include "test.h" + +#ifdef CH_USE_DYNAMIC + +static msg_t thread(void *p) { + + test_emit_token(*(char *)p); + return 0; +} + +#ifdef CH_USE_HEAP +static char *dyn1_gettest(void) { + + return "Dynamic APIs, threads creation from heap"; +} + +static void dyn1_setup(void) { +} + +static void dyn1_teardown(void) { +} + +static void dyn1_execute(void) { + size_t n, sz; + tprio_t prio = chThdGetPriority(); + + /* Test skipped if the heap is already fragmented. */ + if ((n = chHeapStatus(&sz)) == 1) { + /* Starting threads from the heap. */ + threads[0] = chThdCreateFromHeap(UserStackSize(THREADS_STACK_SIZE), + prio-1, thread, "A"); + threads[1] = chThdCreateFromHeap(UserStackSize(THREADS_STACK_SIZE), + prio-2, thread, "B"); + + test_assert((threads[0] != NULL) && + (threads[1] != NULL) && + (threads[2] == NULL) && + (threads[3] == NULL) && + (threads[4] == NULL), + "thread creation failed"); + + /* Claiming the memory from terminated threads. */ + test_wait_threads(); + test_assert_sequence("AB"); + + /* Heap status checked again.*/ + test_assert(chHeapStatus(&n) == 1, "heap fragmented"); + test_assert(n == sz, "heap size changed"); + } +} + +const struct testcase testdyn1 = { + dyn1_gettest, + dyn1_setup, + dyn1_teardown, + dyn1_execute +}; +#endif /* CH_USE_HEAP */ + +#ifdef CH_USE_MEMPOOLS +static MemoryPool mp1; + +static char *dyn2_gettest(void) { + + return "Dynamic APIs, threads creation from memory pool"; +} + +static void dyn2_setup(void) { + + chPoolInit(&mp1, UserStackSize(THREADS_STACK_SIZE)); +} + +static void dyn2_teardown(void) { +} + +static void dyn2_execute(void) { + int i; + tprio_t prio = chThdGetPriority(); + + /* Adding the WAs to the pool. */ + for (i = 0; i < 5; i++) + chPoolFree(&mp1, wa[i]); + + /* Starting threads from the memory pool. */ + threads[0] = chThdCreateFromMemoryPool(&mp1, prio-1, thread, "A"); + threads[1] = chThdCreateFromMemoryPool(&mp1, prio-2, thread, "B"); + threads[2] = chThdCreateFromMemoryPool(&mp1, prio-3, thread, "C"); + threads[3] = chThdCreateFromMemoryPool(&mp1, prio-4, thread, "D"); + threads[4] = chThdCreateFromMemoryPool(&mp1, prio-5, thread, "E"); + + test_assert((threads[0] != NULL) && + (threads[1] != NULL) && + (threads[2] != NULL) && + (threads[3] != NULL) && + (threads[4] != NULL), + "thread creation failed"); + + /* Claiming the memory from terminated threads. */ + test_wait_threads(); + test_assert_sequence("ABCDE"); + + /* Now the pool must be empty again. */ + test_assert(chPoolAlloc(&mp1) == NULL, "pool list not empty"); +} + +const struct testcase testdyn2 = { + dyn2_gettest, + dyn2_setup, + dyn2_teardown, + dyn2_execute +}; +#endif /* CH_USE_MEMPOOLS */ + +#endif /* CH_USE_DYNAMIC */ diff --git a/test/testdyn.h b/test/testdyn.h new file mode 100644 index 000000000..bb2a396bb --- /dev/null +++ b/test/testdyn.h @@ -0,0 +1,25 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _TESTDYN_H_ +#define _TESTDYN_H_ + +extern const struct testcase testdyn1, testdyn2; + +#endif /* _TESTDYN_H_ */ diff --git a/test/testheap.c b/test/testheap.c index 775902dd3..b6468b6be 100644 --- a/test/testheap.c +++ b/test/testheap.c @@ -41,7 +41,6 @@ static void heap1_execute(void) { size_t n, sz; /* Test skipped if the heap is already fragmented. */ - if ((n = chHeapStatus(&sz)) == 1) { test_print("--- Size : "); test_printn(sz);