示例#1
0
/**
 *
 * @brief Test some context routines from a preemptible thread
 *
 * This routines tests the k_current_get() and
 * k_is_in_isr() routines from both a preemtible thread  and an ISR (that
 * interrupted a preemtible thread). Checking those routines with cooperative
 * threads are done elsewhere.
 *
 * @return TC_PASS on success
 * @return TC_FAIL on failure
 */
static int test_kernel_ctx_task(void)
{
	k_tid_t self_thread_id;

	TC_PRINT("Testing k_current_get() from an ISR and task\n");

	self_thread_id = k_current_get();
	isr_info.command = THREAD_SELF_CMD;
	isr_info.error = 0;
	/* isr_info is modified by the isr_handler routine */
	isr_handler_trigger();

	if (isr_info.error) {
		TC_ERROR("ISR detected an error\n");
		return TC_FAIL;
	}

	if (isr_info.data != (void *)self_thread_id) {
		TC_ERROR("ISR context ID mismatch\n");
		return TC_FAIL;
	}

	TC_PRINT("Testing k_is_in_isr() from an ISR\n");
	isr_info.command = EXEC_CTX_TYPE_CMD;
	isr_info.error = 0;
	isr_handler_trigger();

	if (isr_info.error) {
		TC_ERROR("ISR detected an error\n");
		return TC_FAIL;
	}

	if (isr_info.value != K_ISR) {
		TC_ERROR("isr_info.value was not K_ISR\n");
		return TC_FAIL;
	}

	TC_PRINT("Testing k_is_in_isr() from a preemptible thread\n");
	if (k_is_in_isr()) {
		TC_ERROR("Should not be in ISR context\n");
		return TC_FAIL;
	}
	if (_current->base.prio < 0) {
		TC_ERROR("Current thread should have preemptible priority\n");
		return TC_FAIL;
	}

	return TC_PASS;
}
示例#2
0
int strcpy_test(void)
{
	TC_PRINT("\tstrcpy ...\t");

	memset(buffer, '\0', BUFSIZE);
	strcpy(buffer, "10 chars!!\0");

	if (strcmp(buffer, "10 chars!!\0") != 0) {
		TC_PRINT("failed\n");
		return TC_FAIL;
	}

	TC_PRINT("passed\n");
	return TC_PASS;
}
示例#3
0
文件: sleep.c 项目: 32bitmicro/zephyr
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);
}
示例#4
0
文件: sha256.c 项目: rsalveti/zephyr
/*
 * NIST SHA256 test vector 2.
 */
void test_2(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #2:\n");
	const u8_t expected[32] = {
		0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, 0xe5, 0xc0,
		    0x26, 0x93,
		0x0c, 0x3e, 0x60, 0x39, 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff,
		    0x21, 0x67,
		0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1
	};
	const char *m =
	    "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
	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(2, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #2 failed.");
}
示例#5
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;
}
示例#6
0
int strncpy_test(void)
{
	TC_PRINT("\tstrncpy ...\t");

	memset(buffer, '\0', BUFSIZE);
	strncpy(buffer, "This is over 10 characters", BUFSIZE);

	/* Purposely different values */
	if (strncmp(buffer, "This is over 20 characters", BUFSIZE) != 0) {
		TC_PRINT("failed\n");
		return TC_FAIL;
	}

	TC_PRINT("passed\n");
	return TC_PASS;
}
示例#7
0
int testSemTaskNoWait(void)
{
	int  i;     /* loop counter */

	TC_PRINT("Giving and taking a semaphore in a task (non-blocking)\n");

	/*
	 * Give the semaphore many times and then make sure that it can only be
	 * taken that many times.
	 */

	for (i = 0; i < 32; i++) {
		nano_task_sem_give(&testSem);
	}

	for (i = 0; i < 32; i++) {
		if (nano_task_sem_take(&testSem) != 1) {
			TC_ERROR(" *** Expected nano_task_sem_take() to succeed, not fail\n");
			goto errorReturn;
		}
	}

	if (nano_task_sem_take(&testSem) != 0) {
		TC_ERROR(" *** Expected  nano_task_sem_take() to fail, not succeed!\n");
		goto errorReturn;
	}

	return TC_PASS;

errorReturn:
	return TC_FAIL;
}
示例#8
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;
}
示例#9
0
文件: sha256.c 项目: rsalveti/zephyr
void test_10(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #10:\n");
	const u8_t expected[32] = {
		0xc2, 0xe6, 0x86, 0x82, 0x34, 0x89, 0xce, 0xd2, 0x01, 0x7f,
		    0x60, 0x59,
		0xb8, 0xb2, 0x39, 0x31, 0x8b, 0x63, 0x64, 0xf6, 0xdc, 0xd8,
		    0x35, 0xd0,
		0xa5, 0x19, 0x10, 0x5a, 0x1e, 0xad, 0xd6, 0xe4
	};
	u8_t m[1000];
	u8_t digest[32];
	struct tc_sha256_state_struct s;

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

	(void)tc_sha256_init(&s);
	tc_sha256_update(&s, m, sizeof(m));
	(void)tc_sha256_final(digest, &s);

	result = check_result(10, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #10 failed.");

}
示例#10
0
文件: sha256.c 项目: rsalveti/zephyr
void test_9(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #9:\n");
	const u8_t expected[32] = {
		0x54, 0x1b, 0x3e, 0x9d, 0xaa, 0x09, 0xb2, 0x0b, 0xf8, 0x5f,
		    0xa2, 0x73,
		0xe5, 0xcb, 0xd3, 0xe8, 0x01, 0x85, 0xaa, 0x4e, 0xc2, 0x98,
		    0xe7, 0x65,
		0xdb, 0x87, 0x74, 0x2b, 0x70, 0x13, 0x8a, 0x53
	};
	u8_t m[1000];
	u8_t digest[32];
	struct tc_sha256_state_struct s;

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

	(void)tc_sha256_init(&s);
	tc_sha256_update(&s, m, sizeof(m));
	(void)tc_sha256_final(digest, &s);

	result = check_result(9, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #9 failed.");

}
示例#11
0
文件: sha256.c 项目: rsalveti/zephyr
void test_8(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #8:\n");
	const u8_t expected[32] = {
		0xf5, 0xa5, 0xfd, 0x42, 0xd1, 0x6a, 0x20, 0x30, 0x27, 0x98,
		    0xef, 0x6e,
		0xd3, 0x09, 0x97, 0x9b, 0x43, 0x00, 0x3d, 0x23, 0x20, 0xd9,
		    0xf0, 0xe8,
		0xea, 0x98, 0x31, 0xa9, 0x27, 0x59, 0xfb, 0x4b
	};
	u8_t m[64];
	u8_t digest[32];
	struct tc_sha256_state_struct s;

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

	(void)tc_sha256_init(&s);
	tc_sha256_update(&s, m, sizeof(m));
	(void)tc_sha256_final(digest, &s);

	result = check_result(8, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #8 failed.");

}
示例#12
0
文件: sha256.c 项目: rsalveti/zephyr
void test_7(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #7:\n");
	const u8_t expected[32] = {
		0x65, 0xa1, 0x6c, 0xb7, 0x86, 0x13, 0x35, 0xd5, 0xac, 0xe3,
		    0xc6, 0x07,
		0x18, 0xb5, 0x05, 0x2e, 0x44, 0x66, 0x07, 0x26, 0xda, 0x4c,
		    0xd1, 0x3b,
		0xb7, 0x45, 0x38, 0x1b, 0x23, 0x5a, 0x17, 0x85
	};
	u8_t m[57];
	u8_t digest[32];
	struct tc_sha256_state_struct s;

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

	(void)tc_sha256_init(&s);
	tc_sha256_update(&s, m, sizeof(m));
	(void)tc_sha256_final(digest, &s);

	result = check_result(7, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #7 failed.");

}
示例#13
0
文件: sha256.c 项目: rsalveti/zephyr
void test_6(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #6:\n");
	const u8_t expected[32] = {
		0xd4, 0x81, 0x7a, 0xa5, 0x49, 0x76, 0x28, 0xe7, 0xc7, 0x7e,
		    0x6b, 0x60,
		0x61, 0x07, 0x04, 0x2b, 0xbb, 0xa3, 0x13, 0x08, 0x88, 0xc5,
		    0xf4, 0x7a,
		0x37, 0x5e, 0x61, 0x79, 0xbe, 0x78, 0x9f, 0xbb
	};
	u8_t m[56];
	u8_t digest[32];
	struct tc_sha256_state_struct s;

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

	(void)tc_sha256_init(&s);
	tc_sha256_update(&s, m, sizeof(m));
	(void)tc_sha256_final(digest, &s);

	result = check_result(6, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #6 failed.");

}
示例#14
0
文件: sha256.c 项目: rsalveti/zephyr
void test_5(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #5:\n");
	const u8_t expected[32] = {
		0x02, 0x77, 0x94, 0x66, 0xcd, 0xec, 0x16, 0x38, 0x11, 0xd0,
		    0x78, 0x81,
		0x5c, 0x63, 0x3f, 0x21, 0x90, 0x14, 0x13, 0x08, 0x14, 0x49,
		    0x00, 0x2f,
		0x24, 0xaa, 0x3e, 0x80, 0xf0, 0xb8, 0x8e, 0xf7
	};
	u8_t m[55];
	u8_t digest[32];
	struct tc_sha256_state_struct s;

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

	(void)tc_sha256_init(&s);
	tc_sha256_update(&s, m, sizeof(m));
	(void)tc_sha256_final(digest, &s);

	result = check_result(5, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #5 failed.");

}
示例#15
0
文件: sha256.c 项目: rsalveti/zephyr
void test_4(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #4:\n");
	const u8_t expected[32] = {
		0x7a, 0xbc, 0x22, 0xc0, 0xae, 0x5a, 0xf2, 0x6c, 0xe9, 0x3d,
		    0xbb, 0x94,
		0x43, 0x3a, 0x0e, 0x0b, 0x2e, 0x11, 0x9d, 0x01, 0x4f, 0x8e,
		    0x7f, 0x65,
		0xbd, 0x56, 0xc6, 0x1c, 0xcc, 0xcd, 0x95, 0x04
	};
	const u8_t m[4] = { 0xc9, 0x8c, 0x8e, 0x55 };
	u8_t digest[32];
	struct tc_sha256_state_struct s;

	(void)tc_sha256_init(&s);
	tc_sha256_update(&s, m, sizeof(m));
	(void)tc_sha256_final(digest, &s);

	result = check_result(4, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #4 failed.");

}
示例#16
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;
}
示例#17
0
文件: sha256.c 项目: rsalveti/zephyr
void test_11(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #11:\n");
	const u8_t expected[32] = {
		0xf4, 0xd6, 0x2d, 0xde, 0xc0, 0xf3, 0xdd, 0x90, 0xea, 0x13,
		    0x80, 0xfa,
		0x16, 0xa5, 0xff, 0x8d, 0xc4, 0xc5, 0x4b, 0x21, 0x74, 0x06,
		    0x50, 0xf2,
		0x4a, 0xfc, 0x41, 0x20, 0x90, 0x35, 0x52, 0xb0
	};
	u8_t m[1005];
	u8_t digest[32];
	struct tc_sha256_state_struct s;

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

	(void)tc_sha256_init(&s);
	tc_sha256_update(&s, m, sizeof(m));
	(void)tc_sha256_final(digest, &s);

	result = check_result(11, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #11 failed.");

}
示例#18
0
int testSemFiberNoWait(void)
{
	int  i;

	TC_PRINT("Giving and taking a semaphore in a fiber (non-blocking)\n");

	/*
	 * Give the semaphore many times and then make sure that it can only be
	 * taken that many times.
	 */

	for (i = 0; i < 32; i++) {
		nano_fiber_sem_give(&testSem);
	}

	for (i = 0; i < 32; i++) {
		if (nano_fiber_sem_take(&testSem) != 1) {
			TC_ERROR(" *** Expected nano_fiber_sem_take() to succeed, not fail\n");
			goto errorReturn;
		}
	}

	if (nano_fiber_sem_take(&testSem) != 0) {
		TC_ERROR(" *** Expected  nano_fiber_sem_take() to fail, not succeed\n");
		goto errorReturn;
	}

	return TC_PASS;

errorReturn:
	fiberDetectedFailure = 1;
	return TC_FAIL;
}
示例#19
0
文件: sha256.c 项目: rsalveti/zephyr
void test_12(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #12:\n");
	const u8_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
	};
	u8_t m[1000];
	u8_t digest[32];
	struct tc_sha256_state_struct s;
	u32_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), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #12 failed.");
}
示例#20
0
文件: sha256.c 项目: rsalveti/zephyr
void test_13(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #13:\n");
	const u8_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
	};
	u8_t m[32768];
	u8_t digest[32];
	struct tc_sha256_state_struct s;
	u32_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), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #13 failed.");

}
示例#21
0
文件: sha256.c 项目: rsalveti/zephyr
void test_14(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #14:\n");
	const u8_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
	};
	u8_t m[32768];
	u8_t digest[32];
	struct tc_sha256_state_struct s;
	u32_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), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #14 failed.");

}
示例#22
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;
}
示例#23
0
文件: sha256.c 项目: rsalveti/zephyr
/*
 * 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.");
}
示例#24
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;
}
示例#25
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;
}
示例#26
0
文件: lifo.c 项目: 32bitmicro/zephyr
/* the task spins several fibers that pend and timeout on lifos */
static int test_multiple_fibers_pending(struct timeout_order_data *test_data,
										int test_data_size)
{
	int ii;

	for (ii = 0; ii < test_data_size; ii++) {
		task_fiber_start(timeout_stacks[ii], FIBER_STACKSIZE,
							test_fiber_pend_and_timeout,
							(int)&test_data[ii], 0,
							FIBER_PRIORITY, 0);
	}

	for (ii = 0; ii < test_data_size; ii++) {
		struct timeout_order_data *data =
			nano_task_fifo_get(&timeout_order_fifo, TICKS_UNLIMITED);

		if (data->timeout_order == ii) {
			TC_PRINT(" got fiber (q order: %d, t/o: %d, lifo %p) as expected\n",
						data->q_order, data->timeout, data->lifo);
		} else {
			TC_ERROR(" *** fiber %d woke up, expected %d\n",
						data->timeout_order, ii);
			return TC_FAIL;
		}
	}

	return TC_PASS;
}
示例#27
0
文件: sha256.c 项目: rsalveti/zephyr
void test_3(void)
{
	u32_t result = TC_PASS;

	TC_PRINT("SHA256 test #3:\n");
	const u8_t expected[32] = {
		0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f,
		    0x55, 0x4b,
		0x31, 0x3d, 0x05, 0x70, 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4,
		    0xb5, 0xaa,
		0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b
	};
	const u8_t m[1] = { 0xbd };
	u8_t digest[32];
	struct tc_sha256_state_struct s;

	(void)tc_sha256_init(&s);
	tc_sha256_update(&s, m, sizeof(m));
	(void)tc_sha256_final(digest, &s);

	result = check_result(3, expected, sizeof(expected),
			      digest, sizeof(digest), 1);

	/**TESTPOINT: Check result*/
	zassert_false(result, "SHA256 test #3 failed.");

}
示例#28
0
static int driver_open(void)
{
    TC_PRINT("driver: %s\n", __func__);

    /* Indicate that there is no real Bluetooth device */
    return EXPECTED_ERROR;
}
示例#29
0
文件: lifo.c 项目: 32bitmicro/zephyr
static int do_test_multiple_waiters(void)
{
	int ii;

	/* pend all fibers one the same lifo */
	for (ii = 0; ii < NUM_WAITERS; ii++) {
		task_fiber_start(fiber_multi_waiters_stacks[ii], FIBER_STACKSIZE,
						 fiber_multi_waiters, ii, 0, FIBER_PRIORITY, 0);
	}

	/* wake up all the fibers: the task is preempted each time */
	for (ii = 0; ii < NUM_WAITERS; ii++) {
		nano_task_lifo_put(&multi_waiters, &multi_waiters_items[ii]);
	}

	/* reply_multi_waiters will have been given once for each fiber */
	for (ii = 0; ii < NUM_WAITERS; ii++) {
		if (!nano_task_sem_take(&reply_multi_waiters, TICKS_NONE)) {
			TC_ERROR(" *** Cannot take sem supposedly given by waiters.\n");
			return TC_FAIL;
		}
	}

	TC_PRINT("Task took multi-waiter reply semaphore %d times, as expected.\n",
			 NUM_WAITERS);

	if (nano_task_lifo_get(&multi_waiters, TICKS_NONE)) {
		TC_ERROR(" *** multi_waiters should have been empty.\n");
		return TC_FAIL;
	}

	return TC_PASS;
}
示例#30
0
文件: sleep.c 项目: 32bitmicro/zephyr
static void test_objects_init(void)
{
	nano_sem_init(&test_fiber_sem);
	nano_sem_init(&helper_fiber_sem);
	nano_sem_init(&task_sem);

	TC_PRINT("Nanokernel objects initialized\n");
}