/* * NIST SHA256 test vector 1. */ void test_1(void) { TC_START("Performing SHA256 tests (NIST tests vectors):"); u32_t result = TC_PASS; TC_PRINT("SHA256 test #1:\n"); const u8_t expected[32] = { 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad }; const char *m = "abc"; u8_t digest[32]; struct tc_sha256_state_struct s; (void)tc_sha256_init(&s); tc_sha256_update(&s, (const u8_t *)m, strlen(m)); (void)tc_sha256_final(digest, &s); result = check_result(1, expected, sizeof(expected), digest, sizeof(digest), 1); /**TESTPOINT: Check result*/ zassert_false(result, "SHA256 test #1 failed."); }
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 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 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 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 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); }
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 test_arm_runtime_nmi(void) { u32_t i = 0; TC_START("nmi_test_isr"); /* Configure the NMI isr */ _NmiHandlerSet(nmi_test_isr); for (i = 0; i < 10; i++) { printk("Trigger NMI in 10s: %d s\n", i); k_sleep(1000); } /* Trigger NMI: Should fire immediately */ SCB->ICSR |= SCB_ICSR_NMIPENDSET_Msk; }
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 main(void) { int ret, ret_code; TC_START("bluetooth"); 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); }
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); }
/** * @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); }
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 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 */
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) { }; }
/* * 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 main(void) { int failed, rv, i; atomic_t target, orig; atomic_val_t value; atomic_val_t oldvalue; failed = 0; TC_START("Test atomic operation primitives"); TC_PRINT("Test atomic_cas()\n"); target = 4; value = 5; oldvalue = 6; CHECK_OUTPUT(atomic_cas(&target, oldvalue, value), 0); target = 6; CHECK_OUTPUT(atomic_cas(&target, oldvalue, value), 1); CHECK_OUTPUT(target, value); TC_PRINT("Test atomic_add()\n"); target = 1; value = 2; CHECK_OUTPUT(atomic_add(&target, value), 1); CHECK_OUTPUT(target, 3); TC_PRINT("Test atomic_sub()\n"); target = 10; value = 2; CHECK_OUTPUT(atomic_sub(&target, value), 10); CHECK_OUTPUT(target, 8); TC_PRINT("Test atomic_inc()\n"); target = 5; CHECK_OUTPUT(atomic_inc(&target), 5); CHECK_OUTPUT(target, 6); TC_PRINT("Test atomic_dec()\n"); target = 2; CHECK_OUTPUT(atomic_dec(&target), 2); CHECK_OUTPUT(target, 1); TC_PRINT("Test atomic_get()\n"); target = 50; CHECK_OUTPUT(atomic_get(&target), 50); TC_PRINT("Test atomic_set()\n"); target = 42; value = 77; CHECK_OUTPUT(atomic_set(&target, value), 42); CHECK_OUTPUT(target, value); TC_PRINT("Test atomic_clear()\n"); target = 100; CHECK_OUTPUT(atomic_clear(&target), 100); CHECK_OUTPUT(target, 0); TC_PRINT("Test atomic_or()\n"); target = 0xFF00; value = 0x0F0F; CHECK_OUTPUT(atomic_or(&target, value), 0xFF00); CHECK_OUTPUT(target, 0xFF0F); TC_PRINT("Test atomic_xor()\n"); target = 0xFF00; value = 0x0F0F; CHECK_OUTPUT(atomic_xor(&target, value), 0xFF00); CHECK_OUTPUT(target, 0xF00F); TC_PRINT("Test atomic_and()\n"); target = 0xFF00; value = 0x0F0F; CHECK_OUTPUT(atomic_and(&target, value), 0xFF00); CHECK_OUTPUT(target, 0x0F00); TC_PRINT("Test atomic_nand()\n"); target = 0xFF00; value = 0x0F0F; CHECK_OUTPUT(atomic_nand(&target, value), 0xFF00); CHECK_OUTPUT(target, 0xFFFFF0FF); TC_PRINT("Test atomic_test_bit()\n"); for (i = 0; i < 32; i++) { target = 0x0F0F0F0F; CHECK_TRUTH(atomic_test_bit(&target, i), (target & (1 << i))); } TC_PRINT("Test atomic_test_and_clear_bit()\n"); for (i = 0; i < 32; i++) { orig = 0x0F0F0F0F; target = orig; CHECK_TRUTH(atomic_test_and_clear_bit(&target, i), (orig & (1 << i))); CHECK_OUTPUT(target, orig & ~(1 << i)); } TC_PRINT("Test atomic_test_and_set_bit()\n"); for (i = 0; i < 32; i++) { orig = 0x0F0F0F0F; target = orig; CHECK_TRUTH(atomic_test_and_set_bit(&target, i), (orig & (1 << i))); CHECK_OUTPUT(target, orig | (1 << i)); } TC_PRINT("Test atomic_clear_bit()\n"); for (i = 0; i < 32; i++) { orig = 0x0F0F0F0F; target = orig; atomic_clear_bit(&target, i); CHECK_OUTPUT(target, orig & ~(1 << i)); } TC_PRINT("Test atomic_set_bit()\n"); for (i = 0; i < 32; i++) { orig = 0x0F0F0F0F; target = orig; atomic_set_bit(&target, i); CHECK_OUTPUT(target, orig | (1 << i)); } if (failed) { TC_PRINT("%d tests failed\n", failed); rv = TC_FAIL; } else { rv = TC_PASS; } TC_END_RESULT(rv); TC_END_REPORT(rv); }
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) { int rv; /* return value from tests */ volatile int error; /* used to create a divide by zero error */ TC_START("Starting static IDT tests"); TC_PRINT("Testing to see if IDT has address of test stubs()\n"); rv = idt_stub_test(); if (rv != TC_PASS) { goto done_tests; } TC_PRINT("Testing to see interrupt handler executes properly\n"); _trigger_isr_handler(); if (int_handler_executed == 0) { TC_ERROR("Interrupt handler did not execute\n"); rv = TC_FAIL; goto done_tests; } else if (int_handler_executed != 1) { TC_ERROR("Interrupt handler executed more than once! (%d)\n", int_handler_executed); rv = TC_FAIL; goto done_tests; } TC_PRINT("Testing to see exception handler executes properly\n"); /* * Use exc_handler_executed instead of 0 to prevent the compiler issuing a * 'divide by zero' warning. */ error = 32; /* avoid static checker uninitialized warnings */ error = error / exc_handler_executed; if (exc_handler_executed == 0) { TC_ERROR("Exception handler did not execute\n"); rv = TC_FAIL; goto done_tests; } else if (exc_handler_executed != 1) { TC_ERROR("Exception handler executed more than once! (%d)\n", exc_handler_executed); rv = TC_FAIL; goto done_tests; } /* * Start task to trigger the spurious interrupt handler */ TC_PRINT("Testing to see spurious handler executes properly\n"); k_thread_spawn(my_stack_area, MY_STACK_SIZE, idt_spur_task, NULL, NULL, NULL, MY_PRIORITY, 0, K_NO_WAIT); /* * The fiber/task should not run past where the spurious interrupt is * generated. Therefore spur_handler_aborted_thread should remain at 1. */ if (spur_handler_aborted_thread == 0) { TC_ERROR("Spurious handler did not execute as expected\n"); rv = TC_FAIL; goto done_tests; } done_tests: TC_END(rv, "%s - %s.\n", rv == TC_PASS ? PASS : FAIL, __func__); 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); }