Revision of pipes.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12315 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
Giovanni Di Sirio 2018-10-02 12:58:00 +00:00
parent 65221fb131
commit f1f1620287
5 changed files with 219 additions and 209 deletions

View File

@ -70,7 +70,7 @@ int main(void) {
*/
while (true) {
if (palReadLine(LINE_JOY_CENTER)) {
test_execute((BaseSequentialStream *)&SD2, &rt_test_suite);
// test_execute((BaseSequentialStream *)&SD2, &rt_test_suite);
test_execute((BaseSequentialStream *)&SD2, &oslib_test_suite);
}
chThdSleepMilliseconds(500);

View File

@ -58,12 +58,16 @@ typedef struct {
uint8_t *rdptr; /**< @brief Read pointer. */
size_t cnt; /**< @brief Bytes in the pipe. */
bool reset; /**< @brief True if in reset state. */
threads_queue_t qw; /**< @brief Queued writers. */
threads_queue_t qr; /**< @brief Queued readers. */
thread_reference_t wtr; /**< @brief Waiting writer. */
thread_reference_t rtr; /**< @brief Waiting reader. */
#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
mutex_t mtx; /**< @brief Heap access mutex. */
mutex_t cmtx; /**< @brief Common access mutex. */
mutex_t wmtx; /**< @brief Write access mutex. */
mutex_t rmtx; /**< @brief Read access mutex. */
#else
semaphore_t sem; /**< @brief Heap access semaphore. */
semaphore_t csem; /**< @brief Common access semaphore.*/
semaphore_t wsem; /**< @brief Write access semaphore. */
semaphore_t rsem; /**< @brief Read access semaphore. */
#endif
} pipe_t;
@ -88,9 +92,11 @@ typedef struct {
(uint8_t *)(buffer), \
(size_t)0, \
false, \
_THREADS_QUEUE_DATA(name.qw), \
_THREADS_QUEUE_DATA(name.qr), \
_MUTEX_DATA(name.mtx), \
NULL, \
NULL, \
_MUTEX_DATA(name.cmtx), \
_MUTEX_DATA(name.wmtx), \
_MUTEX_DATA(name.rmtx), \
}
#else /* CH_CFG_USE_MUTEXES == FALSE */
#define _PIPE_DATA(name, buffer, size) { \
@ -100,9 +106,11 @@ typedef struct {
(uint8_t *)(buffer), \
(size_t)0, \
false, \
_THREADS_QUEUE_DATA(name.qw), \
_THREADS_QUEUE_DATA(name.qr), \
_SEMAPHORE_DATA(name.sem, (cnt_t)1), \
NULL, \
NULL, \
_SEMAPHORE_DATA(name.csem, (cnt_t)1), \
_SEMAPHORE_DATA(name.wsem, (cnt_t)1), \
_SEMAPHORE_DATA(name.rsem, (cnt_t)1), \
}
#endif /* CH_CFG_USE_MUTEXES == FALSE */
@ -181,23 +189,6 @@ static inline size_t chPipeGetFreeCount(const pipe_t *pp) {
return chPipeGetSize(pp) - chPipeGetUsedCount(pp);
}
/**
* @brief Returns the next byte in the queue without removing it.
* @pre A byte must be present in the queue for this function to work
* or it would return garbage. The correct way to use this macro is
* to use @p chPipeGetFullCountI() and then use this macro, all within
* a lock state.
*
* @param[in] pp the pointer to an initialized @p pipe_t object
* @return The next byte in queue.
*
* @api
*/
static inline uint8_t chPipePeek(const pipe_t *pp) {
return *pp->rdptr;
}
/**
* @brief Terminates the reset state.
*

View File

@ -51,11 +51,25 @@
* Defaults on the best synchronization mechanism available.
*/
#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
#define P_LOCK(p) chMtxLock(&(p)->mtx)
#define P_UNLOCK(p) chMtxUnlock(&(p)->mtx)
#define PC_INIT(p) chMtxObjectInit(&(p)->cmtx)
#define PC_LOCK(p) chMtxLock(&(p)->cmtx)
#define PC_UNLOCK(p) chMtxUnlock(&(p)->cmtx)
#define PW_INIT(p) chMtxObjectInit(&(p)->wmtx)
#define PW_LOCK(p) chMtxLock(&(p)->wmtx)
#define PW_UNLOCK(p) chMtxUnlock(&(p)->wmtx)
#define PR_INIT(p) chMtxObjectInit(&(p)->rmtx)
#define PR_LOCK(p) chMtxLock(&(p)->rmtx)
#define PR_UNLOCK(p) chMtxUnlock(&(p)->rmtx)
#else
#define P_LOCK(p) (void) chSemWait(&(p)->sem)
#define P_UNLOCK(p) chSemSignal(&(p)->sem)
#define PC_INIT(p) chMtxObjectInit(&(p)->csem, (cnt_t)1)
#define PC_LOCK(p) (void) chSemWait(&(p)->csem)
#define PC_UNLOCK(p) chSemSignal(&(p)->csem)
#define PW_INIT(p) chMtxObjectInit(&(p)->wsem, (cnt_t)1)
#define PW_LOCK(p) (void) chSemWait(&(p)->wsem)
#define PW_UNLOCK(p) chSemSignal(&(p)->wsem)
#define PR_INIT(p) chMtxObjectInit(&(p)->rsem, (cnt_t)1)
#define PR_LOCK(p) (void) chSemWait(&(p)->rsem)
#define PR_UNLOCK(p) chSemSignal(&(p)->rsem)
#endif
/*===========================================================================*/
@ -91,15 +105,19 @@
static size_t pipe_write(pipe_t *pp, const uint8_t *bp, size_t n) {
size_t s1, s2;
PC_LOCK(pp);
/* Number of bytes that can be written in a single atomic operation.*/
if (n > chPipeGetFreeCount(pp)) {
n = chPipeGetFreeCount(pp);
}
pp->cnt += n;
/* Number of bytes before buffer limit.*/
/*lint -save -e9033 [10.8] Checked to be safe.*/
s1 = (size_t)(pp->top - pp->wrptr);
/*lint -restore*/
if (n < s1) {
memcpy((void *)pp->wrptr, (const void *)bp, n);
pp->wrptr += n;
@ -116,7 +134,8 @@ static size_t pipe_write(pipe_t *pp, const uint8_t *bp, size_t n) {
pp->wrptr = pp->buffer;
}
pp->cnt += n;
PC_UNLOCK(pp);
return n;
}
@ -137,15 +156,19 @@ static size_t pipe_write(pipe_t *pp, const uint8_t *bp, size_t n) {
static size_t pipe_read(pipe_t *pp, uint8_t *bp, size_t n) {
size_t s1, s2;
PC_LOCK(pp);
/* Number of bytes that can be read in a single atomic operation.*/
if (n > chPipeGetUsedCount(pp)) {
n = chPipeGetUsedCount(pp);
}
pp->cnt -= n;
/* Number of bytes before buffer limit.*/
/*lint -save -e9033 [10.8] Checked to be safe.*/
s1 = (size_t)(pp->top - pp->rdptr);
/*lint -restore*/
if (n < s1) {
memcpy((void *)bp, (void *)pp->rdptr, n);
pp->rdptr += n;
@ -162,7 +185,8 @@ static size_t pipe_read(pipe_t *pp, uint8_t *bp, size_t n) {
pp->rdptr = pp->buffer;
}
pp->cnt -= n;
PC_UNLOCK(pp);
return n;
}
@ -190,8 +214,11 @@ void chPipeObjectInit(pipe_t *pp, uint8_t *buf, size_t n) {
pp->top = &buf[n];
pp->cnt = (size_t)0;
pp->reset = false;
chThdQueueObjectInit(&pp->qw);
chThdQueueObjectInit(&pp->qr);
pp->wtr = NULL;
pp->rtr = NULL;
PC_INIT(pp);
PW_INIT(pp);
PR_INIT(pp);
}
/**
@ -210,17 +237,20 @@ void chPipeReset(pipe_t *pp) {
chDbgCheck(pp != NULL);
P_LOCK(pp);
chSysLock();
PC_LOCK(pp);
pp->wrptr = pp->buffer;
pp->rdptr = pp->buffer;
pp->cnt = (size_t)0;
pp->reset = true;
chThdDequeueAllI(&pp->qw, MSG_RESET);
chThdDequeueAllI(&pp->qr, MSG_RESET);
chSysLock();
chThdResumeI(&pp->wtr, MSG_RESET);
chThdResumeI(&pp->rtr, MSG_RESET);
chSchRescheduleS();
chSysUnlock();
P_UNLOCK(pp);
PC_UNLOCK(pp);
}
/**
@ -232,16 +262,16 @@ void chPipeReset(pipe_t *pp) {
*
* @param[in] pp the pointer to an initialized @p pipe_t object
* @param[in] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred, the
* value 0 is reserved
* @param[in] n the number of bytes to be written, the value 0 is
* reserved
* @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
* .
* @return The number of bytes effectively transferred.
* @retval MSG_RESET if the mailbox has been reset.
* @retval MSG_TIMEOUT if the operation has timed out.
* @return The number of bytes effectively transferred. A number
* lower than @p n means that a timeout occurred or the
* pipe went in reset state.
*
* @api
*/
@ -253,10 +283,10 @@ size_t chPipeWriteTimeout(pipe_t *pp, const uint8_t *bp,
/* If the pipe is in reset state then returns immediately.*/
if (pp->reset) {
return MSG_RESET;
return (size_t)0;
}
P_LOCK(pp);
PW_LOCK(pp);
while (n > 0U) {
size_t done;
@ -266,7 +296,7 @@ size_t chPipeWriteTimeout(pipe_t *pp, const uint8_t *bp,
msg_t msg;
chSysLock();
msg = chThdEnqueueTimeoutS(&pp->qw, timeout);
msg = chThdSuspendTimeoutS(&pp->wtr, timeout);
chSysUnlock();
/* Anything except MSG_OK causes the operation to stop.*/
@ -277,10 +307,13 @@ size_t chPipeWriteTimeout(pipe_t *pp, const uint8_t *bp,
else {
n -= done;
bp += done;
/* Resuming the reader, if present.*/
chThdResume(&pp->rtr, MSG_OK);
}
}
P_UNLOCK(pp);
PW_UNLOCK(pp);
return max - n;
}
@ -294,16 +327,16 @@ size_t chPipeWriteTimeout(pipe_t *pp, const uint8_t *bp,
*
* @param[in] pp the pointer to an initialized @p pipe_t object
* @param[out] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred, the
* value 0 is reserved
* @param[in] n the number of bytes to be read, the value 0 is
* reserved
* @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
* .
* @return The number of bytes effectively transferred.
* @retval MSG_RESET if the mailbox has been reset.
* @retval MSG_TIMEOUT if the operation has timed out.
* @return The number of bytes effectively transferred. A number
* lower than @p n means that a timeout occurred or the
* pipe went in reset state.
*
* @api
*/
@ -315,10 +348,10 @@ size_t chPipeReadTimeout(pipe_t *pp, uint8_t *bp,
/* If the pipe is in reset state then returns immediately.*/
if (pp->reset) {
return MSG_RESET;
return (size_t)0;
}
P_LOCK(pp);
PR_LOCK(pp);
while (n > 0U) {
size_t done;
@ -328,7 +361,7 @@ size_t chPipeReadTimeout(pipe_t *pp, uint8_t *bp,
msg_t msg;
chSysLock();
msg = chThdEnqueueTimeoutS(&pp->qr, timeout);
msg = chThdSuspendTimeoutS(&pp->rtr, timeout);
chSysUnlock();
/* Anything except MSG_OK causes the operation to stop.*/
@ -339,10 +372,13 @@ size_t chPipeReadTimeout(pipe_t *pp, uint8_t *bp,
else {
n -= done;
bp += done;
/* Resuming the writer, if present.*/
chThdResume(&pp->wtr, MSG_OK);
}
}
P_UNLOCK(pp);
PR_UNLOCK(pp);
return max - n;
}

View File

@ -477,17 +477,6 @@ static const uint8_t pipe_pattern[] = "0123456789ABCDEF";]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value></value>
</description>
<tags>
<value></value>
</tags>
<code>
<value><![CDATA[]]></value>
</code>
</step>
<step>
<description>
<value>Resetting pipe.</value>
@ -512,10 +501,10 @@ test_assert((pipe1.rdptr == pipe1.buffer) &&
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == MSG_RESET, "not reset");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == 0, "not reset");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
@ -530,11 +519,11 @@ test_assert((pipe1.rdptr == pipe1.buffer) &&
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == MSG_RESET, "not reset");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == 0, "not reset");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
@ -564,10 +553,10 @@ test_assert((pipe1.rdptr == pipe1.buffer) &&
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE),
@ -582,11 +571,11 @@ test_assert((pipe1.rdptr == pipe1.buffer) &&
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
@ -602,10 +591,10 @@ test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE) == 0, "content mismatch");]]></
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, 4, TIME_IMMEDIATE);
test_assert(msg == 4, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, 4, TIME_IMMEDIATE);
test_assert(n == 4, "wrong size");
test_assert((pipe1.rdptr != pipe1.wrptr) &&
(pipe1.rdptr == pipe1.buffer) &&
(pipe1.cnt == 4),
@ -620,10 +609,10 @@ test_assert((pipe1.rdptr != pipe1.wrptr) &&
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE - 4, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE - 4, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE - 4, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE - 4, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE),
@ -638,11 +627,11 @@ test_assert((pipe1.rdptr == pipe1.buffer) &&
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, 4, TIME_IMMEDIATE);
test_assert(msg == 4, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, 4, TIME_IMMEDIATE);
test_assert(n == 4, "wrong size");
test_assert((pipe1.rdptr != pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE - 4),
@ -658,11 +647,11 @@ test_assert(memcmp(pipe_pattern, buf, 4) == 0, "content mismatch");]]></value>
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE - 4, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE - 4, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE - 4, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE - 4, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
@ -678,10 +667,10 @@ test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE - 4) == 0, "content mismatch");]
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, 5, TIME_IMMEDIATE);
test_assert(msg == 5, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, 5, TIME_IMMEDIATE);
test_assert(n == 5, "wrong size");
test_assert((pipe1.rdptr != pipe1.wrptr) &&
(pipe1.rdptr == pipe1.buffer) &&
(pipe1.cnt == 5),
@ -696,11 +685,11 @@ test_assert((pipe1.rdptr != pipe1.wrptr) &&
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, 5, TIME_IMMEDIATE);
test_assert(msg == 5, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, 5, TIME_IMMEDIATE);
test_assert(n == 5, "wrong size");
test_assert((pipe1.rdptr == pipe1.wrptr) &&
(pipe1.wrptr != pipe1.buffer) &&
(pipe1.cnt == 0),
@ -716,10 +705,10 @@ test_assert(memcmp(pipe_pattern, buf, 5) == 0, "content mismatch");]]></value>
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE, "wrong size");
test_assert((pipe1.rdptr == pipe1.wrptr) &&
(pipe1.wrptr != pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE),
@ -734,11 +723,11 @@ test_assert((pipe1.rdptr == pipe1.wrptr) &&
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE, "wrong size");
test_assert((pipe1.rdptr == pipe1.wrptr) &&
(pipe1.wrptr != pipe1.buffer) &&
(pipe1.cnt == 0),
@ -779,11 +768,11 @@ test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE) == 0, "content mismatch");]]></
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == 0, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == 0, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
@ -798,10 +787,10 @@ test_assert((pipe1.rdptr == pipe1.buffer) &&
<value></value>
</tags>
<code>
<value><![CDATA[msg_t msg;
<value><![CDATA[size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE / 2, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE / 2, "wrong size");
test_assert((pipe1.rdptr == pipe1.wrptr) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE / 2),

View File

@ -68,21 +68,20 @@ static const uint8_t pipe_pattern[] = "0123456789ABCDEF";
* conditions are tested.
*
* <h2>Test Steps</h2>
* - [2.1.1].
* - [2.1.2] Resetting pipe.
* - [2.1.3] Writing data, must fail.
* - [2.1.4] Reading data, must fail.
* - [2.1.5] Reactivating pipe.
* - [2.1.6] Filling whole pipe.
* - [2.1.7] Emptying pipe.
* - [2.1.8] Small write.
* - [2.1.9] Filling remaining space.
* - [2.1.10] Small Read.
* - [2.1.11] Reading remaining data.
* - [2.1.12] Small Write.
* - [2.1.13] Small Read.
* - [2.1.14] Write wrapping buffer boundary.
* - [2.1.15] Read wrapping buffer boundary.
* - [2.1.1] Resetting pipe.
* - [2.1.2] Writing data, must fail.
* - [2.1.3] Reading data, must fail.
* - [2.1.4] Reactivating pipe.
* - [2.1.5] Filling whole pipe.
* - [2.1.6] Emptying pipe.
* - [2.1.7] Small write.
* - [2.1.8] Filling remaining space.
* - [2.1.9] Small Read.
* - [2.1.10] Reading remaining data.
* - [2.1.11] Small Write.
* - [2.1.12] Small Read.
* - [2.1.13] Write wrapping buffer boundary.
* - [2.1.14] Read wrapping buffer boundary.
* .
*/
@ -92,13 +91,8 @@ static void oslib_test_002_001_setup(void) {
static void oslib_test_002_001_execute(void) {
/* [2.1.1].*/
/* [2.1.1] Resetting pipe.*/
test_set_step(1);
{
}
/* [2.1.2] Resetting pipe.*/
test_set_step(2);
{
chPipeReset(&pipe1);
@ -108,35 +102,35 @@ static void oslib_test_002_001_execute(void) {
"invalid pipe state");
}
/* [2.1.3] Writing data, must fail.*/
/* [2.1.2] Writing data, must fail.*/
test_set_step(2);
{
size_t n;
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == 0, "not reset");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
"invalid pipe state");
}
/* [2.1.3] Reading data, must fail.*/
test_set_step(3);
{
msg_t msg;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == MSG_RESET, "not reset");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
"invalid pipe state");
}
/* [2.1.4] Reading data, must fail.*/
test_set_step(4);
{
msg_t msg;
size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == MSG_RESET, "not reset");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == 0, "not reset");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
"invalid pipe state");
}
/* [2.1.5] Reactivating pipe.*/
test_set_step(5);
/* [2.1.4] Reactivating pipe.*/
test_set_step(4);
{
chPipeResume(&pipe1);
test_assert((pipe1.rdptr == pipe1.buffer) &&
@ -145,27 +139,27 @@ static void oslib_test_002_001_execute(void) {
"invalid pipe state");
}
/* [2.1.6] Filling whole pipe.*/
test_set_step(6);
/* [2.1.5] Filling whole pipe.*/
test_set_step(5);
{
msg_t msg;
size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE),
"invalid pipe state");
}
/* [2.1.7] Emptying pipe.*/
test_set_step(7);
/* [2.1.6] Emptying pipe.*/
test_set_step(6);
{
msg_t msg;
size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
@ -173,40 +167,40 @@ static void oslib_test_002_001_execute(void) {
test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE) == 0, "content mismatch");
}
/* [2.1.8] Small write.*/
test_set_step(8);
/* [2.1.7] Small write.*/
test_set_step(7);
{
msg_t msg;
size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, 4, TIME_IMMEDIATE);
test_assert(msg == 4, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, 4, TIME_IMMEDIATE);
test_assert(n == 4, "wrong size");
test_assert((pipe1.rdptr != pipe1.wrptr) &&
(pipe1.rdptr == pipe1.buffer) &&
(pipe1.cnt == 4),
"invalid pipe state");
}
/* [2.1.9] Filling remaining space.*/
test_set_step(9);
/* [2.1.8] Filling remaining space.*/
test_set_step(8);
{
msg_t msg;
size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE - 4, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE - 4, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE - 4, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE - 4, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE),
"invalid pipe state");
}
/* [2.1.10] Small Read.*/
test_set_step(10);
/* [2.1.9] Small Read.*/
test_set_step(9);
{
msg_t msg;
size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, 4, TIME_IMMEDIATE);
test_assert(msg == 4, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, 4, TIME_IMMEDIATE);
test_assert(n == 4, "wrong size");
test_assert((pipe1.rdptr != pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE - 4),
@ -214,14 +208,14 @@ static void oslib_test_002_001_execute(void) {
test_assert(memcmp(pipe_pattern, buf, 4) == 0, "content mismatch");
}
/* [2.1.11] Reading remaining data.*/
test_set_step(11);
/* [2.1.10] Reading remaining data.*/
test_set_step(10);
{
msg_t msg;
size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE - 4, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE - 4, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE - 4, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE - 4, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
@ -229,27 +223,27 @@ static void oslib_test_002_001_execute(void) {
test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE - 4) == 0, "content mismatch");
}
/* [2.1.12] Small Write.*/
test_set_step(12);
/* [2.1.11] Small Write.*/
test_set_step(11);
{
msg_t msg;
size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, 5, TIME_IMMEDIATE);
test_assert(msg == 5, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, 5, TIME_IMMEDIATE);
test_assert(n == 5, "wrong size");
test_assert((pipe1.rdptr != pipe1.wrptr) &&
(pipe1.rdptr == pipe1.buffer) &&
(pipe1.cnt == 5),
"invalid pipe state");
}
/* [2.1.13] Small Read.*/
test_set_step(13);
/* [2.1.12] Small Read.*/
test_set_step(12);
{
msg_t msg;
size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, 5, TIME_IMMEDIATE);
test_assert(msg == 5, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, 5, TIME_IMMEDIATE);
test_assert(n == 5, "wrong size");
test_assert((pipe1.rdptr == pipe1.wrptr) &&
(pipe1.wrptr != pipe1.buffer) &&
(pipe1.cnt == 0),
@ -257,27 +251,27 @@ static void oslib_test_002_001_execute(void) {
test_assert(memcmp(pipe_pattern, buf, 5) == 0, "content mismatch");
}
/* [2.1.14] Write wrapping buffer boundary.*/
test_set_step(14);
/* [2.1.13] Write wrapping buffer boundary.*/
test_set_step(13);
{
msg_t msg;
size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE, "wrong size");
test_assert((pipe1.rdptr == pipe1.wrptr) &&
(pipe1.wrptr != pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE),
"invalid pipe state");
}
/* [2.1.15] Read wrapping buffer boundary.*/
test_set_step(15);
/* [2.1.14] Read wrapping buffer boundary.*/
test_set_step(14);
{
msg_t msg;
size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE, "wrong size");
test_assert((pipe1.rdptr == pipe1.wrptr) &&
(pipe1.wrptr != pipe1.buffer) &&
(pipe1.cnt == 0),
@ -314,11 +308,11 @@ static void oslib_test_002_002_execute(void) {
/* [2.2.1] Reading while pipe is empty.*/
test_set_step(1);
{
msg_t msg;
size_t n;
uint8_t buf[PIPE_SIZE];
msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == 0, "wrong size");
n = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == 0, "wrong size");
test_assert((pipe1.rdptr == pipe1.buffer) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == 0),
@ -328,10 +322,10 @@ static void oslib_test_002_002_execute(void) {
/* [2.2.2] Writing a string larger than pipe buffer.*/
test_set_step(2);
{
msg_t msg;
size_t n;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(msg == PIPE_SIZE / 2, "wrong size");
n = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
test_assert(n == PIPE_SIZE / 2, "wrong size");
test_assert((pipe1.rdptr == pipe1.wrptr) &&
(pipe1.wrptr == pipe1.buffer) &&
(pipe1.cnt == PIPE_SIZE / 2),