void main(void) { int rv; /* return value from tests */ TC_START("Test Nanokernel LIFO"); initNanoObjects(); /* * Start the fiber. The fiber will be given a higher priority than the * main task. */ task_fiber_start(fiberStack, FIBER_STACKSIZE, fiberEntry, 0, 0, FIBER_PRIORITY, 0); rv = taskLifoWaitTest(); if (rv == TC_PASS) { rv = taskLifoNonWaitTest(); } if (rv == TC_PASS) { rv = test_multiple_waiters(); } /* test timeouts */ if (rv == TC_PASS) { rv = test_timeout(); } TC_END_RESULT(rv); TC_END_REPORT(rv); }
void main(void) { int rv; /* return value from tests */ TC_START("Test Nanokernel Semaphores"); initNanoObjects(); rv = testSemTaskNoWait(); if (rv != TC_PASS) { goto doneTests; } rv = testSemIsrNoWait(); if (rv != TC_PASS) { goto doneTests; } semTestState = STS_INIT; /* * Start the fiber. The fiber will be given a higher priority than the * main task. */ task_fiber_start(fiberStack, FIBER_STACKSIZE, fiberEntry, 0, 0, FIBER_PRIORITY, 0); rv = testSemWait(); if (rv != TC_PASS) { goto doneTests; } rv = test_multiple_waiters(); if (rv != TC_PASS) { goto doneTests; } rv = test_timeout(); if (rv != TC_PASS) { goto doneTests; } doneTests: TC_END_RESULT(rv); TC_END_REPORT(rv); }
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); }
void main(void) { int rv; /* return value from tests */ TC_START("Test Nanokernel CPU and thread routines"); TC_PRINT("Initializing nanokernel objects\n"); rv = initNanoObjects(); if (rv != TC_PASS) { goto doneTests; } TC_PRINT("Testing nano_cpu_idle()\n"); rv = nano_cpu_idleTest(); if (rv != TC_PASS) { goto doneTests; } TC_PRINT("Testing interrupt locking and unlocking\n"); rv = nanoCpuDisableInterruptsTest(irq_lockWrapper, irq_unlockWrapper, -1); if (rv != TC_PASS) { goto doneTests; } /* * The Cortex-M3/M4 use the SYSTICK exception for the system timer, which is * not considered an IRQ by the irq_enable/Disable APIs. */ #if !defined(CONFIG_CPU_CORTEX_M3_M4) /* Disable interrupts coming from the timer. */ TC_PRINT("Testing irq_disable() and irq_enable()\n"); rv = nanoCpuDisableInterruptsTest(irq_disableWrapper, irq_enableWrapper, TICK_IRQ); if (rv != TC_PASS) { goto doneTests; } #endif rv = nanoCtxTaskTest(); if (rv != TC_PASS) { goto doneTests; } TC_PRINT("Spawning a fiber from a task\n"); fiberEvidence = 0; task_fiber_start(fiberStack1, FIBER_STACKSIZE, fiberEntry, (int) sys_thread_self_get(), 0, FIBER_PRIORITY, 0); if (fiberEvidence != 1) { rv = TC_FAIL; TC_ERROR(" - fiber did not execute as expected!\n"); goto doneTests; } /* * The fiber ran, now wake it so it can test sys_thread_self_get and * sys_execution_context_type_get. */ TC_PRINT("Fiber to test sys_thread_self_get() and sys_execution_context_type_get\n"); nano_task_sem_give(&wakeFiber); if (fiberDetectedError != 0) { rv = TC_FAIL; TC_ERROR(" - failure detected in fiber; fiberDetectedError = %d\n", fiberDetectedError); goto doneTests; } TC_PRINT("Fiber to test fiber_yield()\n"); nano_task_sem_give(&wakeFiber); if (fiberDetectedError != 0) { rv = TC_FAIL; TC_ERROR(" - failure detected in fiber; fiberDetectedError = %d\n", fiberDetectedError); goto doneTests; } nano_task_sem_give(&wakeFiber); rv = test_timeout(); if (rv != TC_PASS) { goto doneTests; } /* Cortex-M3/M4 does not implement connecting non-IRQ exception handlers */ #if !defined(CONFIG_CPU_CORTEX_M3_M4) /* * Test divide by zero exception handler. * * WARNING: This code has been very carefully crafted so that it does * what it is supposed to. Both "error" and "excHandlerExecuted" must be * volatile to prevent the compiler from issuing a "divide by zero" * warning (since otherwise in knows "excHandlerExecuted" is zero), * and to ensure the compiler issues the two byte "idiv" instruction * that the exception handler is designed to deal with. */ volatile int error; /* used to create a divide by zero error */ TC_PRINT("Verifying exception handler installed\n"); excHandlerExecuted = 0; error = error / excHandlerExecuted; TC_PRINT("excHandlerExecuted: %d\n", excHandlerExecuted); rv = (excHandlerExecuted == 1) ? TC_PASS : TC_FAIL; #endif doneTests: TC_END_RESULT(rv); TC_END_REPORT(rv); }
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); }