int pipeGetWaitTest(void) { int rv; /* return code from pipeGetWaitTestWork() */ int bytesRead; /* # of bytes read from task_pipe_get_waitait() */ task_sem_give(altSem); /* Wake AlternateTask */ rv = pipeGetWaitTestWork(wait_all_N, ARRAY_SIZE(wait_all_N)); if (rv != TC_PASS) { TC_ERROR("Failed on _ALL_N test\n"); return TC_FAIL; } rv = pipeGetWaitTestWork(wait_one_to_N, ARRAY_SIZE(wait_one_to_N)); if (rv != TC_PASS) { TC_ERROR("Failed on _1_TO_N test\n"); return TC_FAIL; } rv = task_pipe_get(pipeId, rxBuffer, PIPE_SIZE, &bytesRead, _0_TO_N, TICKS_UNLIMITED); if (rv != RC_FAIL) { TC_ERROR("Expected return code of %d, not %d\n", RC_FAIL, rv); return TC_FAIL; } return TC_PASS; }
int pipeGetWaitTestWork(SIZE_EXPECT *items, int nItems) { int i; /* loop counter */ int rv; /* return code from task_pipe_get() */ int bytesRead; /* # of bytes read from task_pipe_get() */ for (i = 0; i < nItems; i++) { /* * Pipe should be empty. Most calls to task_pipe_get(TICKS_UNLIMITED) * should block until the call to task_pipe_put() is performed in the * routine pipeGetWaitHelperWork(). */ rv = task_pipe_get(pipeId, rxBuffer, items[i].size, &bytesRead, items[i].options, TICKS_UNLIMITED); if ((rv != items[i].rcode) || (bytesRead != items[i].sent)) { TC_ERROR("Expected return value %d, got %d\n" "Expected bytesRead = %d, got %d\n", items[i].rcode, rv, 0, bytesRead); return TC_FAIL; } } return TC_PASS; }
int pipePutTimeoutHelper(void) { int i; /* loop counter */ int rv; /* return value from task_pipe_get_wait_timeout() */ int bytesRead; /* # of bytes read from task_pipe_get_wait_timeout() */ (void)task_sem_take_wait(altSem); /* Wait until test is ready */ /* 1. task_pipe_get_wait_timeout() will force a context switch to RegressionTask() */ rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, PIPE_SIZE, &bytesRead, _ALL_N, ONE_SECOND); if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) { TC_ERROR("Expected return code %d, not %d\n" "Expected %d bytes to be read, not %d\n", RC_OK, rv, PIPE_SIZE, bytesRead); return TC_FAIL; } /* 2. task_pipe_get_wait_timeout() will force a context switch to RegressionTask(). */ rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, PIPE_SIZE, &bytesRead, _1_TO_N, ONE_SECOND); if ((rv != RC_OK) || (bytesRead != PIPE_SIZE)) { TC_ERROR("Expected return code %d, not %d\n" "Expected %d bytes to be read, not %d\n", RC_OK, rv, PIPE_SIZE, bytesRead); return TC_FAIL; } /* * Before emptying the pipe, check that task_pipe_get_wait_timeout() fails when * using the _0_TO_N option. */ rv = task_pipe_get_wait_timeout(pipeId, rxBuffer, PIPE_SIZE / 2, &bytesRead, _0_TO_N, ONE_SECOND); if (rv != RC_FAIL) { TC_ERROR("Expected return code %d, not %d\n", RC_FAIL, rv); return TC_FAIL; } /* 3. Empty the pipe in two reads */ for (i = 0; i < 2; i++) { rv = task_pipe_get(pipeId, rxBuffer, PIPE_SIZE / 2, &bytesRead, _0_TO_N); if ((rv != RC_OK) || (bytesRead != PIPE_SIZE / 2)) { TC_ERROR("Expected return code %d, not %d\n" "Expected %d bytes to be read, not %d\n", RC_OK, rv, PIPE_SIZE / 2, bytesRead); return TC_FAIL; } } task_sem_give(regSem); return TC_PASS; }
int pipeGetTest(void) { int i; /* loop counter */ int j; /* loop counter */ int rv; /* return code from task_pipe_get() */ int bytesRead; /* # of bytes read from task_pipe_get() */ int size[] ={1, PIPE_SIZE - 1, PIPE_SIZE, PIPE_SIZE + 1}; K_PIPE_OPTION options[] = {_ALL_N, _1_TO_N}; for (j = 0; j < ARRAY_SIZE(options); j++) { for (i = 0; i < ARRAY_SIZE(size); i++) { rv = task_pipe_get(pipeId, rxBuffer, size[i], &bytesRead, options[j]); if (rv != RC_FAIL) { TC_ERROR("Expected return code %d, not %d\n", RC_FAIL, rv); return TC_FAIL; } } } for (i = 0; i < ARRAY_SIZE(size); i++) { rv = task_pipe_get(pipeId, rxBuffer, size[i], &bytesRead, _0_TO_N); if (rv != RC_OK) { TC_ERROR("Expected return code %d, not %d\n", RC_OK, rv); return TC_FAIL; } if (bytesRead != 0) { TC_ERROR("Expected <bytesRead> %d, not %d\n", 0, bytesRead); return TC_FAIL; } } return TC_PASS; }
int pipeGetTimeoutTest(void) { int i; /* loop counter */ int rv; /* return value from task_pipe_get() */ int bytesRead; /* # of bytes read from task_pipe_get() */ for (i = 0; i < ARRAY_SIZE(timeout_cases); i++) { rv = task_pipe_get(pipeId, rxBuffer, timeout_cases[i].size, &bytesRead, timeout_cases[i].options, ONE_SECOND); if ((rv != timeout_cases[i].rcode) || (bytesRead != timeout_cases[i].sent)) { TC_ERROR("Expected return code %d, got %d\n" "Expected <bytesRead> %d, got %d\n" "Iteration %d\n", timeout_cases[i].rcode, rv, timeout_cases[i].sent, bytesRead, i + 1); return TC_FAIL; } } return TC_PASS; }
int pipePutHelperWork(SIZE_EXPECT *singleItems, int nSingles, SIZE_EXPECT *manyItems, int nMany) { int i; /* loop counter */ int j; /* loop counter */ int rv; /* value returned from task_pipe_get() */ int index; /* index to corrupted byte in buffer */ int bytesReceived; /* number of bytes received */ for (i = 0; i < nSingles; i++) { (void)task_sem_take_wait(altSem); for (j = 0; j < sizeof(rxBuffer); j++) { rxBuffer[j] = 0; } rv = task_pipe_get(pipeId, rxBuffer, singleItems[i].size, &bytesReceived, singleItems[i].options); if (rv != singleItems[i].rcode) { TC_ERROR("task_pipe_get(%d bytes) : Expected %d not %d.\n" " bytesReceived = %d\n", singleItems[i].size, singleItems[i].rcode, rv, bytesReceived); return TC_FAIL; } if (bytesReceived != singleItems[i].sent) { TC_ERROR("task_pipe_get(%d) : " "Expected %d bytes to be received, not %d\n", singleItems[i].size, singleItems[i].sent, bytesReceived); return TC_FAIL; } index = receiveBufferCheck(rxBuffer, bytesReceived); if (index != bytesReceived) { TC_ERROR("pipePutHelper: rxBuffer[%d] is %d, not %d\n", index, rxBuffer[index], index); return TC_FAIL; } task_sem_give(counterSem); task_sem_give(regSem); } /* * Get items from the pipe. There should be more than one item * stored in it. */ (void)task_sem_take_wait(altSem); for (i = 0; i < nMany; i++) { for (j = 0; j < sizeof(rxBuffer); j++) { rxBuffer[j] = 0; } rv = task_pipe_get(pipeId, rxBuffer, manyItems[i].size, &bytesReceived, manyItems[i].options); if (rv != manyItems[i].rcode) { TC_ERROR("task_pipe_get(%d bytes) : Expected %d not %d.\n" " bytesReceived = %d, iteration: %d\n", manyItems[i].size, manyItems[i].rcode, rv, bytesReceived, i+1); return TC_FAIL; } if (bytesReceived != manyItems[i].sent) { TC_ERROR("task_pipe_get(%d) : " "Expected %d bytes to be received, not %d\n", manyItems[i].size, manyItems[i].sent, bytesReceived); return TC_FAIL; } index = receiveBufferCheck(rxBuffer, bytesReceived); if (index != bytesReceived) { TC_ERROR("pipeGetHelper: rxBuffer[%d] is %d, not %d\n", index, rxBuffer[index], index); return TC_FAIL; } task_sem_give(counterSem); } task_sem_give(regSem); /* Wake the RegressionTask */ return TC_PASS; }