int testSemWait(void) { if (fiberDetectedFailure != 0) { TC_ERROR(" *** Failure detected in the fiber."); return TC_FAIL; } nano_task_sem_give(&testSem); /* Wake the fiber. */ if (semTestState != STS_TASK_WOKE_FIBER) { TC_ERROR(" *** Expected task to wake fiber. It did not.\n"); return TC_FAIL; } TC_PRINT("Semaphore from the task woke the fiber\n"); nano_task_sem_take(&testSem, TICKS_UNLIMITED); /* Wait on <testSem> */ if (semTestState != STS_FIBER_WOKE_TASK) { TC_ERROR(" *** Expected fiber to wake task. It did not.\n"); return TC_FAIL; } TC_PRINT("Semaphore from the fiber woke the task\n"); nano_task_sem_take(&testSem, TICKS_UNLIMITED); /* Wait on <testSem> again. */ if (semTestState != STS_ISR_WOKE_TASK) { TC_ERROR(" *** Expected ISR to wake task. It did not.\n"); return TC_FAIL; } TC_PRINT("Semaphore from the ISR woke the task.\n"); return TC_PASS; }
int testSemTaskNoWait(void) { int i; /* loop counter */ TC_PRINT("Giving and taking a semaphore in a task (non-blocking)\n"); /* * Give the semaphore many times and then make sure that it can only be * taken that many times. */ for (i = 0; i < 32; i++) { nano_task_sem_give(&testSem); } for (i = 0; i < 32; i++) { if (nano_task_sem_take(&testSem, TICKS_NONE) != 1) { TC_ERROR(" *** Expected nano_task_sem_take() to succeed, not fail\n"); goto errorReturn; } } if (nano_task_sem_take(&testSem, TICKS_NONE) != 0) { TC_ERROR(" *** Expected nano_task_sem_take() to fail, not succeed!\n"); goto errorReturn; } return TC_PASS; errorReturn: return TC_FAIL; }
static int do_test_multiple_waiters(void) { int ii; /* pend all fibers one the same lifo */ for (ii = 0; ii < NUM_WAITERS; ii++) { task_fiber_start(fiber_multi_waiters_stacks[ii], FIBER_STACKSIZE, fiber_multi_waiters, ii, 0, FIBER_PRIORITY, 0); } /* wake up all the fibers: the task is preempted each time */ for (ii = 0; ii < NUM_WAITERS; ii++) { nano_task_lifo_put(&multi_waiters, &multi_waiters_items[ii]); } /* reply_multi_waiters will have been given once for each fiber */ for (ii = 0; ii < NUM_WAITERS; ii++) { if (!nano_task_sem_take(&reply_multi_waiters, TICKS_NONE)) { TC_ERROR(" *** Cannot take sem supposedly given by waiters.\n"); return TC_FAIL; } } TC_PRINT("Task took multi-waiter reply semaphore %d times, as expected.\n", NUM_WAITERS); if (nano_task_lifo_get(&multi_waiters, TICKS_NONE)) { TC_ERROR(" *** multi_waiters should have been empty.\n"); return TC_FAIL; } return TC_PASS; }
void RegressionTaskEntry(void) { int tcRC; nano_sem_init(&test_nano_timers_sem); PRINT_DATA("Starting timer tests\n"); PRINT_LINE; task_fiber_start(test_nano_timers_stack, 512, test_nano_timers, 0, 0, 5, 0); /* Test the task_timer_alloc() API */ TC_PRINT("Test the allocation of timers\n"); tcRC = testLowTimerGet(); if (tcRC != TC_PASS) { goto exitRtn; } TC_PRINT("Test the one shot feature of a timer\n"); tcRC = testLowTimerOneShot(); if (tcRC != TC_PASS) { goto exitRtn; } TC_PRINT("Test that a timer does not start\n"); tcRC = testLowTimerDoesNotStart(); if (tcRC != TC_PASS) { goto exitRtn; } TC_PRINT("Test the periodic feature of a timer\n"); tcRC = testLowTimerPeriodicity(); if (tcRC != TC_PASS) { goto exitRtn; } TC_PRINT("Test the stopping of a timer\n"); tcRC = testLowTimerStop(); if (tcRC != TC_PASS) { goto exitRtn; } TC_PRINT("Verifying the nanokernel timer fired\n"); if (!nano_task_sem_take(&test_nano_timers_sem)) { tcRC = TC_FAIL; goto exitRtn; } TC_PRINT("Verifying the nanokernel timeouts worked\n"); tcRC = task_sem_take_wait_timeout(test_nano_timeouts_sem, SECONDS(5)); tcRC = tcRC == RC_OK ? TC_PASS : TC_FAIL; exitRtn: TC_END_RESULT(tcRC); TC_END_REPORT(tcRC); }
void main(void) { int status = TC_FAIL; uint32_t start_tick; uint32_t end_tick; TC_START("Test Nanokernel Sleep and Wakeup APIs\n"); test_objects_init(); test_fiber_id = task_fiber_start(test_fiber_stack, FIBER_STACKSIZE, test_fiber, 0, 0, TEST_FIBER_PRIORITY, 0); TC_PRINT("Test fiber started: id = 0x%x\n", test_fiber_id); helper_fiber_id = task_fiber_start(helper_fiber_stack, FIBER_STACKSIZE, helper_fiber, 0, 0, HELPER_FIBER_PRIORITY, 0); TC_PRINT("Helper fiber started: id = 0x%x\n", helper_fiber_id); /* Activate test_fiber */ nano_task_sem_give(&test_fiber_sem); /* Wait for test_fiber to activate us */ nano_task_sem_take(&task_sem, TICKS_UNLIMITED); /* Wake the test fiber */ task_fiber_wakeup(test_fiber_id); if (test_failure) { goto done_tests; } TC_PRINT("Testing nanokernel task_sleep()\n"); align_to_tick_boundary(); start_tick = sys_tick_get_32(); task_sleep(ONE_SECOND); end_tick = sys_tick_get_32(); if (end_tick - start_tick != ONE_SECOND) { TC_ERROR("task_sleep() slept for %d ticks, not %d\n", end_tick - start_tick, ONE_SECOND); goto done_tests; } status = TC_PASS; done_tests: TC_END_REPORT(status); }
int nano_task_sem_take_wait_timeout(struct nano_sem *sem, int32_t timeout_in_ticks) { int64_t cur_ticks, limit; unsigned int key; if (unlikely(TICKS_UNLIMITED == timeout_in_ticks)) { nano_task_sem_take_wait(sem); return 1; } if (unlikely(TICKS_NONE == timeout_in_ticks)) { return nano_task_sem_take(sem); } key = irq_lock_inline(); cur_ticks = nano_tick_get(); limit = cur_ticks + timeout_in_ticks; while (cur_ticks < limit) { /* * Predict that the branch will be taken to break out of the loop. * There is little cost to a misprediction since that leads to idle. */ if (likely(sem->nsig > 0)) { sem->nsig--; irq_unlock_inline(key); return 1; } /* see explanation in nano_stack.c:nano_task_stack_pop_wait() */ nano_cpu_atomic_idle(key); key = irq_lock_inline(); cur_ticks = nano_tick_get(); } irq_unlock_inline(key); return 0; }
int taskLifoNonWaitTest(void) { void *data; /* ptr to data retrieved from LIFO */ /* * The fiber is presently waiting for <fiberWaitSem>. Populate the LIFO * before waking the fiber. */ TC_PRINT("Fiber to get LIFO items without waiting\n"); nano_task_lifo_put(&test_lifo, &lifoItem[2]); nano_task_lifo_put(&test_lifo, &lifoItem[3]); nano_task_sem_give(&fiberWaitSem); /* Wake the fiber */ /* Check that fiber received the items correctly */ if (fiberDetectedFailure) { TC_ERROR(" *** nano_task_lifo_put()/nano_fiber_lifo_get() failure\n"); return TC_FAIL; } /* Wait for the fiber to be ready */ nano_task_sem_take(&taskWaitSem, TICKS_UNLIMITED); data = nano_task_lifo_get(&test_lifo, TICKS_NONE); if (data != (void *) &lifoItem[1]) { TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n"); return TC_FAIL; } data = nano_task_lifo_get(&test_lifo, TICKS_NONE); if (data != (void *) &lifoItem[0]) { TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n"); return TC_FAIL; } data = nano_task_lifo_get(&test_lifo, TICKS_NONE); if (data != NULL) { TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n"); return TC_FAIL; } /* * Software interrupts have been configured so that when invoked, * the ISR will add an item to the LIFO. The fiber (when unblocked) * trigger software interrupts to get the items from the LIFO from * within an ISR. * * Populate the LIFO. */ TC_PRINT("ISR to get LIFO items without waiting\n"); isrLifoInfo.data = &lifoItem[3]; _trigger_nano_isr_lifo_put(); isrLifoInfo.data = &lifoItem[1]; _trigger_nano_isr_lifo_put(); isrLifoInfo.data = NULL; /* Force NULL to ensure [data] changes */ nano_task_sem_give(&fiberWaitSem); /* Wake the fiber */ if (fiberDetectedFailure) { TC_ERROR(" *** nano_isr_lifo_put()/nano_isr_lifo_get() failure\n"); return TC_FAIL; } return TC_PASS; }
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); }
static int test_timeout(void) { int32_t timeout; int rv; int ii; struct timeout_order_data *data; /* * sys_thread_busy_wait() is currently unsupported for ARM */ #ifndef CONFIG_ARM /* test sys_thread_busy_wait() */ TC_PRINT("Testing sys_thread_busy_wait()\n"); timeout = 2; task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_busy_wait, (int)timeout, 0, FIBER_PRIORITY, 0); rv = nano_task_sem_take(&reply_timeout, timeout + 2); if (!rv) { rv = TC_FAIL; TC_ERROR(" *** task timed out waiting for sys_thread_busy_wait()\n"); return TC_FAIL; } #endif /* CONFIG_ARM */ /* test fiber_sleep() */ TC_PRINT("Testing fiber_sleep()\n"); timeout = 5; task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_sleep, (int)timeout, 0, FIBER_PRIORITY, 0); rv = nano_task_sem_take(&reply_timeout, timeout + 5); if (!rv) { rv = TC_FAIL; TC_ERROR(" *** task timed out waiting for fiber on fiber_sleep().\n"); return TC_FAIL; } /* test fiber_delayed_start() without cancellation */ TC_PRINT("Testing fiber_delayed_start() without cancellation\n"); for (ii = 0; ii < NUM_TIMEOUT_FIBERS; ii++) { (void)task_fiber_delayed_start(timeout_stacks[ii], FIBER_STACKSIZE, delayed_fiber, ii, 0, 5, 0, timeout_order_data[ii].timeout); } for (ii = 0; ii < NUM_TIMEOUT_FIBERS; ii++) { data = nano_task_fifo_get(&timeout_order_fifo, TIMEOUT_TWO_INTERVALS); if (!data) { TC_ERROR(" *** timeout while waiting for delayed fiber\n"); return TC_FAIL; } if (data->timeout_order != ii) { TC_ERROR(" *** wrong delayed fiber ran (got %d, expected %d)\n", data->timeout_order, ii); return TC_FAIL; } TC_PRINT(" got fiber (q order: %d, t/o: %d) as expected\n", data->q_order, data->timeout); } /* ensure no more fibers fire */ data = nano_task_fifo_get(&timeout_order_fifo, TIMEOUT_TWO_INTERVALS); if (data) { TC_ERROR(" *** got something on the fifo, but shouldn't have...\n"); return TC_FAIL; } /* test fiber_delayed_start() with cancellation */ TC_PRINT("Testing fiber_delayed_start() with cancellations\n"); int cancellations[] = {0, 3, 4, 6}; int num_cancellations = ARRAY_SIZE(cancellations); int next_cancellation = 0; void *delayed_fibers[NUM_TIMEOUT_FIBERS]; for (ii = 0; ii < NUM_TIMEOUT_FIBERS; ii++) { delayed_fibers[ii] = task_fiber_delayed_start(timeout_stacks[ii], FIBER_STACKSIZE, delayed_fiber, ii, 0, 5, 0, timeout_order_data[ii].timeout); } for (ii = 0; ii < NUM_TIMEOUT_FIBERS; ii++) { int jj; if (ii == cancellations[next_cancellation]) { TC_PRINT(" cancelling [q order: %d, t/o: %d, t/o order: %d]\n", timeout_order_data[ii].q_order, timeout_order_data[ii].timeout, ii); for (jj = 0; jj < NUM_TIMEOUT_FIBERS; jj++) { if (timeout_order_data[jj].timeout_order == ii) { break; } } task_fiber_delayed_start_cancel(delayed_fibers[jj]); ++next_cancellation; continue; } data = nano_task_fifo_get(&timeout_order_fifo, TIMEOUT_TEN_INTERVALS); if (!data) { TC_ERROR(" *** timeout while waiting for delayed fiber\n"); return TC_FAIL; } if (data->timeout_order != ii) { TC_ERROR(" *** wrong delayed fiber ran (got %d, expected %d)\n", data->timeout_order, ii); return TC_FAIL; } TC_PRINT(" got (q order: %d, t/o: %d, t/o order %d) as expected\n", data->q_order, data->timeout); } if (num_cancellations != next_cancellation) { TC_ERROR(" *** wrong number of cancellations (expected %d, got %d\n", num_cancellations, next_cancellation); return TC_FAIL; } /* ensure no more fibers fire */ data = nano_task_fifo_get(&timeout_order_fifo, TIMEOUT_TWO_INTERVALS); if (data) { TC_ERROR(" *** got something on the fifo, but shouldn't have...\n"); return TC_FAIL; } return TC_PASS; }
void main(void) { void *pData; /* pointer to FIFO object get from the queue */ int count = 0; /* counter */ TC_START("Test Nanokernel FIFO"); /* Initialize the FIFO queues and semaphore */ initNanoObjects(); /* Create and start the three (3) fibers. */ task_fiber_start(&fiberStack1[0], FIBER_STACKSIZE, (nano_fiber_entry_t) fiber1, 0, 0, 7, 0); task_fiber_start(&fiberStack2[0], FIBER_STACKSIZE, (nano_fiber_entry_t) fiber2, 0, 0, 7, 0); task_fiber_start(&fiberStack3[0], FIBER_STACKSIZE, (nano_fiber_entry_t) fiber3, 0, 0, 7, 0); /* * The three fibers have each blocked on a different semaphore. Giving * the semaphore nanoSemObjX will unblock fiberX (where X = {1, 2, 3}). * * Activate fibers #1 and #2. They will each block on nanoFifoObj. */ nano_task_sem_give(&nanoSemObj1); nano_task_sem_give(&nanoSemObj2); /* Put two items into <nanoFifoObj> to unblock fibers #1 and #2. */ nano_task_fifo_put(&nanoFifoObj, pPutList1[0]); /* Wake fiber1 */ nano_task_fifo_put(&nanoFifoObj, pPutList1[1]); /* Wake fiber2 */ /* Activate fiber #3 */ nano_task_sem_give(&nanoSemObj3); /* * All three fibers should be blocked on their semaphores. Put data into * <nanoFifoObj2>. Fiber #3 will read it after it is reactivated. */ nano_task_fifo_put(&nanoFifoObj2, pPutList2[0]); nano_task_sem_give(&nanoSemObj3); /* Reactivate fiber #3 */ for (int i = 0; i < 4; i++) { pData = nano_task_fifo_get(&nanoFifoObj2, TICKS_UNLIMITED); if (pData != pPutList2[i]) { TC_ERROR("nano_task_fifo_get() expected 0x%x, got 0x%x\n", pPutList2[i], pData); goto exit; } } /* Add items to <nanoFifoObj> for fiber #2 */ for (int i = 0; i < 4; i++) { nano_task_fifo_put(&nanoFifoObj, pPutList1[i]); } nano_task_sem_give(&nanoSemObj2); /* Activate fiber #2 */ /* Wait for fibers to finish */ nano_task_sem_take(&nanoSemObjTask, TICKS_UNLIMITED); if (retCode == TC_FAIL) { goto exit; } /* * Entries in the FIFO queue have to be unique. * Put data to queue. */ TC_PRINT("Test Task FIFO Put\n"); TC_PRINT("\nTASK FIFO Put Order: "); for (int i = 0; i < NUM_FIFO_ELEMENT; i++) { nano_task_fifo_put(&nanoFifoObj, pPutList1[i]); TC_PRINT(" %p,", pPutList1[i]); } TC_PRINT("\n"); PRINT_LINE; nano_task_sem_give(&nanoSemObj1); /* Activate fiber1 */ 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(&nanoSemObjTask, TICKS_UNLIMITED); TC_PRINT("Test Task FIFO Get\n"); /* Get all FIFOs */ while ((pData = nano_task_fifo_get(&nanoFifoObj, TICKS_NONE)) != NULL) { TC_PRINT("TASK FIFO Get: count = %d, ptr is %p\n", count, pData); if ((count >= NUM_FIFO_ELEMENT) || (pData != pPutList2[count])) { TCERR1(count); retCode = TC_FAIL; goto exit; } count++; } /* Test FIFO Get Wait interfaces*/ testTaskFifoGetW(); PRINT_LINE; testIsrFifoFromTask(); PRINT_LINE; /* test timeouts */ if (test_fifo_timeout() != TC_PASS) { retCode = TC_FAIL; goto exit; } PRINT_LINE; exit: TC_END_RESULT(retCode); TC_END_REPORT(retCode); }
/* the timeout test entry point */ static int test_timeout(void) { int64_t orig_ticks; int32_t timeout; int rv; int test_data_size; struct reply_packet reply_packet; nano_sem_init(&sem_timeout[0]); nano_sem_init(&sem_timeout[1]); nano_fifo_init(&timeout_order_fifo); /* test nano_task_sem_take() with timeout */ timeout = 10; orig_ticks = sys_tick_get(); rv = nano_task_sem_take(&sem_timeout[0], timeout); if (rv) { TC_ERROR(" *** timeout of %d did not time out.\n", timeout); return TC_FAIL; } if ((sys_tick_get() - orig_ticks) < timeout) { TC_ERROR(" *** task did not wait long enough on timeout of %d.\n", timeout); return TC_FAIL; } /* test nano_task_sem_take() with timeout of 0 */ rv = nano_task_sem_take(&sem_timeout[0], 0); if (rv) { TC_ERROR(" *** timeout of 0 did not time out.\n"); return TC_FAIL; } /* test nano_task_sem_take() with timeout > 0 */ TC_PRINT("test nano_task_sem_take() with timeout > 0\n"); timeout = 3; orig_ticks = sys_tick_get(); rv = nano_task_sem_take(&sem_timeout[0], timeout); if (rv) { TC_ERROR(" *** timeout of %d did not time out.\n", timeout); return TC_FAIL; } if (!is_timeout_in_range(orig_ticks, timeout)) { return TC_FAIL; } TC_PRINT("nano_task_sem_take() timed out as expected\n"); /* * test nano_task_sem_take() with a timeout and fiber that gives * the semaphore on time */ timeout = 5; orig_ticks = sys_tick_get(); task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_give_timeout, (int)&sem_timeout[0], timeout, FIBER_PRIORITY, 0); rv = nano_task_sem_take(&sem_timeout[0], (int)(timeout + 5)); if (!rv) { TC_ERROR(" *** timed out even if semaphore was given in time.\n"); return TC_FAIL; } if (!is_timeout_in_range(orig_ticks, timeout)) { return TC_FAIL; } TC_PRINT("nano_task_sem_take() got sem in time, as expected\n"); /* * test nano_task_sem_take() with TICKS_NONE and the * semaphore unavailable. */ if (nano_task_sem_take(&sem_timeout[0], TICKS_NONE)) { TC_ERROR("task with TICKS_NONE got sem, but shouldn't have\n"); return TC_FAIL; } TC_PRINT("task with TICKS_NONE did not get sem, as expected\n"); /* * test nano_task_sem_take() with TICKS_NONE and the * semaphore available. */ nano_task_sem_give(&sem_timeout[0]); if (!nano_task_sem_take(&sem_timeout[0], TICKS_NONE)) { TC_ERROR("task with TICKS_NONE did not get available sem\n"); return TC_FAIL; } TC_PRINT("task with TICKS_NONE got available sem, as expected\n"); /* * test nano_task_sem_take() with TICKS_UNLIMITED and the * semaphore available. */ TC_PRINT("Trying to take available sem with TICKS_UNLIMITED:\n" " will hang the test if it fails.\n"); nano_task_sem_give(&sem_timeout[0]); if (!nano_task_sem_take(&sem_timeout[0], TICKS_UNLIMITED)) { TC_ERROR(" *** This will never be hit!!! .\n"); return TC_FAIL; } TC_PRINT("task with TICKS_UNLIMITED got available sem, as expected\n"); /* test fiber with timeout of TICKS_NONE not getting empty semaphore */ task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_ticks_special_values, (int)&reply_packet, TICKS_NONE, FIBER_PRIORITY, 0); if (!nano_task_fifo_get(&timeout_order_fifo, TICKS_NONE)) { TC_ERROR(" *** fiber should have run and filled the fifo.\n"); return TC_FAIL; } if (reply_packet.reply != 0) { TC_ERROR(" *** fiber should not have obtained the semaphore.\n"); return TC_FAIL; } TC_PRINT("fiber with TICKS_NONE did not get sem, as expected\n"); /* test fiber with timeout of TICKS_NONE getting full semaphore */ nano_task_sem_give(&sem_timeout[0]); task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_ticks_special_values, (int)&reply_packet, TICKS_NONE, FIBER_PRIORITY, 0); if (!nano_task_fifo_get(&timeout_order_fifo, TICKS_NONE)) { TC_ERROR(" *** fiber should have run and filled the fifo.\n"); return TC_FAIL; } if (reply_packet.reply != 1) { TC_ERROR(" *** fiber should have obtained the semaphore.\n"); return TC_FAIL; } TC_PRINT("fiber with TICKS_NONE got available sem, as expected\n"); /* test fiber with timeout of TICKS_UNLIMITED getting full semaphore */ nano_task_sem_give(&sem_timeout[0]); task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_ticks_special_values, (int)&reply_packet, TICKS_UNLIMITED, FIBER_PRIORITY, 0); if (!nano_task_fifo_get(&timeout_order_fifo, TICKS_NONE)) { TC_ERROR(" *** fiber should have run and filled the fifo.\n"); return TC_FAIL; } if (reply_packet.reply != 1) { TC_ERROR(" *** fiber should have obtained the semaphore.\n"); return TC_FAIL; } TC_PRINT("fiber with TICKS_UNLIMITED got available sem, as expected\n"); /* test multiple fibers pending on the same sem with different timeouts */ test_data_size = ARRAY_SIZE(timeout_order_data); TC_PRINT("testing timeouts of %d fibers on same sem\n", test_data_size); rv = test_multiple_fibers_pending(timeout_order_data, test_data_size); if (rv != TC_PASS) { TC_ERROR(" *** fibers did not time out in the right order\n"); return TC_FAIL; } /* test multiple fibers pending on different sems with different timeouts */ test_data_size = ARRAY_SIZE(timeout_order_data_mult_sem); TC_PRINT("testing timeouts of %d fibers on different sems\n", test_data_size); rv = test_multiple_fibers_pending(timeout_order_data_mult_sem, test_data_size); if (rv != TC_PASS) { TC_ERROR(" *** fibers did not time out in the right order\n"); return TC_FAIL; } /* * test multiple fibers pending on same sem with different timeouts, but * getting the semaphore in time, except the last one. */ test_data_size = ARRAY_SIZE(timeout_order_data); TC_PRINT("testing %d fibers timing out, but obtaining the sem in time\n" "(except the last one, which times out)\n", test_data_size); rv = test_multiple_fibers_get_sem(timeout_order_data, test_data_size); if (rv != TC_PASS) { TC_ERROR(" *** fibers did not get the sem in the right order\n"); return TC_FAIL; } return TC_PASS; }