diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-04-19 08:42:58 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-04-19 08:42:58 +0000 |
commit | 8a83ae1bb9db8b0e25d6b1cc899fec54bfe8fbf8 (patch) | |
tree | 863344d47c22a6141e083cbb08f8b8d907be99d3 /test | |
parent | d62a644b1e910c7fccd65d768a838fcc651e4e80 (diff) | |
download | ChibiOS-8a83ae1bb9db8b0e25d6b1cc899fec54bfe8fbf8.tar.gz ChibiOS-8a83ae1bb9db8b0e25d6b1cc899fec54bfe8fbf8.tar.bz2 ChibiOS-8a83ae1bb9db8b0e25d6b1cc899fec54bfe8fbf8.zip |
100% code coverage for messages.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@915 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test')
-rw-r--r-- | test/testmsg.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/test/testmsg.c b/test/testmsg.c index 69f1461e1..b31f57097 100644 --- a/test/testmsg.c +++ b/test/testmsg.c @@ -25,32 +25,49 @@ static char *msg1_gettest(void) {
- return "Messages, dispatch test";
+ return "Messages, loop";
}
static msg_t thread(void *p) {
- msg_t msg;
- int i;
- for (i = 0; i < 5; i++) {
- msg = chMsgSend(p, 'A' + i);
- test_emit_token(msg);
- }
- chMsgSend(p, 0);
+ chMsgSend(p, 'A');
+ chMsgSend(p, 'B');
+ chMsgSend(p, 'C');
+ chMsgSend(p, 'D');
return 0;
}
static void msg1_execute(void) {
msg_t msg;
- threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-1, thread, chThdSelf());
- do {
- chMsgRelease(msg = chMsgWait());
- if (msg)
- test_emit_token(msg);
- } while (msg);
- test_wait_threads();
- test_assert_sequence("AABBCCDDEE");
+ /*
+ * Testing the whole messages loop.
+ */
+ threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() + 1,
+ thread, chThdSelf());
+ chMsgRelease(msg = chMsgWait());
+ test_emit_token(msg);
+ chMsgRelease(msg = chMsgWait());
+ test_emit_token(msg);
+ chMsgRelease(msg = chMsgWait());
+ test_emit_token(msg);
+ test_assert_sequence("ABC");
+
+ /*
+ * Testing message fetch using chMsgGet().
+ * Note, the following is valid because the sender has higher priority than
+ * the receiver.
+ */
+ msg = chMsgGet();
+ test_assert(msg != 0, "#1");
+ chMsgRelease(0);
+ test_assert(msg == 'D', "#2");
+
+ /*
+ * Must not have pending messages.
+ */
+ msg = chMsgGet();
+ test_assert(msg == 0, "#3");
}
const struct testcase testmsg1 = {
|