aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2007-12-16 19:01:30 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2007-12-16 19:01:30 +0000
commit430010715e7a9af17185412273165674f3b58f20 (patch)
tree595c6897e48c954b29cc2b2e03855937f23fc182 /test
parentb196b277b9fe301ee2fa73f45be4d5e55d74e402 (diff)
downloadChibiOS-430010715e7a9af17185412273165674f3b58f20.tar.gz
ChibiOS-430010715e7a9af17185412273165674f3b58f20.tar.bz2
ChibiOS-430010715e7a9af17185412273165674f3b58f20.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@141 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test')
-rw-r--r--test/test.c232
1 files changed, 175 insertions, 57 deletions
diff --git a/test/test.c b/test/test.c
index 15b70b9d4..5f6736843 100644
--- a/test/test.c
+++ b/test/test.c
@@ -40,6 +40,7 @@ static Thread *t1, *t2, *t3, *t4, *t5;
static FullDuplexDriver *comp;
static Semaphore sem1;
+static Mutex m1, m2;
static void wait(void) {
@@ -92,8 +93,9 @@ t_msg Thread2(void *p) {
t_msg Thread3(void *p) {
- chSemRaisePrioWait(&sem1);
+ chMtxLock(&m1);
chFDDPut(comp, *(BYTE8 *)p);
+ chMtxUnlock();
return 0;
}
@@ -129,25 +131,8 @@ t_msg Thread7(void *p) {
return (unsigned int)p + 1;
}
-/**
- * Tester thread, this thread must be created with priority \p NORMALPRIO.
- */
-t_msg TestThread(void *p) {
- static BYTE8 ib[16];
- static Queue iq;
- t_msg msg;
- unsigned int i;
- t_time time;
+static void testrdy1(void) {
- comp = p;
- println("*****************************");
- println("*** ChibiOS/RT test suite ***");
- println("*****************************");
- println("");
-
- /*
- * Ready list ordering test.
- */
println("*** Ready List, priority enqueuing test #1, you should read ABCDE:");
t5 = chThdCreate(chThdGetPriority()-5, 0, wsT5, sizeof(wsT5), Thread1, "E");
t4 = chThdCreate(chThdGetPriority()-4, 0, wsT4, sizeof(wsT4), Thread1, "D");
@@ -156,6 +141,10 @@ t_msg TestThread(void *p) {
t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread1, "A");
wait();
println("");
+}
+
+static void testrdy2(void) {
+
println("*** Ready List, priority enqueuing test #2, you should read ABCDE:");
t4 = chThdCreate(chThdGetPriority()-4, 0, wsT4, sizeof(wsT4), Thread1, "D");
t5 = chThdCreate(chThdGetPriority()-5, 0, wsT5, sizeof(wsT5), Thread1, "E");
@@ -164,12 +153,12 @@ t_msg TestThread(void *p) {
t3 = chThdCreate(chThdGetPriority()-3, 0, wsT3, sizeof(wsT3), Thread1, "C");
wait();
println("");
+}
+
+static void testsem1(void) {
- /*
- * Semaphores test.
- */
- chSemInit(&sem1, 0);
println("*** Semaphores, FIFO enqueuing test, you should read ABCDE:");
+ chSemInit(&sem1, 0);
t1 = chThdCreate(chThdGetPriority()+5, 0, wsT1, sizeof(wsT1), Thread2, "A");
t2 = chThdCreate(chThdGetPriority()+1, 0, wsT2, sizeof(wsT2), Thread2, "B");
t3 = chThdCreate(chThdGetPriority()+3, 0, wsT3, sizeof(wsT3), Thread2, "C");
@@ -182,45 +171,111 @@ t_msg TestThread(void *p) {
chSemSignal(&sem1);
wait();
println("");
- println("*** Semaphores, priority enqueuing test #1, you should read ABCDE:");
+}
+
+static void testsem2(void) {
+ unsigned int i;
+
+ println("*** Semaphores, timeout test, you should read ABCDE (slowly):");
chSemInit(&sem1, 0);
+ for (i = 0; i < 5; i++) {
+ chFDDPut(comp, 'A' + i);
+ chSemWaitTimeout(&sem1, 500);
+ }
+ println("");
+}
+
+static void testmtx1(void) {
+
+ chMtxInit(&m1);
+ println("*** Mutexes, priority enqueuing test, you should read ABCDE:");
+ chMtxLock(&m1);
t5 = chThdCreate(chThdGetPriority()+1, 0, wsT5, sizeof(wsT5), Thread3, "E");
- t4 = chThdCreate(chThdGetPriority()+2, 0, wsT4, sizeof(wsT4), Thread3, "D");
+ t4 = chThdCreate(chThdGetPriority()+3, 0, wsT4, sizeof(wsT4), Thread3, "D");
t3 = chThdCreate(chThdGetPriority()+3, 0, wsT3, sizeof(wsT3), Thread3, "C");
t2 = chThdCreate(chThdGetPriority()+4, 0, wsT2, sizeof(wsT2), Thread3, "B");
t1 = chThdCreate(chThdGetPriority()+5, 0, wsT1, sizeof(wsT1), Thread3, "A");
- chSemLowerPrioSignal(&sem1);
- chSemLowerPrioSignal(&sem1);
- chSemLowerPrioSignal(&sem1);
- chSemLowerPrioSignal(&sem1);
- chSemLowerPrioSignal(&sem1);
+ chMtxUnlock();
wait();
println("");
- println("*** Semaphores, priority enqueuing test #2, you should read ABCDE:");
- chSemInit(&sem1, 0);
- t4 = chThdCreate(chThdGetPriority()+2, 0, wsT4, sizeof(wsT4), Thread3, "D");
- t5 = chThdCreate(chThdGetPriority()+1, 0, wsT5, sizeof(wsT5), Thread3, "E");
- t1 = chThdCreate(chThdGetPriority()+5, 0, wsT1, sizeof(wsT1), Thread3, "A");
- t2 = chThdCreate(chThdGetPriority()+4, 0, wsT2, sizeof(wsT2), Thread3, "B");
- t3 = chThdCreate(chThdGetPriority()+3, 0, wsT3, sizeof(wsT3), Thread3, "C");
- chSemLowerPrioSignal(&sem1);
- chSemLowerPrioSignal(&sem1);
- chSemLowerPrioSignal(&sem1);
- chSemLowerPrioSignal(&sem1);
- chSemLowerPrioSignal(&sem1);
- wait();
+}
+
+t_msg Thread8(void *p) {
+
+ chThdSleep(5);
+ chMtxLock(&m1);
+ chMtxUnlock();
+ chFDDPut(comp, *(BYTE8 *)p);
+ return 0;
+}
+
+t_msg Thread9(void *p) {
+
+ chMtxLock(&m1);
+ chThdSleep(20);
+ chMtxUnlock();
+ chFDDPut(comp, *(BYTE8 *)p);
+ return 0;
+}
+
+t_msg Thread10(void *p) {
+
+ chThdSleep(10);
+ /* 50mS CPU pulse */
+ t_time time = chSysGetTime() + 50;
+ while (chSysGetTime() != time)
+ ;
+ chFDDPut(comp, *(BYTE8 *)p);
+ return 0;
+}
+
+t_msg Thread11(void *p) {
+
+ chThdSleep(5);
+ chSemWait(&sem1);
+ chSemSignal(&sem1);
+ chFDDPut(comp, *(BYTE8 *)p);
+ return 0;
+}
+
+t_msg Thread12(void *p) {
+
+ chSemWait(&sem1);
+ chThdSleep(20);
+ chSemSignal(&sem1);
+ chFDDPut(comp, *(BYTE8 *)p);
+ return 0;
+}
+
+static void testmtx2(void) {
+
+ chMtxInit(&m1);
+ println("*** Mutexes, mutex with inheritance, you should read ABC:");
+ t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread8, "A");
+ t2 = chThdCreate(chThdGetPriority()-3, 0, wsT2, sizeof(wsT2), Thread9, "C");
+ t3 = chThdCreate(chThdGetPriority()-2, 0, wsT3, sizeof(wsT3), Thread10, "B");
+ chThdWait(t1);
+ chThdWait(t2);
+ chThdWait(t3);
println("");
- println("*** Semaphores, timeout test, you should read ABCDE (slowly):");
- chSemInit(&sem1, 0);
- for (i = 0; i < 5; i++) {
- chFDDPut(comp, 'A'+i);
- chSemWaitTimeout(&sem1, 500);
- }
+}
+
+static void testmtx3(void) {
+
+ chSemInit(&sem1, 1);
+ println("*** Mutexes, mutex without inheritance, inversion happens, you should read BAC:");
+ t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread11, "A");
+ t2 = chThdCreate(chThdGetPriority()-3, 0, wsT2, sizeof(wsT2), Thread12, "C");
+ t3 = chThdCreate(chThdGetPriority()-2, 0, wsT3, sizeof(wsT3), Thread10, "B");
+ chThdWait(t1);
+ chThdWait(t2);
+ chThdWait(t3);
println("");
+}
+
+static void testmsg1(void) {
+ t_msg msg;
- /*
- * Messages test.
- */
println("*** Messages, dispatch test, you should read AABBCCDDEE:");
t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread4, chThdSelf());
do {
@@ -230,19 +285,26 @@ t_msg TestThread(void *p) {
} while (msg);
chThdWait(t1);
println("");
+}
+
+static void testmsg2(void) {
+ unsigned int i;
+
println("*** Messages, timeout test, you should read ABCDE (slowly):");
t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread5, chThdSelf());
for (i = 0; i < 5; i++) {
- chFDDPut(comp, 'A'+i);
- chMsgSendTimeout(t1, 'A'+i, 500);
+ chFDDPut(comp, 'A' + i);
+ chMsgSendTimeout(t1, 'A' + i, 500);
}
chMsgSendTimeout(t1, 0, 500);
chThdWait(t1);
println("");
+}
+
+static void bench1(void) {
+ unsigned int i;
+ t_time time;
- /*
- * Kernel benchmarks.
- */
println("*** Kernel Benchmark, context switch stress test:");
time = chSysGetTime() + 1;
while (chSysGetTime() < time) {
@@ -266,6 +328,11 @@ t_msg TestThread(void *p) {
print(" msgs/S, ");
printn(i << 1);
println(" ctxsws/S");
+}
+
+static void bench2(void) {
+ unsigned int i;
+ t_time time;
println("*** Kernel Benchmark, threads creation/termination:");
time = chSysGetTime() + 1;
@@ -286,6 +353,13 @@ t_msg TestThread(void *p) {
print("Threads throughput = ");
printn(i);
println(" threads/S");
+}
+
+static void bench3(void) {
+ static BYTE8 ib[16];
+ static Queue iq;
+ unsigned int i;
+ t_time time;
println("*** Kernel Benchmark, I/O Queues throughput:");
chIQInit(&iq, ib, sizeof(ib), NULL);
@@ -311,6 +385,50 @@ t_msg TestThread(void *p) {
print("Queues throughput = ");
printn(i * 4);
println(" bytes/S");
+}
+
+/**
+ * Tester thread, this thread must be created with priority \p NORMALPRIO.
+ */
+t_msg TestThread(void *p) {
+
+ comp = p;
+ println("*****************************");
+ println("*** ChibiOS/RT test suite ***");
+ println("*****************************");
+ println("");
+
+ /*
+ * Ready list ordering tests.
+ */
+ testrdy1();
+ testrdy2();
+
+ /*
+ * Semaphores tests.
+ */
+ testsem1();
+ testsem2();
+
+ /*
+ * Mutexes tests.
+ */
+ testmtx1();
+ testmtx2();
+ testmtx3();
+
+ /*
+ * Messages tests.
+ */
+ testmsg1();
+ testmsg2();
+
+ /*
+ * Kernel benchmarks.
+ */
+ bench1();
+ bench2();
+ bench3();
println("\r\nTest complete");
return 0;