git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@438 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2008-09-23 15:04:14 +00:00
parent 9a1c91e6ee
commit 0544bfe97b
6 changed files with 170 additions and 3 deletions

View File

@ -76,7 +76,7 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
*** 0.7.1 *** *** 0.7.1 ***
- NEW: New chThdInit() and chThdCreateStatic() APIs now replace the old - 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. The new APIs use one less parameter and are faster.
- NEW: New dynamic chThdCreateFromHeap() and chthdCreateFromMemoryPool() APIs. - NEW: New dynamic chThdCreateFromHeap() and chthdCreateFromMemoryPool() APIs.
The dynamic APIs are only included if the CH_USE_DYNAMIC option is specified 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 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 documented as correct behavior. If you need to create a suspended thread
please use the new chThdInit() API. please use the new chThdInit() API.
- Added new test cases to the test suite for the new dynamic APIs.
*** 0.7.0 *** *** 0.7.0 ***
- NEW: Memory Heap Allocator functionality added. The allocator implements a - NEW: Memory Heap Allocator functionality added. The allocator implements a

View File

@ -26,6 +26,7 @@
#include "testmsg.h" #include "testmsg.h"
#include "testheap.h" #include "testheap.h"
#include "testpools.h" #include "testpools.h"
#include "testdyn.h"
#include "testbmk.h" #include "testbmk.h"
/* /*
@ -47,6 +48,12 @@ static const struct testcase *tests[] = {
#endif #endif
#ifdef CH_USE_MEMPOOLS #ifdef CH_USE_MEMPOOLS
&testpools1, &testpools1,
#endif
#if defined(CH_USE_DYNAMIC) && defined(CH_USE_HEAP)
&testdyn1,
#endif
#if defined(CH_USE_DYNAMIC) && defined(CH_USE_MEMPOOLS)
&testdyn2,
#endif #endif
&testbmk1, &testbmk1,
&testbmk2, &testbmk2,

View File

@ -1,4 +1,4 @@
# List of all the ChibiOS/RT test files. # List of all the ChibiOS/RT test files.
TESTSRC = ../../test/test.c ../../test/testrdy.c ../../test/testsem.c \ TESTSRC = ../../test/test.c ../../test/testrdy.c ../../test/testsem.c \
../../test/testmtx.c ../../test/testmsg.c ../../test/testheap.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

135
test/testdyn.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <ch.h>
#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 */

25
test/testdyn.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef _TESTDYN_H_
#define _TESTDYN_H_
extern const struct testcase testdyn1, testdyn2;
#endif /* _TESTDYN_H_ */

View File

@ -41,7 +41,6 @@ static void heap1_execute(void) {
size_t n, sz; size_t n, sz;
/* Test skipped if the heap is already fragmented. */ /* Test skipped if the heap is already fragmented. */
if ((n = chHeapStatus(&sz)) == 1) { if ((n = chHeapStatus(&sz)) == 1) {
test_print("--- Size : "); test_print("--- Size : ");
test_printn(sz); test_printn(sz);