示例#1
0
文件: pipe.c 项目: 32bitmicro/zephyr
int pipePutWaitTest(void)
{
	int  rv;            /* return code from task_pipe_put() */
	int  bytesWritten;  /* # of bytes written to pipe */

	/* 1. Fill the pipe */
	rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
							&bytesWritten, _ALL_N, TICKS_UNLIMITED);
	if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
		TC_ERROR("Return code: expected %d, got %d\n"
				 "Bytes written: expected %d, got %d\n",
				 RC_OK, rv, PIPE_SIZE, bytesWritten);
		return TC_FAIL;
	}

	task_sem_give(altSem);    /* Wake the alternate task */

	/* 2. task_pipe_put() will force a context switch to AlternateTask(). */
	rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
						&bytesWritten, _ALL_N, TICKS_UNLIMITED);
	if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
		TC_ERROR("Return code: expected %d, got %d\n"
				 "Bytes written: expected %d, got %d\n",
				 RC_OK, rv, PIPE_SIZE, bytesWritten);
		return TC_FAIL;
	}

	/* 3. task_pipe_put() will force a context switch to AlternateTask(). */
	rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
						&bytesWritten, _1_TO_N, TICKS_UNLIMITED);
	if ((rv != RC_OK) || (bytesWritten != PIPE_SIZE)) {
		TC_ERROR("Return code: expected %d, got %d\n"
				 "Bytes written: expected %d, got %d\n",
				 RC_OK, rv, PIPE_SIZE, bytesWritten);
		return TC_FAIL;
	}

	/* This should return immediately as _0_TO_N with a wait is an error. */
	rv = task_pipe_put(pipeId, txBuffer, PIPE_SIZE,
						&bytesWritten, _0_TO_N, TICKS_UNLIMITED);
	if ((rv != RC_FAIL) || (bytesWritten != 0)) {
		TC_ERROR("Return code: expected %d, got %d\n"
				 "Bytes written: expected %d, got %d\n",
				 RC_FAIL, rv, 0, bytesWritten);
		return TC_FAIL;
	}

	/* Wait for AlternateTask()'s pipePutWaitHelper() to finish */
	(void)task_sem_take(regSem, TICKS_UNLIMITED);

	return TC_PASS;
}
示例#2
0
文件: pipe.c 项目: 32bitmicro/zephyr
int pipeGetWaitHelperWork(SIZE_EXPECT *items, int nItems)
{
	int  i;          /* loop counter */
	int  rv;         /* return value from task_pipe_put() */
	int  bytesSent;  /* # of bytes sent to task_pipe_put() */

	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().
		 */

		bytesSent = 0;
		rv = task_pipe_put(pipeId, rxBuffer, items[i].size,
						   &bytesSent, items[i].options,
						   TICKS_UNLIMITED);
		if ((rv != items[i].rcode) || (bytesSent != items[i].sent)) {
			TC_ERROR("Expected return value %d, got %d\n"
					 "Expected bytesSent = %d, got %d\n",
					 items[i].rcode, rv, 0, bytesSent);
			return TC_FAIL;
		}
	}

	return TC_PASS;
}
示例#3
0
int pipePutTestWork(SIZE_EXPECT *singleItems, int nSingles,
					SIZE_EXPECT *manyItems, int nMany)
{
	int  rv;                     /* return code from task_pipe_put() */
	int  i;                      /* loop counter */
	int  bytesWritten;           /* # of bytes sent to pipe */
	int nitem;           /* expected item number processed by the other task */

	task_sem_reset(counterSem);

	for (i = 0; i < nSingles; i++) {
		rv = task_pipe_put(pipeId, txBuffer, singleItems[i].size,
						   &bytesWritten, singleItems[i].options);
		if (rv != singleItems[i].rcode) {
			TC_ERROR("task_pipe_put(%d) : Expected %d not %d.\n"
					 "    bytesWritten = %d, Iteration: %d\n",
					 singleItems[i].size, singleItems[i].rcode,
					 rv, bytesWritten, i + 1);
			return TC_FAIL;
		}

		if (bytesWritten != singleItems[i].sent) {
			TC_ERROR("task_pipe_put(%d) : "
					 "Expected %d bytes to be written, not %d\n",
					 singleItems[i].size, singleItems[i].sent, bytesWritten);
			return TC_FAIL;
		}

		task_sem_give(altSem);
		(void)task_sem_take_wait(regSem);

		nitem = task_sem_count_get(counterSem) - 1;
		if (nitem != i) {
			TC_ERROR("Expected item number is %d, not %d\n",
					 i, nitem);
			return TC_FAIL;
		}
	}

	/* This time, more than one item will be in the pipe at a time */

	task_sem_reset(counterSem);

	for (i = 0; i < nMany; i++) {
		rv = task_pipe_put(pipeId, txBuffer, manyItems[i].size,
						   &bytesWritten, manyItems[i].options);
		if (rv != manyItems[i].rcode) {
			TC_ERROR("task_pipe_put(%d) : Expected %d not %d.\n"
					 "    bytesWritten = %d, iteration: %d\n",
					 manyItems[i].size, manyItems[i].rcode,
					 rv, bytesWritten, i + 1);
			return TC_FAIL;
		}

		if (bytesWritten != manyItems[i].sent) {
			TC_ERROR("task_pipe_put(%d) : "
					 "Expected %d bytes to be written, not %d\n",
					 manyItems[i].size, manyItems[i].sent, bytesWritten);
			return TC_FAIL;
		}
	}

	task_sem_give(altSem);   /* Wake the alternate task */
	/* wait for other task reading all the items from pipe */
	(void)task_sem_take_wait(regSem);

	if (task_sem_count_get(counterSem) != nMany) {
		TC_ERROR("Expected number of items %d, not %d\n",
				 nMany, task_sem_count_get(counterSem));
		return TC_FAIL;
	}

	return TC_PASS;
}