Exemplo n.º 1
0
void testTaskStackPopW(void)
{
	uint32_t  data;     /* data used to put and get from the stack queue */
	int rc;

	PRINT_LINE;
	TC_PRINT("Test STACK Pop Wait Interfaces\n\n");
	data = myData[0];
	TC_PRINT("TASK  STACK Push to queue2: %d\n", data);
	nano_task_stack_push(&nanoStackObj2, data);

	/* Start fiber */
	task_fiber_start(&fiberStack2[0], STACKSIZE,
					 (nano_fiber_entry_t) fiber2, 0, 0, 7, 0);

	rc = nano_task_stack_pop(&nanoStackObj, &data, TICKS_UNLIMITED);
	TC_PRINT("TASK STACK Pop from queue1: %d\n", data);
	/* Verify results */
	if ((rc == 0) || (data != myData[1])) {
		retCode = TC_FAIL;
		TCERR2;
		return;
	}

	data = myData[2];
	TC_PRINT("TASK STACK Push to queue2: %d\n", data);
	nano_task_stack_push(&nanoStackObj2, data);

	TC_END_RESULT(retCode);
}  /* testTaskStackPopW */
Exemplo n.º 2
0
void main(void)
{
	int         count = 0;  /* counter */
	uint32_t    data;       /* data used to put and get from the stack queue */
	int         rc;         /* return code */

	TC_START("Test Nanokernel STACK");

	/* Initialize data */
	initData();

	/* Initialize the queues and semaphore */
	initNanoObjects();

	/* Start fiber3 */
	task_fiber_start(&fiberStack3[0], STACKSIZE, (nano_fiber_entry_t) fiber3,
					 0, 0, 7, 0);
	/*
	 * While fiber3 blocks (for one second), wait for an item to be pushed
	 * onto the stack so that it can be popped.  This will put the nanokernel
	 * into an idle state.
	 */

	rc = nano_task_stack_pop(&nanoStackObj, &data, TICKS_UNLIMITED);
	if ((rc == 0) || (data != myData[0])) {
		TC_ERROR("nano_task_stack_pop(TICKS_UNLIMITED) expected 0x%x, but got 0x%x\n",
				 myData[0], data);
		retCode = TC_FAIL;
		goto exit;
	}

	/* Put data */
	TC_PRINT("Test Task STACK Push\n");
	TC_PRINT("\nTASK STACK Put Order: ");
	for (int i=0; i<NUM_STACK_ELEMENT; i++) {
		nano_task_stack_push(&nanoStackObj, myData[i]);
		TC_PRINT(" %d,", myData[i]);
	}
	TC_PRINT("\n");

	PRINT_LINE;

	/* Start fiber */
	task_fiber_start(&fiberStack1[0], STACKSIZE,
					 (nano_fiber_entry_t) fiber1, 0, 0, 7, 0);

	if (retCode == TC_FAIL) {
		goto exit;
	}

	/*
	 * Wait for fiber1 to complete execution. (Using a semaphore gives
	 * the fiber the freedom to do blocking-type operations if it wants to.)
	 *
	 */
	nano_task_sem_take(&nanoSemObj, TICKS_UNLIMITED);
	TC_PRINT("Test Task STACK Pop\n");

	/* Get all data */
	while (nano_task_stack_pop(&nanoStackObj, &data, TICKS_NONE) != 0) {
		TC_PRINT("TASK STACK Pop: count = %d, data is %d\n", count, data);
		if ((count >= NUM_STACK_ELEMENT) || (data != myData[count])) {
			TCERR1(count);
			retCode = TC_FAIL;
			goto exit;
		}
		count++;
	}

	/* Test Task Stack Pop Wait interfaces*/
	testTaskStackPopW();

	if (retCode == TC_FAIL) {
		goto exit;
	}

	PRINT_LINE;

	/* Test ISR interfaces */
	testIsrStackFromTask();
	PRINT_LINE;

exit:
	TC_END_RESULT(retCode);
	TC_END_REPORT(retCode);
}
Exemplo n.º 3
0
int stack_test(void)
{
	uint32_t t;
	int i = 0;
	int return_value = 0;

	/* test get wait & put fiber functions */
	fprintf(output_file, sz_test_case_fmt,
			"Stack #1");
	fprintf(output_file, sz_description,
			"\n\tnano_stack_init"
			"\n\tnano_fiber_stack_pop_wait"
			"\n\tnano_fiber_stack_push");
	printf(sz_test_start_fmt);

	stack_test_init();

	t = BENCH_START();

	task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0,
					 NUMBER_OF_LOOPS, 3, 0);
	task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber2, (int) &i,
					 NUMBER_OF_LOOPS, 3, 0);

	t = TIME_STAMP_DELTA_GET(t);

	return_value += check_result(i, t);

	/* test get/yield & put fiber functions */
	fprintf(output_file, sz_test_case_fmt,
			"Stack #2");
	fprintf(output_file, sz_description,
			"\n\tnano_stack_init"
			"\n\tnano_fiber_stack_pop_wait"
			"\n\tnano_fiber_stack_pop"
			"\n\tnano_fiber_stack_push"
			"\n\tfiber_yield");
	printf(sz_test_start_fmt);

	stack_test_init();

	t = BENCH_START();

	i = 0;
	task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0,
					 NUMBER_OF_LOOPS, 3, 0);
	task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber3, (int) &i,
					 NUMBER_OF_LOOPS, 3, 0);

	t = TIME_STAMP_DELTA_GET(t);

	return_value += check_result(i, t);

	/* test get wait & put fiber/task functions */
	fprintf(output_file, sz_test_case_fmt,
			"Stack #3");
	fprintf(output_file, sz_description,
			"\n\tnano_stack_init"
			"\n\tnano_fiber_stack_pop_wait"
			"\n\tnano_fiber_stack_push"
			"\n\tnano_task_stack_pop_wait"
			"\n\tnano_task_stack_push");
	printf(sz_test_start_fmt);

	stack_test_init();

	t = BENCH_START();

	task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0,
					 NUMBER_OF_LOOPS, 3, 0);
	for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) {
		uint32_t data;
		data = 2 * i;
		nano_task_stack_push(&nano_stack_1, data);
		data = 2 * i + 1;
		nano_task_stack_push(&nano_stack_1, data);

		data = nano_task_stack_pop_wait(&nano_stack_2);
		if (data != 2 * i + 1) {
			break;
		}
		data = nano_task_stack_pop_wait(&nano_stack_2);
		if (data != 2 * i) {
			break;
		}
	}

	t = TIME_STAMP_DELTA_GET(t);

	return_value += check_result(i * 2, t);

	return return_value;
}