aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-05-04 12:31:05 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-05-04 12:31:05 +0000
commitbc9d319ddb279f973404c2b1abf15ec1091bd891 (patch)
tree1d66cd2898724e9e582332da57f8d863ad8b11a7 /test
parent0074052e3f64b2166258f2d117faf8acdf5d4566 (diff)
downloadChibiOS-bc9d319ddb279f973404c2b1abf15ec1091bd891.tar.gz
ChibiOS-bc9d319ddb279f973404c2b1abf15ec1091bd891.tar.bz2
ChibiOS-bc9d319ddb279f973404c2b1abf15ec1091bd891.zip
Improved code coverage.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1902 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test')
-rw-r--r--test/testdyn.c75
-rw-r--r--test/testheap.c3
-rw-r--r--test/testpools.c9
3 files changed, 87 insertions, 0 deletions
diff --git a/test/testdyn.c b/test/testdyn.c
index 2d05f346b..dcd2d951e 100644
--- a/test/testdyn.c
+++ b/test/testdyn.c
@@ -44,6 +44,7 @@
* <h2>Test Cases</h2>
* - @subpage test_dynamic_001
* - @subpage test_dynamic_002
+ * - @subpage test_dynamic_003
* .
* @file testdyn.c
* @brief Dynamic thread APIs test source file
@@ -189,6 +190,77 @@ const struct testcase testdyn2 = {
};
#endif /* CH_USE_MEMPOOLS */
+#if CH_USE_HEAP
+/**
+ * @page test_dynamic_003 Registry and References test
+ *
+ * <h2>Description</h2>
+ * Registry and Thread References APIs are tested for functionality and
+ * coverage.
+ */
+
+static unsigned regscan(void) {
+ Thread *tp;
+ unsigned i = 0;
+
+ tp = chRegFirstThread();
+ do {
+ i++;
+ tp = chRegNextThread(tp);
+ } while (tp != NULL);
+ return i;
+}
+
+static char *dyn3_gettest(void) {
+
+ return "Dynamic APIs, registry and references";
+}
+
+static void dyn3_setup(void) {
+
+ chHeapInit(&heap1, test.buffer, sizeof(union test_buffers));
+}
+
+static void dyn3_execute(void) {
+ unsigned n1, n2, n3;
+ tprio_t prio = chThdGetPriority();
+
+ /* Current number of threads in the system, two times just in case some
+ external detached thread terminated.*/
+ (void)regscan();
+ n1 = regscan();
+
+ /* Testing references increase/decrease and final detach.*/
+ threads[0] = chThdCreateFromHeap(&heap1, THD_WA_SIZE(THREADS_STACK_SIZE),
+ prio-1, thread, "A");
+ test_assert(1, threads[0]->p_refs == 1, "wrong initial reference counter");
+ chThdAddRef(threads[0]);
+ test_assert(2, threads[0]->p_refs == 2, "references increase failure");
+ chThdRelease(threads[0]);
+ test_assert(3, threads[0]->p_refs == 1, "references decrease failure");
+
+ /* Verify the new threads count.*/
+ n2 = regscan();
+ test_assert(4, n1 == n2 - 1, "unexpected threads count");
+
+ /* Detach and let the thread execute and terminate.*/
+ chThdRelease(threads[0]);
+ test_assert(5, threads[0]->p_refs == 0, "detach failure");
+ chThdSleepMilliseconds(50); /* The thread just terminates. */
+ test_assert(6, threads[0]->p_state == THD_STATE_FINAL, "invalid state");
+
+ /* Clearing the zombie by scanning the registry.*/
+ n3 = regscan();
+ test_assert(7, n1 == n3, "unexpected threads count");
+}
+
+const struct testcase testdyn3 = {
+ dyn3_gettest,
+ dyn3_setup,
+ NULL,
+ dyn3_execute
+};
+#endif /* CH_USE_HEAP */
#endif /* CH_USE_DYNAMIC */
/**
@@ -202,6 +274,9 @@ const struct testcase * const patterndyn[] = {
#if CH_USE_MEMPOOLS
&testdyn2,
#endif
+#if CH_USE_HEAP
+ &testdyn3,
+#endif
#endif
NULL
};
diff --git a/test/testheap.c b/test/testheap.c
index 2f4998be6..eb81f77ed 100644
--- a/test/testheap.c
+++ b/test/testheap.c
@@ -78,6 +78,9 @@ static void heap1_execute(void) {
void *p1, *p2, *p3;
size_t n, sz;
+ /* Unrelated, for coverage only.*/
+ (void)chCoreStatus();
+
/*
* Test on the default heap in order to cover the core allocator at
* least one time.
diff --git a/test/testpools.c b/test/testpools.c
index 75b26d50f..af4999547 100644
--- a/test/testpools.c
+++ b/test/testpools.c
@@ -60,6 +60,11 @@ static MEMORYPOOL_DECL(mp1, THD_WA_SIZE(THREADS_STACK_SIZE), NULL);
* operation.
*/
+static void *null_provider(size_t size) {
+
+ return NULL;
+}
+
static char *pools1_gettest(void) {
return "Memory Pools, queue/dequeue";
@@ -83,6 +88,10 @@ static void pools1_execute(void) {
/* Now must be empty. */
test_assert(2, chPoolAlloc(&mp1) == NULL, "list not empty");
+
+ /* Covering the case where a provider is unable to return more memory.*/
+ chPoolInit(&mp1, 16, null_provider);
+ test_assert(3, chPoolAlloc(&mp1) == NULL, "provider returned memory");
}
const struct testcase testpools1 = {