Coverage 100% for modified queues.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1505 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
gdisirio 2010-01-06 10:30:01 +00:00
parent 78167cbb9f
commit bc489e39a8
3 changed files with 88 additions and 17 deletions

View File

@ -45,6 +45,19 @@ BaseChannel CD1;
/* Driver local functions. */
/*===========================================================================*/
static size_t writes(void *ip, const uint8_t *bp, size_t n) {
(void)ip;
return fwrite(bp, 1, n, stdout);
}
static size_t reads(void *ip, uint8_t *bp, size_t n) {
(void)ip;
return fread(bp, 1, n, stdin);
}
static bool_t putwouldblock(void *ip) {
(void)ip;
@ -57,24 +70,39 @@ static bool_t getwouldblock(void *ip) {
return TRUE;
}
static msg_t put(void *ip, uint8_t b, systime_t timeout) {
static msg_t putt(void *ip, uint8_t b, systime_t time) {
(void)ip;
(void)timeout;
(void)time;
fputc(b, stdout);
fflush(stdout);
return RDY_OK;
}
static msg_t get(void *ip, systime_t timeout) {
static msg_t gett(void *ip, systime_t time) {
(void)ip;
(void)timeout;
(void)time;
return fgetc(stdin);
}
static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) {
(void)ip;
(void)time;
return fwrite(bp, 1, n, stdout);
}
static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
(void)ip;
(void)time;
return fread(bp, 1, n, stdin);
}
static const struct BaseChannelVMT vmt = {
{putwouldblock, getwouldblock, put, get}
{writes, reads},
{putwouldblock, getwouldblock, putt, gett, writet, readt}
};
/*===========================================================================*/

View File

@ -45,6 +45,19 @@ BaseChannel CD1;
/* Driver local functions. */
/*===========================================================================*/
static size_t writes(void *ip, const uint8_t *bp, size_t n) {
(void)ip;
return fwrite(bp, 1, n, stdout);
}
static size_t reads(void *ip, uint8_t *bp, size_t n) {
(void)ip;
return fread(bp, 1, n, stdin);
}
static bool_t putwouldblock(void *ip) {
(void)ip;
@ -57,24 +70,39 @@ static bool_t getwouldblock(void *ip) {
return TRUE;
}
static msg_t put(void *ip, uint8_t b, systime_t timeout) {
static msg_t putt(void *ip, uint8_t b, systime_t time) {
(void)ip;
(void)timeout;
(void)time;
fputc(b, stdout);
fflush(stdout);
return RDY_OK;
}
static msg_t get(void *ip, systime_t timeout) {
static msg_t gett(void *ip, systime_t time) {
(void)ip;
(void)timeout;
(void)time;
return fgetc(stdin);
}
static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) {
(void)ip;
(void)time;
return fwrite(bp, 1, n, stdout);
}
static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
(void)ip;
(void)time;
return fread(bp, 1, n, stdin);
}
static const struct BaseChannelVMT vmt = {
{putwouldblock, getwouldblock, put, get}
{writes, reads},
{putwouldblock, getwouldblock, putt, gett, writet, readt}
};
/*===========================================================================*/

View File

@ -112,13 +112,24 @@ static void queues1_execute(void) {
test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size");
test_assert(7, chIQIsEmpty(&iq), "still full");
/* Queue filling again */
for (i = 0; i < TEST_QUEUES_SIZE; i++)
chIQPutI(&iq, 'A' + i);
/* Partial reads */
n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
test_assert(8, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
test_assert(9, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
test_assert(10, chIQIsEmpty(&iq), "still full");
/* Testing reset */
chIQPutI(&iq, 0);
chIQResetI(&iq);
test_assert(8, chIQIsEmpty(&iq), "still full");
test_assert(11, chIQIsEmpty(&iq), "still full");
/* Timeout */
test_assert(9, chIQGetTimeout(&iq, 10) == Q_TIMEOUT, "wrong timeout return");
test_assert(12, chIQGetTimeout(&iq, 10) == Q_TIMEOUT, "wrong timeout return");
}
const struct testcase testqueues1 = {
@ -167,18 +178,22 @@ static void queues2_execute(void) {
/* Writing the whole thing */
n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE * 2, TIME_IMMEDIATE);
test_assert(6, n == TEST_QUEUES_SIZE,"wrong returned size");
test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size");
test_assert(7, chOQIsFull(&oq), "not full");
/* Testing reset */
chOQResetI(&oq);
test_assert(8, chOQIsEmpty(&oq), "still full");
/* Partial writes */
n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
test_assert(9, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
test_assert(10, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
test_assert(11, chOQIsFull(&oq), "not full");
/* Timeout */
for (i = 0; i < TEST_QUEUES_SIZE; i++)
chOQPut(&oq, 'A' + i);
test_assert(9, chOQIsFull(&oq), "still has space");
test_assert(10, chOQPutTimeout(&oq, 0, 10) == Q_TIMEOUT, "wrong timeout return");
test_assert(12, chOQPutTimeout(&oq, 0, 10) == Q_TIMEOUT, "wrong timeout return");
}
const struct testcase testqueues2 = {