예제 #1
0
파일: sema.c 프로젝트: 32bitmicro/zephyr
/**
 *
 * @brief Test semaphore signaling from fiber
 *
 * Routine starts a fiber and does the following tests:
 * - fiber signals the semaphore N times, task checks that task_sem_count_get is N
 * - task waits on a semaphore and fiber signals it
 * - task waits on a semaphore group and fiber signals each of them once. Task
 *   checks which of the semaphores has been signaled
 *
 * See also: testFiber.c
 *
 * @return TC_PASS on success or TC_FAIL on failure
 */
static int simpleFiberSemTest(void)
{
	int signalCount;
	int status;
	int i;
	ksem_t  sema;

	task_sem_reset(simpleSem);
	task_sem_group_reset(semList);

	/* let the fiber signal the semaphore and wait on it */
	releaseTestFiber();
	status = task_sem_take(simpleSem, OBJ_TIMEOUT);
	if (status != RC_OK) {
		TC_ERROR("task_sem_take() error.  Expected %d, got %d\n",
				 RC_OK, status);
		return TC_FAIL;
	}

	/* release the fiber and let it signal the semaphore N_TESTS times */
	releaseTestFiber();
	signalCount = task_sem_count_get(simpleSem);
	if (signalCount != N_TESTS) {
		TC_ERROR("<signalCount> error.  Expected %d, got %d\n",
				 N_TESTS, signalCount);
		return TC_FAIL;
	}

	/* wait on the semaphore group while the fiber signals each semaphore in it */
	for (i = 0; semList[i] != ENDLIST; i++) {
		releaseTestFiber();
		sema = task_sem_group_take(semList, OBJ_TIMEOUT);
		if (sema != semList[i]) {
			TC_ERROR("task_sem_group_take() error.  Expected %d, not %d\n",
					 (int) semList[i], (int) sema);
			return TC_FAIL;
		}
	}
	return TC_PASS;
}
예제 #2
0
void pipe_test(void)
{
	uint32_t	putsize;
	int         getsize;
	uint32_t	puttime[3];
	int		putcount;
	int		pipe;
	kpriority_t	TaskPrio;
	int		prio;
	GetInfo	getinfo;

	task_sem_reset(SEM0);
	task_sem_give(STARTRCV);

	/* action: */

	/* non-buffered operation, matching (ALL_N) */
	PRINT_STRING(dashline, output_file);
	PRINT_STRING("|                   "
				 "P I P E   M E A S U R E M E N T S"
				 "                         |\n", output_file);
	PRINT_STRING(dashline, output_file);
	PRINT_STRING("| Send data into a pipe towards a "
				 "receiving high priority task and wait       |\n",
				 output_file);
	PRINT_STRING(dashline, output_file);
	PRINT_STRING("|                          "
				 "matching sizes (_ALL_N)"
				 "                            |\n", output_file);
	PRINT_STRING(dashline, output_file);
	PRINT_ALL_TO_N_HEADER_UNIT();
	PRINT_STRING(dashline, output_file);
	PRINT_STRING("| put | get |  no buf  | small buf| big buf  |"
				 "  no buf  | small buf| big buf  |\n", output_file);
	PRINT_STRING(dashline, output_file);

	for (putsize = 8; putsize <= MESSAGE_SIZE_PIPE; putsize <<= 1) {
		for (pipe = 0; pipe < 3; pipe++) {
			putcount = NR_OF_PIPE_RUNS;
			pipeput(TestPipes[pipe], _ALL_N, putsize, putcount,
				 &puttime[pipe]);

			task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */
		}
		PRINT_ALL_TO_N();
	}
	PRINT_STRING(dashline, output_file);

	/* Test with two different sender priorities */
	for (prio = 0; prio < 2; prio++) {
		/* non-buffered operation, non-matching (1_TO_N) */
		if (prio == 0) {
			PRINT_STRING("|                      "
						 "non-matching sizes (1_TO_N) to higher priority"
						 "         |\n", output_file);
			TaskPrio = task_priority_get();
		}
		if (prio == 1) {
			PRINT_STRING("|                      "
						 "non-matching sizes (1_TO_N) to lower priority"
						 "          |\n", output_file);
			task_priority_set(task_id_get(), TaskPrio - 2);
		}
		PRINT_STRING(dashline, output_file);
		PRINT_1_TO_N_HEADER();
		PRINT_STRING("| put | get |  no buf  | small buf| big buf  |  "
					 "no buf  | small buf| big buf  |\n", output_file);
		PRINT_STRING(dashline, output_file);

		for (putsize = 8; putsize <= (MESSAGE_SIZE_PIPE); putsize <<= 1) {
			putcount = MESSAGE_SIZE_PIPE / putsize;
			for (pipe = 0; pipe < 3; pipe++) {
				pipeput(TestPipes[pipe], _1_TO_N, putsize,
						 putcount, &puttime[pipe]);
				/* size*count == MESSAGE_SIZE_PIPE */
				task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */
				getsize = getinfo.size;
			}
			PRINT_1_TO_N();
		}
		PRINT_STRING(dashline, output_file);
		task_priority_set(task_id_get(), TaskPrio);
	}
}
예제 #3
0
파일: sema.c 프로젝트: 32bitmicro/zephyr
int simpleSemaTest(void)
{
	int  signalCount;
	int  i;
	int  status;

	/*
	 * Signal the semaphore several times from an ISR.  After each signal,
	 * check the signal count.
	 */

	for (i = 0; i < 5; i++) {
		trigger_isrSemaSignal(simpleSem);

		task_sleep(10);     /* Time for low priority task to run. */
		signalCount = task_sem_count_get(simpleSem);
		if (signalCount != (i + 1)) {
			TC_ERROR("<signalCount> error.  Expected %d, got %d\n",
					 i + 1, signalCount);
			return TC_FAIL;
		}
	}

	/*
	 * Signal the semaphore several times from a task.  After each signal,
	 * check the signal count.
	 */

	for (i = 5; i < 10; i++) {
		task_sem_give(simpleSem);

		signalCount = task_sem_count_get(simpleSem);
		if (signalCount != (i + 1)) {
			TC_ERROR("<signalCount> error.  Expected %d, got %d\n",
					 i + 1, signalCount);
			return TC_FAIL;
		}
	}

	/*
	 * Test the semaphore without wait.  Check the signal count after each
	 * attempt (it should be decrementing by 1 each time).
	 */

	for (i = 9; i >= 4; i--) {
		status = task_sem_take(simpleSem, TICKS_NONE);
		if (status != RC_OK) {
			TC_ERROR("task_sem_take(SIMPLE_SEM) error.  Expected %d, not %d.\n",
					 RC_OK, status);
			return TC_FAIL;
		}

		signalCount = task_sem_count_get(simpleSem);
		if (signalCount != i) {
			TC_ERROR("<signalCount> error.  Expected %d, not %d\n",
					 i, signalCount);
			return TC_FAIL;
		}
	}

	task_sem_reset(simpleSem);

	/*
	 * The semaphore's signal count should now be zero (0).  Test the
	 * semaphore without wait.  It should fail.
	 */

	for (i = 0; i < 10; i++) {
		status = task_sem_take(simpleSem, TICKS_NONE);
		if (status != RC_FAIL) {
			TC_ERROR("task_sem_take(SIMPLE_SEM) error.  Expected %d, got %d.\n",
					 RC_FAIL, status);
			return TC_FAIL;
		}

		signalCount = task_sem_count_get(simpleSem);
		if (signalCount != 0) {
			TC_ERROR("<signalCount> error.  Expected %d, not %d\n",
					 0, signalCount);
			return TC_FAIL;
		}
	}

	return TC_PASS;
}
예제 #4
0
파일: sema_b.c 프로젝트: 32bitmicro/zephyr
/**
 *
 * @brief Semaphore signal speed test
 *
 * @return N/A
 */
void sema_test(void)
{
	uint32_t et; /* elapsed Time */
	int i;

	PRINT_STRING(dashline, output_file);
	et = BENCH_START();
	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
		task_sem_give(SEM0);
	}
	et = TIME_STAMP_DELTA_GET(et);
	check_result();

	PRINT_F(output_file, FORMAT, "signal semaphore",
			SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));

	task_sem_reset(SEM1);
	task_sem_give(STARTRCV);

	et = BENCH_START();
	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
		task_sem_give(SEM1);
	}
	et = TIME_STAMP_DELTA_GET(et);
	check_result();

	PRINT_F(output_file, FORMAT, "signal to waiting high pri task",
			SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));

	et = BENCH_START();
	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
		task_sem_give(SEM1);
	}
	et = TIME_STAMP_DELTA_GET(et);
	check_result();

	PRINT_F(output_file, FORMAT,
			"signal to waiting high pri task, with timeout",
			SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));

	et = BENCH_START();
	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
		task_sem_give(SEM2);
	}
	et = TIME_STAMP_DELTA_GET(et);
	check_result();

	PRINT_F(output_file, FORMAT, "signal to waitm (2)",
			SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));

	et = BENCH_START();
	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
		task_sem_give(SEM2);
	}
	et = TIME_STAMP_DELTA_GET(et);
	check_result();

	PRINT_F(output_file, FORMAT, "signal to waitm (2), with timeout",
			SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));

	et = BENCH_START();
	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
		task_sem_give(SEM3);
	}
	et = TIME_STAMP_DELTA_GET(et);
	check_result();

	PRINT_F(output_file, FORMAT, "signal to waitm (3)",
			SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));

	et = BENCH_START();
	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
		task_sem_give(SEM3);
	}
	et = TIME_STAMP_DELTA_GET(et);
	check_result();

	PRINT_F(output_file, FORMAT, "signal to waitm (3), with timeout",
			SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));

	et = BENCH_START();
	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
		task_sem_give(SEM4);
	}
	et = TIME_STAMP_DELTA_GET(et);
	check_result();

	PRINT_F(output_file, FORMAT, "signal to waitm (4)",
			SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));

	et = BENCH_START();
	for (i = 0; i < NR_OF_SEMA_RUNS; i++) {
		task_sem_give(SEM4);
	}
	et = TIME_STAMP_DELTA_GET(et);
	check_result();

	PRINT_F(output_file, FORMAT, "signal to waitm (4), with timeout",
			SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS));
}
예제 #5
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;
}