void main_thread(void) { if (run_tests()) { TC_END_REPORT(TC_PASS); } else { TC_END_REPORT(TC_FAIL); } }
void RegressionTask(void) { uint32_t nCalls = 0; int status; TC_START("Test Microkernel Critical Section API\n"); task_sem_give(ALT_SEM); /* Activate AlternateTask() */ nCalls = criticalLoop(nCalls); /* Wait for AlternateTask() to complete */ status = task_sem_take_wait_timeout(REGRESS_SEM, TEST_TIMEOUT); if (status != RC_OK) { TC_ERROR("Timed out waiting for REGRESS_SEM\n"); goto errorReturn; } if (criticalVar != nCalls + altTaskIterations) { TC_ERROR("Unexpected value for <criticalVar>. Expected %d, got %d\n", nCalls + altTaskIterations, criticalVar); goto errorReturn; } TC_PRINT("Obtained expected <criticalVar> value of %u\n", criticalVar); TC_PRINT("Enabling time slicing ...\n"); sys_scheduler_time_slice_set(1, 10); task_sem_give(ALT_SEM); /* Re-activate AlternateTask() */ nCalls = criticalLoop(nCalls); /* Wait for AlternateTask() to finish */ status = task_sem_take_wait_timeout(REGRESS_SEM, TEST_TIMEOUT); if (status != RC_OK) { TC_ERROR("Timed out waiting for REGRESS_SEM\n"); goto errorReturn; } if (criticalVar != nCalls + altTaskIterations) { TC_ERROR("Unexpected value for <criticalVar>. Expected %d, got %d\n", nCalls + altTaskIterations, criticalVar); goto errorReturn; } TC_PRINT("Obtained expected <criticalVar> value of %u\n", criticalVar); TC_END_RESULT(TC_PASS); TC_END_REPORT(TC_PASS); return; errorReturn: TC_END_RESULT(TC_FAIL); TC_END_REPORT(TC_FAIL); }
static void nmi_test_isr(void) { printk("NMI received (test_handler_isr)! Rebooting...\n"); /* ISR triggered correctly: test passed! */ TC_END_RESULT(TC_PASS); TC_END_REPORT(TC_PASS); }
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, i; struct device *ipm; TC_START("Test IPM"); ipm = device_get_binding("ipm_dummy0"); /* Try sending a raw string to the IPM device to show that the * receiver works */ for (i = 0; i < strlen(thestr); i++) { ipm_send(ipm, 1, thestr[i], NULL, 0); } /* Now do this through printf() to exercise the sender */ printf("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " "sed do eiusmod tempor incididunt ut labore et dolore magna " "aliqua. Ut enim ad minim veniam, quis nostrud exercitation " "ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis " "aute irure dolor in reprehenderit in voluptate velit esse " "cillum dolore eu fugiat nulla pariatur. Excepteur sint " "occaecat cupidatat non proident, sunt in culpa qui officia " "deserunt mollit anim id est laborum.\n"); /* XXX how to tell if something was actually printed out for * automation purposes? */ rv = TC_PASS; TC_END_RESULT(rv); TC_END_REPORT(rv); }
void main(void) { int status = TC_FAIL; u32_t start_tick; u32_t end_tick; TC_START("Test kernel Sleep and Wakeup APIs\n"); test_objects_init(); test_thread_id = k_thread_create(&test_thread_data, test_thread_stack, THREAD_STACK, (k_thread_entry_t) test_thread, 0, 0, NULL, TEST_THREAD_PRIORITY, 0, 0); TC_PRINT("Test thread started: id = %p\n", test_thread_id); helper_thread_id = k_thread_create(&helper_thread_data, helper_thread_stack, THREAD_STACK, (k_thread_entry_t) helper_thread, 0, 0, NULL, HELPER_THREAD_PRIORITY, 0, 0); TC_PRINT("Helper thread started: id = %p\n", helper_thread_id); /* Activate test_thread */ k_sem_give(&test_thread_sem); /* Wait for test_thread to activate us */ k_sem_take(&task_sem, K_FOREVER); /* Wake the test fiber */ k_wakeup(test_thread_id); if (test_failure) { goto done_tests; } TC_PRINT("Testing kernel k_sleep()\n"); align_to_tick_boundary(); start_tick = k_uptime_get_32(); /* FIXME: one tick less to account for * one extra tick for _TICK_ALIGN in k_sleep*/ k_sleep(ONE_SECOND - TICKS_PER_MS); end_tick = k_uptime_get_32(); if (!sleep_time_valid(start_tick, end_tick, ONE_SECOND)) { TC_ERROR("k_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); }
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) { /* Fake personalization and additional_input * (replace by appropriate values) * e.g.: hostname+timestamp */ uint8_t additional_input[] = "additional input"; uint8_t personalization[] = "HOSTNAME"; uint32_t size = (1 << 15); uint32_t result = TC_PASS; struct tc_hmac_prng_struct h; uint8_t random[size]; uint8_t seed[128]; uint32_t i; TC_START("Performing HMAC-PRNG tests:"); TC_PRINT("HMAC-PRNG test#1 (init, reseed, generate):\n"); /* Fake seed (replace by a a truly random seed): */ for (i = 0; i < (uint32_t)sizeof(seed); ++i) { seed[i] = i; } TC_PRINT("HMAC-PRNG test#1 (init):\n"); if (tc_hmac_prng_init(&h, personalization, sizeof(personalization)) == 0) { TC_ERROR("HMAC-PRNG initialization failed.\n"); result = TC_FAIL; goto exitTest; } TC_END_RESULT(result); TC_PRINT("HMAC-PRNG test#1 (reseed):\n"); if (tc_hmac_prng_reseed(&h, seed, sizeof(seed), additional_input, sizeof(additional_input)) == 0) { TC_ERROR("HMAC-PRNG reseed failed.\n"); result = TC_FAIL; goto exitTest; } TC_END_RESULT(result); TC_PRINT("HMAC-PRNG test#1 (generate):\n"); if (tc_hmac_prng_generate(random, size, &h) < 1) { TC_ERROR("HMAC-PRNG generate failed.\n"); result = TC_FAIL; goto exitTest; } TC_END_RESULT(result); TC_PRINT("All HMAC tests succeeded!\n"); exitTest: TC_END_RESULT(result); TC_END_REPORT(result); }
void main(void) { u32_t result = TC_PASS; struct tc_cmac_struct state; struct tc_aes_key_sched_struct sched; const u8_t key[BUF_LEN] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; u8_t K1[BUF_LEN], K2[BUF_LEN]; TC_START("Performing CMAC tests:"); (void) tc_cmac_setup(&state, key, &sched); result = verify_gf_2_128_double(K1, K2, state); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("CMAC test #1 (128 double) failed.\n"); goto exitTest; } (void) tc_cmac_setup(&state, key, &sched); result = verify_cmac_null_msg(&state); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("CMAC test #2 (null msg) failed.\n"); goto exitTest; } (void) tc_cmac_setup(&state, key, &sched); result = verify_cmac_1_block_msg(&state); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("CMAC test #3 (1 block msg)failed.\n"); goto exitTest; } (void) tc_cmac_setup(&state, key, &sched); result = verify_cmac_320_bit_msg(&state); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("CMAC test #4 (320 bit msg) failed.\n"); goto exitTest; } (void) tc_cmac_setup(&state, key, &sched); result = verify_cmac_512_bit_msg(&state); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("CMAC test #5 (512 bit msg)failed.\n"); goto exitTest; } TC_PRINT("All CMAC tests succeeded!\n"); exitTest: TC_END_RESULT(result); TC_END_REPORT(result); }
void main(void) { int status = TC_PASS; TC_START("Test sprintf APIs\n"); PRINT_LINE; TC_PRINT("Testing sprintf() with integers ....\n"); if (sprintfIntegerTest() != TC_PASS) { status = TC_FAIL; } TC_PRINT("Testing snprintf() ....\n"); if (snprintfTest() != TC_PASS) { status = TC_FAIL; } TC_PRINT("Testing vsprintf() ....\n"); if (vsprintfTest() != TC_PASS) { status = TC_FAIL; } TC_PRINT("Testing vsnprintf() ....\n"); if (vsnprintfTest() != TC_PASS) { status = TC_FAIL; } TC_PRINT("Testing sprintf() with strings ....\n"); if (sprintfStringTest() != TC_PASS) { status = TC_FAIL; } TC_PRINT("Testing sprintf() with misc options ....\n"); if (sprintfMiscTest() != TC_PASS) { status = TC_FAIL; } #ifdef CONFIG_FLOAT TC_PRINT("Testing sprintf() with doubles ....\n"); if (sprintfDoubleTest() != TC_PASS) { status = TC_FAIL; } #endif /* CONFIG_FLOAT */ TC_END_RESULT(status); TC_END_REPORT(status); }
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); }
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); }
/* * Main task to test CTR PRNG */ int main(void) { int elements; int rc; int i; TC_START("Performing CTR-PRNG tests:"); elements = (int)sizeof(vectors) / sizeof(vectors[0]); for (i = 0; i < elements; i++) { rc = test_prng_vector(&vectors[i]); TC_PRINT("[%s] test_prng_vector #%d\n", RC_STR(rc), i); if (rc != TC_PASS) { goto exit_test; } } rc = test_reseed(); TC_PRINT("[%s] test_reseed\n", RC_STR(rc)); if (rc != TC_PASS) { goto exit_test; } rc = test_uninstantiate(); TC_PRINT("[%s] test_uninstantiate\n", RC_STR(rc)); if (rc != TC_PASS) { goto exit_test; } rc = test_robustness(); TC_PRINT("[%s] test_robustness\n", RC_STR(rc)); if (rc != TC_PASS) { goto exit_test; } TC_PRINT("\nAll CTR PRNG tests succeeded!\n"); rc = TC_PASS; exit_test: TC_END_RESULT(rc); TC_END_REPORT(rc); return 0; }
void RegressionTaskEntry(void) { int tc_result; /* test result code */ uint32_t rnd_values[N_VALUES]; int i; PRINT_DATA("Starting random number tests\n"); PRINT_LINE; /* * Test subsequently calls sys_rand32_get(), checking * that two values are not equal. */ PRINT_DATA("Generating random numbers\n"); /* * Get several subsequent numbers as fast as possible. * If random number generator is based on timer, check * the situation when random number generator is called * faster than timer clock ticks. * In order to do this, make several subsequent calls * and save results in an array to verify them on the * next step */ for (i = 0; i < N_VALUES; i++) { rnd_values[i] = sys_rand32_get(); } for (tc_result = TC_PASS, i = 1; i < N_VALUES; i++) { if (rnd_values[i - 1] == rnd_values[i]) { tc_result = TC_FAIL; break; } } if (tc_result == TC_FAIL) { TC_ERROR("random number subsequent calls\n" "returned same value %d\n", rnd_values[i]); } else { PRINT_DATA("Generated %d values with expected randomness\n", N_VALUES); } TC_END_RESULT(tc_result); TC_END_REPORT(tc_result); }
void main(void) #endif { int ret, ret_code; driver_init(); ret = bt_enable(NULL); if (ret == EXPECTED_ERROR) { ret_code = TC_PASS; } else { ret_code = TC_FAIL; } TC_END(ret_code, "%s - %s.\n", ret_code == TC_PASS ? PASS : FAIL, __func__); TC_END_REPORT(ret_code); }
int main(void) { unsigned int result = TC_PASS; TC_START("Performing AES128-CTR mode tests:"); TC_PRINT("Performing CTR tests:\n"); result = test_1_and_2(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("CBC test #1 failed.\n"); goto exitTest; } TC_PRINT("All CTR tests succeeded!\n"); exitTest: TC_END_RESULT(result); TC_END_REPORT(result); }
void main(void) { int tc_rC; /* test case return code */ TC_START("Test Memory Pool and Heap APIs"); TC_PRINT("Testing k_mem_pool_alloc(K_NO_WAIT) ...\n"); tc_rC = pool_block_get_test(); if (tc_rC != TC_PASS) { goto done_tests; } TC_PRINT("Testing k_mem_pool_alloc(timeout) ...\n"); tc_rC = pool_block_get_timeout_test(); if (tc_rC != TC_PASS) { goto done_tests; } TC_PRINT("Testing k_mem_pool_alloc(K_FOREVER) ...\n"); tc_rC = pool_block_get_wait_test(); if (tc_rC != TC_PASS) { goto done_tests; } TC_PRINT("Testing k_mem_pool_defragment() ...\n"); tc_rC = pool_defrag_test(); if (tc_rC != TC_PASS) { goto done_tests; } tc_rC = pool_malloc_test(); if (tc_rC != TC_PASS) { goto done_tests; } done_tests: TC_END_RESULT(tc_rC); TC_END_REPORT(tc_rC); }
/* * Main task to test CTR PRNG */ int main(void) { int32_t result = TC_PASS; uint32_t i; TC_START("Performing CTR-PRNG tests:"); for (i = 0U; i < sizeof vectors / sizeof vectors[0]; i++) { result = executePRNG_TestVector(vectors[i], i); if (TC_PASS != result) { goto exitTest; } } if (TC_PASS != test_reseed()) { goto exitTest; } if (TC_PASS != test_uninstantiate()) { goto exitTest; } if (TC_PASS != test_robustness()) { goto exitTest; } TC_PRINT("All CTR PRNG tests succeeded!\n"); exitTest: TC_END_RESULT(result); TC_END_REPORT(result); }
static void receive_data(const char *taskname, struct net_context *ctx) { struct net_buf *buf; #ifdef CONFIG_NET_SANITY_TEST int rp; #endif buf = net_receive(ctx, TICKS_NONE); if (buf) { PRINT("%s: %s(): received %d bytes\n", taskname, __func__, ip_buf_appdatalen(buf)); if (memcmp(ip_buf_appdata(buf), lorem_ipsum, sizeof(lorem_ipsum))) { PRINT("ERROR: data does not match\n"); #ifdef CONFIG_NET_SANITY_TEST rp = TC_FAIL; } else { rp = TC_PASS; #endif } ip_buf_unref(buf); #ifdef CONFIG_NET_SANITY_TEST loopback++; test_rp = test_rp && rp; TC_END_RESULT(rp); if (loopback == CONFIG_NET_15_4_LOOPBACK_NUM) { loopback = 0; TC_END_REPORT(test_rp); } #endif } }
void main(void) { int rv = TC_PASS; nano_fifo_init(&fifo); errno = errno_values[N_FIBERS]; printk("task, errno before starting fibers: %x\n", errno); for (int ii = 0; ii < N_FIBERS; ii++) { result[ii].pass = TC_FAIL; } for (int ii = 0; ii < N_FIBERS; ii++) { task_fiber_start(stacks[ii], STACK_SIZE, errno_fiber, ii, errno_values[ii], ii + 5, 0); } for (int ii = 0; ii < N_FIBERS; ii++) { struct result *p = nano_task_fifo_get(&fifo, 10); if (!p || !p->pass) { rv = TC_FAIL; } } printk("task, errno after running fibers: %x\n", errno); if (errno != errno_values[N_FIBERS]) { rv = TC_FAIL; } 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); }
/** * @brief Entry point to timer tests * * This is the entry point to the CPU and thread tests. * * @return N/A */ void main(void) { int rv; /* return value from tests */ thread_detected_error = 0; thread_evidence = 0; TC_START("Test kernel CPU and thread routines"); TC_PRINT("Initializing kernel objects\n"); rv = kernel_init_objects(); if (rv != TC_PASS) { goto tests_done; } #ifdef HAS_POWERSAVE_INSTRUCTION TC_PRINT("Testing k_cpu_idle()\n"); rv = test_kernel_cpu_idle(0); if (rv != TC_PASS) { goto tests_done; } #ifndef CONFIG_ARM TC_PRINT("Testing k_cpu_atomic_idle()\n"); rv = test_kernel_cpu_idle(1); if (rv != TC_PASS) { goto tests_done; } #endif #endif TC_PRINT("Testing interrupt locking and unlocking\n"); rv = test_kernel_interrupts(irq_lock_wrapper, irq_unlock_wrapper, -1); if (rv != TC_PASS) { goto tests_done; } #ifdef TICK_IRQ /* Disable interrupts coming from the timer. */ TC_PRINT("Testing irq_disable() and irq_enable()\n"); rv = test_kernel_interrupts(irq_disable_wrapper, irq_enable_wrapper, TICK_IRQ); if (rv != TC_PASS) { goto tests_done; } #endif TC_PRINT("Testing some kernel context routines\n"); rv = test_kernel_ctx_task(); if (rv != TC_PASS) { goto tests_done; } TC_PRINT("Spawning a thread from a task\n"); thread_evidence = 0; k_thread_spawn(thread_stack1, THREAD_STACKSIZE, thread_entry, k_current_get(), NULL, NULL, K_PRIO_COOP(THREAD_PRIORITY), 0, 0); if (thread_evidence != 1) { rv = TC_FAIL; TC_ERROR(" - thread did not execute as expected!\n"); goto tests_done; } /* * The thread ran, now wake it so it can test k_current_get and * k_is_in_isr. */ TC_PRINT("Thread to test k_current_get() and " "k_is_in_isr()\n"); k_sem_give(&sem_thread); if (thread_detected_error != 0) { rv = TC_FAIL; TC_ERROR(" - failure detected in thread; " "thread_detected_error = %d\n", thread_detected_error); goto tests_done; } TC_PRINT("Thread to test k_yield()\n"); k_sem_give(&sem_thread); if (thread_detected_error != 0) { rv = TC_FAIL; TC_ERROR(" - failure detected in thread; " "thread_detected_error = %d\n", thread_detected_error); goto tests_done; } k_sem_give(&sem_thread); rv = test_timeout(); if (rv != TC_PASS) { goto tests_done; } tests_done: TC_END_RESULT(rv); TC_END_REPORT(rv); }
/* * Main task to test AES */ int main(void) { uint8_t seed[128]; struct tc_hmac_prng_struct h; unsigned int size = (1 << 19); uint8_t random[size]; unsigned int i; unsigned int result = TC_PASS; TC_START("Performing HMAC-PRNG tests:"); TC_PRINT("HMAC-PRNG test#1 (init, reseed, generate):\n"); /* Fake seed (replace by a a truly random seed): */ for (i = 0; i < (unsigned int) sizeof(seed); ++i) { seed[i] = i; } /* Fake personalization and additional_input (replace by appropriate * values): * * e.g.: hostname+timestamp */ uint8_t *personalization = (uint8_t *) "HOSTNAME"; uint8_t *additional_input = (uint8_t *) "additional input"; TC_PRINT("HMAC-PRNG test#1 (init):\n"); if (tc_hmac_prng_init(&h, personalization, sizeof(personalization)) == 0) { TC_ERROR("HMAC-PRNG initialization failed.\n"); result = TC_FAIL; goto exitTest; } TC_END_RESULT(result); TC_PRINT("HMAC-PRNG test#1 (reseed):\n"); if (tc_hmac_prng_reseed(&h, seed, sizeof(seed), additional_input, sizeof(additional_input)) == 0) { TC_ERROR("HMAC-PRNG reseed failed.\n"); result = TC_FAIL; goto exitTest; } TC_END_RESULT(result); TC_PRINT("HMAC-PRNG test#1 (generate):\n"); if (tc_hmac_prng_generate(random, size, &h) < 1) { TC_ERROR("HMAC-PRNG generate failed.\n"); result = TC_FAIL; goto exitTest; } TC_END_RESULT(result); #ifdef TC_DEBUG_MODE printBinaryFile(random, size); show ("Pseudo-random data", random, size); #endif TC_PRINT("All HMAC tests succeeded!\n"); exitTest: TC_END_RESULT(result); TC_END_REPORT(result); }
void RegressionTask(void) { int retValue; /* task_mem_map_xxx interface return value */ void *b; /* Pointer to memory block */ void *ptr[NUMBLOCKS]; /* Pointer to memory block */ /* Part 1 of test */ TC_START("Test Microkernel Memory Maps"); TC_PRINT("Starts %s\n", __func__); /* Test task_mem_map_alloc */ tcRC = testMapGetAllBlocks(ptr); if (tcRC == TC_FAIL) { TC_ERROR("Failed testMapGetAllBlocks function\n"); goto exitTest; /* terminate test */ } printPointers(ptr); /* Test task_mem_map_free */ tcRC = testMapFreeAllBlocks(ptr); if (tcRC == TC_FAIL) { TC_ERROR("Failed testMapFreeAllBlocks function\n"); goto exitTest; /* terminate test */ } printPointers(ptr); task_sem_give(SEM_REGRESSDONE); /* Allow HelperTask to run */ /* Wait for HelperTask to finish */ task_sem_take(SEM_HELPERDONE, TICKS_UNLIMITED); /* * Part 3 of test. * * HelperTask got all memory blocks. There is no free block left. * The call will timeout. Note that control does not switch back to * HelperTask as it is waiting for SEM_REGRESSDONE. */ retValue = task_mem_map_alloc(MAP_LgBlks, &b, 2); if (verifyRetValue(RC_TIME, retValue)) { TC_PRINT("%s: task_mem_map_alloc timeout expected\n", __func__); } else { TC_ERROR("Failed task_mem_map_alloc, retValue %d\n", retValue); tcRC = TC_FAIL; goto exitTest; /* terminate test */ } TC_PRINT("%s: start to wait for block\n", __func__); task_sem_give(SEM_REGRESSDONE); /* Allow HelperTask to run part 4 */ retValue = task_mem_map_alloc(MAP_LgBlks, &b, 5); if (verifyRetValue(RC_OK, retValue)) { TC_PRINT("%s: task_mem_map_alloc OK, block allocated at %p\n", __func__, b); } else { TC_ERROR("Failed task_mem_map_alloc, retValue %d\n", retValue); tcRC = TC_FAIL; goto exitTest; /* terminate test */ } /* Wait for HelperTask to complete */ task_sem_take(SEM_HELPERDONE, TICKS_UNLIMITED); TC_PRINT("%s: start to wait for block\n", __func__); task_sem_give(SEM_REGRESSDONE); /* Allow HelperTask to run part 5 */ retValue = task_mem_map_alloc(MAP_LgBlks, &b, TICKS_UNLIMITED); if (verifyRetValue(RC_OK, retValue)) { TC_PRINT("%s: task_mem_map_alloc OK, block allocated at %p\n", __func__, b); } else { TC_ERROR("Failed task_mem_map_alloc, retValue %d\n", retValue); tcRC = TC_FAIL; goto exitTest; /* terminate test */ } /* Wait for HelperTask to complete */ task_sem_take(SEM_HELPERDONE, TICKS_UNLIMITED); /* Free memory block */ TC_PRINT("%s: Used %d block\n", __func__, task_mem_map_used_get(MAP_LgBlks)); task_mem_map_free(MAP_LgBlks, &b); TC_PRINT("%s: 1 block freed, used %d block\n", __func__, task_mem_map_used_get(MAP_LgBlks)); exitTest: TC_END_RESULT(tcRC); TC_END_REPORT(tcRC); } /* RegressionTask */
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); }
int main(void) { int v, suites_tested = 0, suites_failed = 0; void *pointer; mbedtls_platform_set_printf(MBEDTLS_PRINT); TC_START("Performing mbedTLS crypto tests:"); /* * The C standard doesn't guarantee that all-bits-0 is the representation * of a NULL pointer. We do however use that in our code for initializing * structures, which should work on every modern platform. Let's be sure. */ memset(&pointer, 0, sizeof(void *)); if (pointer != NULL) { mbedtls_printf("all-bits-zero is not a NULL pointer\n"); mbedtls_exit(MBEDTLS_EXIT_FAILURE); } /* * Make sure we have a snprintf that correctly zero-terminates */ if (run_test_snprintf() != 0) { mbedtls_printf("the snprintf implementation is broken\n"); mbedtls_exit(MBEDTLS_EXIT_FAILURE); } v = 1; mbedtls_printf("\n"); #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) mbedtls_memory_buffer_alloc_init(buf, sizeof(buf)); #endif #if defined(MBEDTLS_MD2_C) if (mbedtls_md2_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_MD4_C) if (mbedtls_md4_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_MD5_C) if (mbedtls_md5_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_RIPEMD160_C) if (mbedtls_ripemd160_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_SHA1_C) if (mbedtls_sha1_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_SHA256_C) if (mbedtls_sha256_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_SHA512_C) if (mbedtls_sha512_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_ARC4_C) if (mbedtls_arc4_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_DES_C) if (mbedtls_des_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_AES_C) if (mbedtls_aes_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C) if (mbedtls_gcm_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C) if (mbedtls_ccm_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_BASE64_C) if (mbedtls_base64_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_BIGNUM_C) if (mbedtls_mpi_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_RSA_C) if (mbedtls_rsa_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_X509_USE_C) if (mbedtls_x509_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_XTEA_C) if (mbedtls_xtea_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_CAMELLIA_C) if (mbedtls_camellia_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_CTR_DRBG_C) if (mbedtls_ctr_drbg_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_HMAC_DRBG_C) if (mbedtls_hmac_drbg_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_ECP_C) if (mbedtls_ecp_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_ECJPAKE_C) if (mbedtls_ecjpake_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_DHM_C) if (mbedtls_dhm_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_ENTROPY_C) #if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY) create_entropy_seed_file(); #endif if (mbedtls_entropy_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #if defined(MBEDTLS_PKCS5_C) if (mbedtls_pkcs5_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif /* Slow tests last */ #if defined(MBEDTLS_TIMING_C) if (mbedtls_timing_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif #else mbedtls_printf(" MBEDTLS_SELF_TEST not defined.\n"); #endif if (v != 0) { #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG) mbedtls_memory_buffer_alloc_status(); #endif } #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) mbedtls_memory_buffer_alloc_free(); if (mbedtls_memory_buffer_alloc_self_test(v) != 0) { suites_failed++; } suites_tested++; #endif if (v != 0) { mbedtls_printf(" Executed %d test suites\n\n", suites_tested); if (suites_failed > 0) { mbedtls_printf(" [ %d tests FAIL ]\n\n", suites_failed); TC_END_RESULT(TC_FAIL); TC_END_REPORT(TC_FAIL); } else { mbedtls_printf(" [ All tests PASS ]\n\n"); TC_END_RESULT(TC_PASS); TC_END_REPORT(TC_PASS); } #if defined(_WIN32) mbedtls_printf(" Press Enter to exit this program.\n"); fflush(stdout); getchar(); #endif } while (1) { }; }
void main(void) { int status = TC_FAIL; TC_PRINT("Starting slist test\n"); TC_PRINT(" - Initializing the list\n"); sys_slist_init(&test_list); if (!verify_emptyness(&test_list)) { TC_ERROR("*** test_list should be empty\n"); goto end; } TC_PRINT(" - Appending node 1\n"); sys_slist_append(&test_list, &test_node_1); if (!verify_content_amount(&test_list, 1)) { TC_ERROR("*** test_list has wrong content\n"); goto end; } if (!verify_tail_head(&test_list, &test_node_1, &test_node_1, true)) { TC_ERROR("*** test_list head/tail are wrong\n"); goto end; } TC_PRINT(" - Finding and removing node 1\n"); sys_slist_find_and_remove(&test_list, &test_node_1); if (!verify_emptyness(&test_list)) { TC_ERROR("*** test_list should be empty\n"); goto end; } TC_PRINT(" - Prepending node 1\n"); sys_slist_prepend(&test_list, &test_node_1); if (!verify_content_amount(&test_list, 1)) { TC_ERROR("*** test_list has wrong content\n"); goto end; } if (!verify_tail_head(&test_list, &test_node_1, &test_node_1, true)) { TC_ERROR("*** test_list head/tail are wrong\n"); goto end; } TC_PRINT(" - Removing node 1\n"); sys_slist_remove(&test_list, NULL, &test_node_1); if (!verify_emptyness(&test_list)) { TC_ERROR("*** test_list should be empty\n"); goto end; } TC_PRINT(" - Appending node 1\n"); sys_slist_append(&test_list, &test_node_1); TC_PRINT(" - Prepending node 2\n"); sys_slist_prepend(&test_list, &test_node_2); if (!verify_content_amount(&test_list, 2)) { TC_ERROR("*** test_list has wrong content\n"); goto end; } if (!verify_tail_head(&test_list, &test_node_2, &test_node_1, false)) { TC_ERROR("*** test_list head/tail are wrong\n"); goto end; } TC_PRINT(" - Appending node 3\n"); sys_slist_append(&test_list, &test_node_3); if (!verify_content_amount(&test_list, 3)) { TC_ERROR("*** test_list has wrong content\n"); goto end; } if (!verify_tail_head(&test_list, &test_node_2, &test_node_3, false)) { TC_ERROR("*** test_list head/tail are wrong\n"); goto end; } if (sys_slist_peek_next(&test_node_2) != &test_node_1) { TC_ERROR("*** test_list node links are wrong\n"); goto end; } TC_PRINT(" - Inserting node 4 after node 2\n"); sys_slist_insert(&test_list, &test_node_2, &test_node_4); if (!verify_tail_head(&test_list, &test_node_2, &test_node_3, false)) { TC_ERROR("*** test_list head/tail are wrong\n"); goto end; } if (sys_slist_peek_next(&test_node_2) != &test_node_4) { TC_ERROR("*** test_list node links are wrong\n"); goto end; } TC_PRINT(" - Finding and removing node 1\n"); sys_slist_find_and_remove(&test_list, &test_node_1); if (!verify_content_amount(&test_list, 3)) { TC_ERROR("*** test_list has wrong content\n"); goto end; } if (!verify_tail_head(&test_list, &test_node_2, &test_node_3, false)) { TC_ERROR("*** test_list head/tail are wrong\n"); goto end; } TC_PRINT(" - Removing node 3\n"); sys_slist_remove(&test_list, &test_node_4, &test_node_3); if (!verify_content_amount(&test_list, 2)) { TC_ERROR("*** test_list has wrong content\n"); goto end; } if (!verify_tail_head(&test_list, &test_node_2, &test_node_4, false)) { TC_ERROR("*** test_list head/tail are wrong\n"); goto end; } TC_PRINT(" - Removing node 4\n"); sys_slist_remove(&test_list, &test_node_2, &test_node_4); if (!verify_content_amount(&test_list, 1)) { TC_ERROR("*** test_list has wrong content\n"); goto end; } if (!verify_tail_head(&test_list, &test_node_2, &test_node_2, true)) { TC_ERROR("*** test_list head/tail are wrong\n"); goto end; } TC_PRINT(" - Removing node 2\n"); sys_slist_remove(&test_list, NULL, &test_node_2); if (!verify_emptyness(&test_list)) { TC_ERROR("*** test_list should be empty\n"); goto end; } status = TC_PASS; end: TC_END_RESULT(status); TC_END_REPORT(status); }
int main(void) { uint32_t result = TC_PASS; TC_START("Performing SHA256 tests (NIST tests vectors):"); result = test_1(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #1 failed.\n"); goto exitTest; } result = test_2(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #2 failed.\n"); goto exitTest; } result = test_3(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #3 failed.\n"); goto exitTest; } result = test_4(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #4 failed.\n"); goto exitTest; } result = test_5(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #5 failed.\n"); goto exitTest; } result = test_6(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #6 failed.\n"); goto exitTest; } result = test_7(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #7 failed.\n"); goto exitTest; } result = test_8(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #8 failed.\n"); goto exitTest; } result = test_9(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #9 failed.\n"); goto exitTest; } result = test_10(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #10 failed.\n"); goto exitTest; } result = test_11(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #11 failed.\n"); goto exitTest; } result = test_12(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #12 failed.\n"); goto exitTest; } result = test_13(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #13 failed.\n"); goto exitTest; } result = test_14(); if (result == TC_FAIL) { /* terminate test */ TC_ERROR("SHA256 test #14 failed.\n"); goto exitTest; } TC_PRINT("All SHA256 tests succeeded!\n"); exitTest: TC_END_RESULT(result); TC_END_REPORT(result); }
void load_store_high(void) { unsigned int i; unsigned char init_byte; unsigned char *reg_set_ptr = (unsigned char *)&float_reg_set; /* test until the specified time limit, or until an error is detected */ while (1) { /* * Initialize the float_reg_set structure by treating it as * a simple array of bytes (the arrangement and actual number * of registers is not important for this generic C code). The * structure is initialized by using the byte value specified * by the constant FIBER_FLOAT_REG_CHECK_BYTE, and then * incrementing the value for each successive location in the * float_reg_set structure. * * The initial byte value, and thus the contents of the entire * float_reg_set structure, must be different for each * thread to effectively test the kernel's ability to * properly save/restore the floating point values during a * context switch. */ init_byte = FIBER_FLOAT_REG_CHECK_BYTE; for (i = 0; i < SIZEOF_FP_REGISTER_SET; i++) { reg_set_ptr[i] = init_byte++; } /* * Utilize an architecture specific function to load all the * floating point registers with the contents of the * float_reg_set structure. * * The goal of the loading all floating point registers with * values that differ from the values used in other threads is * to help determine whether the floating point register * save/restore mechanism in the kernel's context switcher * is operating correctly. * * When a subsequent k_timer_test() invocation is * performed, a (cooperative) context switch back to the * preempted task will occur. This context switch should result * in restoring the state of the task's floating point * registers when the task was swapped out due to the * occurrence of the timer tick. */ _load_then_store_all_float_registers(&float_reg_set); /* * Relinquish the processor for the remainder of the current * system clock tick, so that lower priority threads get a * chance to run. * * This exercises the ability of the kernel to restore the * FPU state of a low priority thread _and_ the ability of the * kernel to provide a "clean" FPU state to this thread * once the sleep ends. */ k_sleep(1); /* periodically issue progress report */ if ((++load_store_high_count % 100) == 0) { PRINT_DATA("Load and store OK after %u (high) " "+ %u (low) tests\n", load_store_high_count, load_store_low_count); } /* terminate testing if specified limit has been reached */ if (load_store_high_count == MAX_TESTS) { TC_END_RESULT(TC_PASS); TC_END_REPORT(TC_PASS); return; } } }
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); }