Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
0
static u32_t verify_cmac_320_bit_msg(TCCmacState_t s)
{
	u32_t result = TC_PASS;

	TC_PRINT("Performing CMAC test #4 (SP 800-38B test vector #3):\n");

	const u8_t msg[40] = {
		0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
		0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
		0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
		0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
		0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11
	};
	const u8_t tag[BUF_LEN] = {
		0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
		0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
	};
	u8_t Tag[BUF_LEN];

	(void) tc_cmac_init(s);
	(void) tc_cmac_update(s, msg, sizeof(msg));
	(void) tc_cmac_final(Tag, s);

	if (memcmp(Tag, tag, BUF_LEN) != 0) {
		TC_ERROR("%s: aes_cmac failed with 320 bit msg\n", __func__);
		show("aes_cmac failed with 320 bit msg =", msg, sizeof(msg));
		show("expected Tag =", tag, sizeof(tag));
		show("computed Tag =", Tag, sizeof(Tag));
		return TC_FAIL;
	}

	TC_END_RESULT(result);
	return result;
}
Exemplo n.º 5
0
static u32_t verify_cmac_1_block_msg(TCCmacState_t s)
{
	u32_t result = TC_PASS;

	TC_PRINT("Performing CMAC test #3 (SP 800-38B test vector #2):\n");

	const u8_t msg[BUF_LEN] = {
		0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
		0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
	};
	const u8_t tag[BUF_LEN] = {
		0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
		0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
	};
	u8_t Tag[BUF_LEN];

	(void) tc_cmac_init(s);
	(void) tc_cmac_update(s, msg, sizeof(msg));
	(void) tc_cmac_final(Tag, s);

	if (memcmp(Tag, tag, BUF_LEN) != 0) {
		TC_ERROR("%s: aes_cmac failed with 1 block msg\n", __func__);
		show("aes_cmac failed with 1 block msg =", msg, sizeof(msg));
		show("expected Tag =", tag, sizeof(tag));
		show("computed Tag =", Tag, sizeof(Tag));
		return TC_FAIL;
	}

	TC_END_RESULT(result);
	return result;
}
Exemplo n.º 6
0
uint32_t test_13(void)
{
        uint32_t result = TC_PASS;

        TC_PRINT("SHA256 test #13:\n");
        const uint8_t expected[32] = {
                0x15, 0xa1, 0x86, 0x8c, 0x12, 0xcc, 0x53, 0x95, 0x1e, 0x18, 0x23, 0x44,
                0x27, 0x74, 0x47, 0xcd, 0x09, 0x79, 0x53, 0x6b, 0xad, 0xcc, 0x51, 0x2a,
                0xd2, 0x4c, 0x67, 0xe9, 0xb2, 0xd4, 0xf3, 0xdd
        };
        uint8_t m[32768];
        uint8_t digest[32];
        struct tc_sha256_state_struct s;
        uint32_t i;

        (void)memset(m, 0x5a, sizeof(m));

        (void)tc_sha256_init(&s);
        for (i = 0; i < 16384; ++i) {
                tc_sha256_update(&s, m, sizeof(m));
        }
        (void)tc_sha256_final(digest, &s);

        result = check_result(13, expected, sizeof(expected), digest, sizeof(digest));
        TC_END_RESULT(result);
        return result;
}
Exemplo n.º 7
0
void fiber1(void)
{
	void   *pData;      /* pointer to FIFO object get from the queue */
	int     count = 0;  /* counter */

	/* Wait for fiber1 to be activated. */
	nano_fiber_sem_take_wait(&nanoSemObj1);

	/* Wait for data to be added to <nanoFifoObj> by task */
	pData = nano_fiber_fifo_get_wait(&nanoFifoObj);
	if (pData != pPutList1[0]) {
		TC_ERROR("fiber1 (1) - expected 0x%x, got 0x%x\n",
				 pPutList1[0], pData);
		retCode = TC_FAIL;
		return;
	}

	/* Wait for data to be added to <nanoFifoObj2> by fiber3 */
	pData = nano_fiber_fifo_get_wait(&nanoFifoObj2);
	if (pData != pPutList2[0]) {
		TC_ERROR("fiber1 (2) - expected 0x%x, got 0x%x\n",
				 pPutList2[0], pData);
		retCode = TC_FAIL;
		return;
	}

	nano_fiber_sem_take_wait(&nanoSemObj1);   /* Wait for fiber1 to be reactivated */

	TC_PRINT("Test Fiber FIFO Get\n\n");
	/* Get all FIFOs */
	while ((pData = nano_fiber_fifo_get(&nanoFifoObj)) != NULL) {
		TC_PRINT("FIBER FIFO Get: count = %d, ptr is %p\n", count, pData);
		if ((count >= NUM_FIFO_ELEMENT) || (pData != pPutList1[count])) {
			TCERR1(count);
			retCode = TC_FAIL;
			return;
		}
		count++;
	}

	TC_END_RESULT(retCode);
	PRINT_LINE;

	/*
	 * Entries in the FIFO queue have to be unique.
	 * Put data.
	 */
	TC_PRINT("Test Fiber FIFO Put\n");
	TC_PRINT("\nFIBER FIFO Put Order: ");
	for (int i=0; i<NUM_FIFO_ELEMENT; i++) {
		nano_fiber_fifo_put(&nanoFifoObj, pPutList2[i]);
		TC_PRINT(" %p,", pPutList2[i]);
	}
	TC_PRINT("\n");
	PRINT_LINE;

	/* Give semaphore to allow the main task to run */
	nano_fiber_sem_give(&nanoSemObjTask);

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

	TC_PRINT("Test Fiber STACK Pop Wait Interfaces\n\n");
	rc = nano_fiber_stack_pop(&nanoStackObj2, &data, TICKS_UNLIMITED);
	TC_PRINT("FIBER STACK Pop from queue2: %d\n", data);
	/* Verify results */
	if ((rc == 0) || (data != myData[0])) {
		retCode = TC_FAIL;
		TCERR2;
		return;
	}

	data = myData[1];
	TC_PRINT("FIBER STACK Push to queue1: %d\n", data);
	nano_fiber_stack_push(&nanoStackObj, data);

	rc = nano_fiber_stack_pop(&nanoStackObj2, &data, TICKS_UNLIMITED);
	TC_PRINT("FIBER STACK Pop from queue2: %d\n", data);
	/* Verify results */
	if ((rc == 0) || (data != myData[2])) {
		retCode = TC_FAIL;
		TCERR2;
		return;
	}

	data = myData[3];
	TC_PRINT("FIBER STACK Push to queue1: %d\n", data);
	nano_fiber_stack_push(&nanoStackObj, data);

	TC_END_RESULT(retCode);

}  /* testFiberStackPopW */
Exemplo n.º 9
0
static u32_t verify_cmac_null_msg(TCCmacState_t s)
{
	u32_t result = TC_PASS;

	TC_PRINT("Performing CMAC test #2 (SP 800-38B test vector #1):\n");

	const u8_t tag[BUF_LEN] = {
		0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
		0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
	};
	u8_t Tag[BUF_LEN];

	(void) tc_cmac_init(s);
	(void) tc_cmac_update(s, (const u8_t *) 0, 0);
	(void) tc_cmac_final(Tag, s);

	if (memcmp(Tag, tag, BUF_LEN) != 0) {
		TC_ERROR("%s: aes_cmac failed with null msg = 1\n", __func__);
		show("expected Tag =", tag, sizeof(tag));
		show("computed Tag =", Tag, sizeof(Tag));
		return TC_FAIL;
	}

	TC_END_RESULT(result);
	return result;
}
Exemplo n.º 10
0
void testTaskFifoGetW(void)
{
	void *pGetData;   /* pointer to FIFO object get from the queue */
	void *pPutData;   /* pointer to FIFO object to put to the queue */

	PRINT_LINE;
	TC_PRINT("Test Task FIFO Get Wait Interfaces\n\n");
	pPutData = pMyFifoData1;
	TC_PRINT("TASK FIFO Put to queue2: %p\n", pPutData);
	nano_task_fifo_put(&nanoFifoObj2, pPutData);

	/* Activate fiber2 */
	nano_task_sem_give(&nanoSemObj2);

	pGetData = nano_task_fifo_get(&nanoFifoObj, TICKS_UNLIMITED);
	TC_PRINT("TASK FIFO Get from queue1: %p\n", pGetData);
	/* Verify results */
	if (pGetData != pMyFifoData2) {
		retCode = TC_FAIL;
		TCERR2;
		return;
	}

	pPutData = pMyFifoData3;
	TC_PRINT("TASK FIFO Put to queue2: %p\n", pPutData);
	nano_task_fifo_put(&nanoFifoObj2, pPutData);

	TC_END_RESULT(retCode);
} /* testTaskFifoGetW */
Exemplo n.º 11
0
void testFiberFifoGetW(void)
{
	void *pGetData;   /* pointer to FIFO object get from the queue */
	void *pPutData;   /* pointer to FIFO object to put to the queue */

	TC_PRINT("Test Fiber FIFO Get Wait Interfaces\n\n");
	pGetData = nano_fiber_fifo_get(&nanoFifoObj2, TICKS_UNLIMITED);
	TC_PRINT("FIBER FIFO Get from queue2: %p\n", pGetData);
	/* Verify results */
	if (pGetData != pMyFifoData1) {
		retCode = TC_FAIL;
		TCERR2;
		return;
	}

	pPutData = pMyFifoData2;
	TC_PRINT("FIBER FIFO Put to queue1: %p\n", pPutData);
	nano_fiber_fifo_put(&nanoFifoObj, pPutData);

	pGetData = nano_fiber_fifo_get(&nanoFifoObj2, TICKS_UNLIMITED);
	TC_PRINT("FIBER FIFO Get from queue2: %p\n", pGetData);
	/* Verify results */
	if (pGetData != pMyFifoData3) {
		retCode = TC_FAIL;
		TCERR2;
		return;
	}

	pPutData = pMyFifoData4;
	TC_PRINT("FIBER FIFO Put to queue1: %p\n", pPutData);
	nano_fiber_fifo_put(&nanoFifoObj, pPutData);

	TC_END_RESULT(retCode);

}  /* testFiberFifoGetW */
Exemplo n.º 12
0
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);
}
Exemplo n.º 13
0
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);
}
Exemplo n.º 14
0
void fiber1(void)
{
	uint32_t    data;        /* data used to put and get from the stack queue */
	int         count = 0;   /* counter */

	TC_PRINT("Test Fiber STACK Pop\n\n");
	/* Get all data */
	while (nano_fiber_stack_pop(&nanoStackObj, &data, TICKS_NONE) != 0) {
		TC_PRINT("FIBER STACK Pop: count = %d, data is %d\n", count, data);
		if ((count >= NUM_STACK_ELEMENT) || (data != myData[NUM_STACK_ELEMENT - 1 - count])) {
			TCERR1(count);
			retCode = TC_FAIL;
			return;
		}
		count++;
	}

	TC_END_RESULT(retCode);
	PRINT_LINE;

	/* Put data */
	TC_PRINT("Test Fiber STACK Push\n");
	TC_PRINT("\nFIBER STACK Put Order: ");
	for (int i=NUM_STACK_ELEMENT; i>0; i--) {
		nano_fiber_stack_push(&nanoStackObj, myData[i-1]);
		TC_PRINT(" %d,", myData[i-1]);
	}
	TC_PRINT("\n");
	PRINT_LINE;

	/* Give semaphore to allow the main task to run */
	nano_fiber_sem_give(&nanoSemObj);

} /* fiber1 */
Exemplo n.º 15
0
uint32_t test_14(void)
{
        uint32_t result = TC_PASS;

        TC_PRINT("SHA256 test #14:\n");
        const uint8_t expected[32] = {
                0x46, 0x1c, 0x19, 0xa9, 0x3b, 0xd4, 0x34, 0x4f, 0x92, 0x15, 0xf5, 0xec,
                0x64, 0x35, 0x70, 0x90, 0x34, 0x2b, 0xc6, 0x6b, 0x15, 0xa1, 0x48, 0x31,
                0x7d, 0x27, 0x6e, 0x31, 0xcb, 0xc2, 0x0b, 0x53
        };
        uint8_t m[32768];
        uint8_t digest[32];
        struct tc_sha256_state_struct s;
        uint32_t i;

        (void)memset(m, 0x00, sizeof(m));

        (void) tc_sha256_init(&s);
        for (i = 0; i < 33280; ++i) {
                tc_sha256_update(&s, m, sizeof(m));
        }
        (void) tc_sha256_final(digest, &s);

        result = check_result(14, expected, sizeof(expected), digest, sizeof(digest));
        TC_END_RESULT(result);
        return result;
}
Exemplo n.º 16
0
uint32_t test_12(void)
{
        uint32_t result = TC_PASS;

        TC_PRINT("SHA256 test #12:\n");
        const uint8_t expected[32] = {
                0xd2, 0x97, 0x51, 0xf2, 0x64, 0x9b, 0x32, 0xff, 0x57, 0x2b, 0x5e, 0x0a,
                0x9f, 0x54, 0x1e, 0xa6, 0x60, 0xa5, 0x0f, 0x94, 0xff, 0x0b, 0xee, 0xdf,
                0xb0, 0xb6, 0x92, 0xb9, 0x24, 0xcc, 0x80, 0x25
        };
        uint8_t m[1000];
        uint8_t digest[32];
        struct tc_sha256_state_struct s;
        uint32_t i;

        (void)memset(m, 0x00, sizeof(m));

        (void)tc_sha256_init(&s);
        for (i = 0; i < 1000; ++i) {
                tc_sha256_update(&s, m, sizeof(m));
        }
        (void)tc_sha256_final(digest, &s);

        result = check_result(12, expected, sizeof(expected), digest, sizeof(digest));
        TC_END_RESULT(result);
        return result;
}
Exemplo n.º 17
0
void testTaskStackPopW(void)
{
	uint32_t  data;     /* data used to put and get from the stack queue */
	int rc;

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

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

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

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

	TC_END_RESULT(retCode);
}  /* testTaskStackPopW */
Exemplo n.º 18
0
void fiber2(void)
{
	testFiberStackPopW();
	PRINT_LINE;
	testIsrStackFromFiber();

	TC_END_RESULT(retCode);
}
Exemplo n.º 19
0
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);
}
Exemplo n.º 20
0
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);
}
Exemplo n.º 21
0
void HelperTask(void)
{
	void *ptr[NUMBLOCKS];      /* Pointer to memory block */

	/* Wait for part 1 to complete */
	task_sem_take(SEM_REGRESSDONE, TICKS_UNLIMITED);

	/* Part 2 of test */

	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 exitTest1;          /* terminate test */
	}

	task_sem_give(SEM_HELPERDONE);  /* Indicate part 2 is complete */
	/* Wait for part 3 to complete */
	task_sem_take(SEM_REGRESSDONE, TICKS_UNLIMITED);

	/*
	 * Part 4 of test.
	 * Free the first memory block.  RegressionTask is currently blocked
	 * waiting (with a timeout) for a memory block.  Freeing the memory
	 * block will unblock RegressionTask.
	 */

	TC_PRINT("%s: About to free a memory block\n", __func__);
	task_mem_map_free(MAP_LgBlks, &ptr[0]);
	task_sem_give(SEM_HELPERDONE);

	/* Part 5 of test */
	task_sem_take(SEM_REGRESSDONE, TICKS_UNLIMITED);
	TC_PRINT("%s: About to free another memory block\n", __func__);
	task_mem_map_free(MAP_LgBlks, &ptr[1]);

	/*
	 * Free all the other blocks.  The first 2 blocks are freed by this task
	 */
	for (int i = 2; i < NUMBLOCKS; i++) {
		task_mem_map_free(MAP_LgBlks, &ptr[i]);
	}
	TC_PRINT("%s: freed all blocks allocated by this task\n", __func__);

exitTest1:

	TC_END_RESULT(tcRC);
	task_sem_give(SEM_HELPERDONE);
}  /* HelperTask */
Exemplo n.º 22
0
void fiber2(void)
{
	void *pData;    /* pointer to FIFO object from the queue */

	/* Wait for fiber2 to be activated */

	nano_fiber_sem_take(&nanoSemObj2, TICKS_UNLIMITED);

	/* Wait for data to be added to <nanoFifoObj> */
	pData = nano_fiber_fifo_get(&nanoFifoObj, TICKS_UNLIMITED);
	if (pData != pPutList1[1]) {
		TC_ERROR("fiber2 (1) - expected 0x%x, got 0x%x\n",
				 pPutList1[1], pData);
		retCode = TC_FAIL;
		return;
	}

	/* Wait for data to be added to <nanoFifoObj2> by fiber3 */
	pData = nano_fiber_fifo_get(&nanoFifoObj2, TICKS_UNLIMITED);
	if (pData != pPutList2[1]) {
		TC_ERROR("fiber2 (2) - expected 0x%x, got 0x%x\n",
				 pPutList2[1], pData);
		retCode = TC_FAIL;
		return;
	}

	/* Wait for fiber2 to be reactivated */
	nano_fiber_sem_take(&nanoSemObj2, TICKS_UNLIMITED);

	/* Fiber #2 has been reactivated by main task */
	for (int i = 0; i < 4; i++) {
		pData = nano_fiber_fifo_get(&nanoFifoObj, TICKS_UNLIMITED);
		if (pData != pPutList1[i]) {
			TC_ERROR("fiber2 (3) - iteration %d expected 0x%x, got 0x%x\n",
					 i, pPutList1[i], pData);
			retCode = TC_FAIL;
			return;
		}
	}

	nano_fiber_sem_give(&nanoSemObjTask); /* Wake main task */
	/* Wait for fiber2 to be reactivated */
	nano_fiber_sem_take(&nanoSemObj2, TICKS_UNLIMITED);

	testFiberFifoGetW();
	PRINT_LINE;
	testIsrFifoFromFiber();

	TC_END_RESULT(retCode);
}  /* fiber2 */
Exemplo n.º 23
0
void testIsrFifoFromTask(void)
{
	void *pGetData;   /* pointer to FIFO object get from the queue */
	void *pPutData;   /* pointer to FIFO object put to queue */
	int count = 0;      /* counter */

	TC_PRINT("Test ISR FIFO (invoked from Task)\n\n");

	/* This is data pushed by function testIsrFifoFromFiber
	 * Get all FIFOs
	 */
	_trigger_nano_isr_fifo_get();
	pGetData = isrFifoInfo.data;

	while (pGetData != NULL) {
		TC_PRINT("Get from queue1: count = %d, ptr is %p\n", count, pGetData);
		if ((count >= NUM_FIFO_ELEMENT) || (pGetData != pPutList1[count])) {
			TCERR1(count);
			retCode = TC_FAIL;
			return;
		}

		/* Get the next element */
		_trigger_nano_isr_fifo_get();
		pGetData = isrFifoInfo.data;
		count++;
	}  /* while */


	/* Put data into queue and get it again */
	pPutData = pPutList2[3];

	isrFifoInfo.data = pPutData;
	_trigger_nano_isr_fifo_put();
	isrFifoInfo.data = NULL;    /* force data to a new value */
	/* Get data from queue */
	_trigger_nano_isr_fifo_get();
	pGetData = isrFifoInfo.data;
	/* Verify data */
	if (pGetData != pPutData) {
		retCode = TC_FAIL;
		TCERR2;
		return;
	} else {
		TC_PRINT("\nTest ISR FIFO (invoked from Task) - put %p and get back %p\n",
				 pPutData, pGetData);
	}

	TC_END_RESULT(retCode);
}  /* testIsrFifoFromTask */
Exemplo n.º 24
0
static u32_t verify_gf_2_128_double(u8_t *K1, u8_t *K2, struct tc_cmac_struct s)
{
	u32_t result = TC_PASS;

	TC_PRINT("Performing CMAC test #1 (GF(2^128) double):\n");

	u8_t zero[BUF_LEN];
	u8_t L[BUF_LEN];
	const u8_t l[BUF_LEN] = {
		0x7d, 0xf7, 0x6b, 0x0c, 0x1a, 0xb8, 0x99, 0xb3,
		0x3e, 0x42, 0xf0, 0x47, 0xb9, 0x1b, 0x54, 0x6f
	};
	const u8_t k1[BUF_LEN] = {
		0xfb, 0xee, 0xd6, 0x18, 0x35, 0x71, 0x33, 0x66,
		0x7c, 0x85, 0xe0, 0x8f, 0x72, 0x36, 0xa8, 0xde
	};
	const u8_t k2[BUF_LEN] = {
		0xf7, 0xdd, 0xac, 0x30, 0x6a, 0xe2, 0x66, 0xcc,
		0xf9, 0x0b, 0xc1, 0x1e, 0xe4, 0x6d, 0x51, 0x3b
	};

	(void) memset(zero, '\0', sizeof(zero));
	tc_aes_encrypt(L, zero, s.sched);
	if (memcmp(L, l, BUF_LEN) != 0) {
		TC_ERROR("%s: AES encryption failed\n", __func__);
		show("expected L =", l, sizeof(l));
		show("computed L =", L, sizeof(L));
		return TC_FAIL;
	}

	gf_double(K1, L);
	if (memcmp(K1, k1, BUF_LEN) != 0) {
		TC_ERROR("%s: gf_2_128_double failed when msb = 0\n", __func__);
		show("expected K1 =", k1, sizeof(k1));
		show("computed K1 =", K1, sizeof(k1));
		return TC_FAIL;
	}

	gf_double(K2, K1);
	if (memcmp(K2, k2, BUF_LEN) != 0) {
		TC_ERROR("%s: gf_2_128_double failed when msb = 1\n", __func__);
		show("expected K2 =", k2, sizeof(k2));
		show("computed K2 =", K2, sizeof(k2));
		return TC_FAIL;
	}

	TC_END_RESULT(result);
	return result;
}
Exemplo n.º 25
0
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);
}
Exemplo n.º 26
0
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);
}
Exemplo n.º 27
0
void testIsrStackFromTask(void)
{
	uint32_t  result = INVALID_DATA;     /* data used to put and get from the stack queue */
	int       count  = 0;

	TC_PRINT("Test ISR STACK (invoked from Task)\n\n");

	/* Get all data */
	_trigger_nano_isr_stack_pop();
	result = isrStackInfo.data;

	while (result != INVALID_DATA) {
		TC_PRINT("  Pop from queue1: count = %d, data is %d\n", count, result);
		if ((count >= NUM_STACK_ELEMENT) || (result != myIsrData[NUM_STACK_ELEMENT - count - 1])) {
			TCERR1(count);
			retCode = TC_FAIL;
			return;
		}  /* if */

		/* Get the next element */
		_trigger_nano_isr_stack_pop();
		result = isrStackInfo.data;
		count++;
	}  /* while */


	/* Put data into stack and get it again */
	isrStackInfo.data = myIsrData[3];
	_trigger_nano_isr_stack_push();
	isrStackInfo.data = INVALID_DATA;   /* force variable to a new value */
	/* Get data from stack */
	_trigger_nano_isr_stack_pop();
	result = isrStackInfo.data;
	/* Verify data */
	if (result != myIsrData[3]) {
		TCERR2;
		retCode = TC_FAIL;
		return;
	} else {
		TC_PRINT("\nTest ISR STACK (invoked from Task) - push %d and pop back %d\n",
				 myIsrData[3], result);
	}

	TC_END_RESULT(retCode);
}
Exemplo n.º 28
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);
}
Exemplo n.º 29
0
/*
 * 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;
}
Exemplo n.º 30
0
void testIsrStackFromFiber(void)
{
	uint32_t  result = INVALID_DATA;     /* data used to put and get from the stack queue */

	TC_PRINT("Test ISR STACK (invoked from Fiber)\n\n");

	/* This is data pushed by function testFiberStackPopW */
	_trigger_nano_isr_stack_pop();
	result = isrStackInfo.data;
	if (result != INVALID_DATA) {
		TC_PRINT("ISR STACK (running in fiber) Pop from queue1: %d\n", result);
		if (result != myData[3]) {
			retCode = TC_FAIL;
			TCERR2;
			return;
		}
	}

	/* Verify that the STACK is empty */
	_trigger_nano_isr_stack_pop();
	result = isrStackInfo.data;
	if (result != INVALID_DATA) {
		 TC_PRINT("Pop from queue1: %d\n", result);
		 retCode = TC_FAIL;
		 TCERR3;
		 return;
	}

	/* Put more data into STACK */
	TC_PRINT("ISR STACK (running in fiber) Push to queue1:\n");
	for (int i=0; i<NUM_STACK_ELEMENT; i++) {
		isrStackInfo.data = myIsrData[i];
		TC_PRINT("  %d, ", myIsrData[i]);
		_trigger_nano_isr_stack_push();
	}
	TC_PRINT("\n");

	/* Set variable to INVALID_DATA to ensure [data] changes */
	isrStackInfo.data = INVALID_DATA;

	TC_END_RESULT(retCode);

}  /* testIsrStackFromFiber */