Пример #1
0
TEST(shell, start)
{
	char test_chars[] = {
		'0', '1', '2', '3', '4', '5', '6', '7',
		'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
		'\n', 0
	};
	char *p = test_chars;

	s_handle = shell_create(s_pool, POOL_SIZE,
			stub_putc, stub_getc, stub_exec, NULL);
	TEST_ASSERT_NOT_NULL( s_handle );
	TEST_ASSERT_UNLESS( shell_set_prompt(s_handle, "") );

	pthread_create(&s_thread, NULL, thread_shell, NULL);

	while (*p) {
		while (s_txc);
		s_txc = *p++;
	}

	pthread_mutex_lock(&s_mutex);
	pthread_cond_wait(&s_cv, &s_mutex);
	pthread_mutex_unlock(&s_mutex);

	TEST_ASSERT_EQUAL_STRING_LEN(test_chars, s_rxbuf, strlen(test_chars));
	/* excludes new line code */
	TEST_ASSERT_EQUAL_STRING_LEN(test_chars, s_result_line, strlen(test_chars) - 1);

	TEST_ASSERT_UNLESS( shell_destroy(s_handle) );
	s_txc = '\n';

	pthread_join(s_thread, NULL);
}
Пример #2
0
TEST(shell, set_prompt)
{
	s_handle = shell_create(s_pool, POOL_SIZE,
			stub_putc, stub_getc, stub_exec, NULL);
	TEST_ASSERT_NOT_NULL( s_handle );
	TEST_ASSERT( shell_set_prompt(s_handle, NULL) );
	TEST_ASSERT_UNLESS( shell_set_prompt(s_handle, "hoge") );
	TEST_ASSERT_UNLESS( shell_set_prompt(s_handle, "") );
}
Пример #3
0
TEST(fixed_memorypool, destroy)
{
	s_handle = fixedmpool_create(s_pool, s_blocksize, s_blockcount);
	TEST_ASSERT_NOT_NULL( s_handle );
	TEST_ASSERT_UNLESS( fixedmpool_destroy(s_handle) );
	TEST_ASSERT_NULL( fixedmpool_allocate(s_handle) );
}
Пример #4
0
TEST(fixed_memorypool, free)
{
	uint8_t *p[BLOCK_COUNT];
	uint8_t *q[BLOCK_COUNT];
	int i;

	s_handle = fixedmpool_create(s_pool, s_blocksize, s_blockcount);
	TEST_ASSERT_NOT_NULL( s_handle );

	for (i=0; i<(int)s_blockcount; i++) {
		p[i] = q[i] = fixedmpool_allocate(s_handle);
		/* 
		 *  p[0] = q[0]
		 *  p[1] = q[1]
		 *  p[2] = q[2]
		 *  p[3] = q[3]
		 */
		TEST_ASSERT_NOT_NULL( p[i] );
	}

	TEST_ASSERT_UNLESS( fixedmpool_free(s_handle, p[0]) );
	p[0] = fixedmpool_allocate(s_handle);
	TEST_ASSERT_EQUAL_PTR( p[0], q[0] );

	{
		int random_idxs[BLOCK_COUNT] = { 3, 0, 1, 2 };
		/* 
		 *  p[0] = q[3]
		 *  p[1] = q[0]
		 *  p[2] = q[1]
		 *  p[3] = q[2]
		 */
		for (i=0; i<(int)s_blockcount; i++) {
			int idx = random_idxs[i];
			TEST_ASSERT_UNLESS( fixedmpool_free(s_handle, p[idx]) );
		}
		for (i=0; i<(int)s_blockcount; i++) {
			/* LIFO */
			int idx = random_idxs[s_blockcount - 1 - i];
			p[i] = fixedmpool_allocate(s_handle);
			TEST_ASSERT_EQUAL_PTR( p[i], q[idx] );
		}
	}

	TEST_ASSERT_UNLESS( fixedmpool_free(s_handle, p[0]) );
	TEST_ASSERT( fixedmpool_free(s_handle, p[0]) );
}
Пример #5
0
TEST(shell, hook)
{
	char test_chars[] = {
		'a', '\n', 0
	};
	char *p;

	// OK hook
	s_error = 1;
	p = test_chars;
	s_handle = shell_create(s_pool, POOL_SIZE,
			stub_putc, stub_getc, stub_exec_ok, stub_post_hook);
	TEST_ASSERT_NOT_NULL( s_handle );
	pthread_create(&s_thread, NULL, thread_shell, NULL);
	while (*p) {
		while (s_txc);
		s_txc = *p++;
	}

	pthread_mutex_lock(&s_mutex);
	pthread_cond_wait(&s_cv, &s_mutex);
	pthread_mutex_unlock(&s_mutex);
	TEST_ASSERT_EQUAL_INT32( 0, s_error );
	TEST_ASSERT_UNLESS( shell_destroy(s_handle) );
	s_txc = '\n';
	pthread_join(s_thread, NULL);


	// NG hook
	s_error = 0;
	p = test_chars;
	s_handle = shell_create(s_pool, POOL_SIZE,
			stub_putc, stub_getc, stub_exec_ng, stub_post_hook);
	TEST_ASSERT_NOT_NULL( s_handle );
	pthread_create(&s_thread, NULL, thread_shell, NULL);
	while (*p) {
		while (s_txc);
		s_txc = *p++;
	}
	pthread_mutex_lock(&s_mutex);
	pthread_cond_wait(&s_cv, &s_mutex);
	pthread_mutex_unlock(&s_mutex);
	TEST_ASSERT_EQUAL_INT32( -1, s_error );
	TEST_ASSERT_UNLESS( shell_destroy(s_handle) );
	s_txc = '\n';
	pthread_join(s_thread, NULL);
}
Пример #6
0
TEST(shell, destroy)
{
	s_handle = shell_create(s_pool, POOL_SIZE,
			stub_putc, stub_getc, stub_exec, NULL);
	TEST_ASSERT_NOT_NULL( s_handle );
	TEST_ASSERT_UNLESS( shell_destroy(s_handle) );
	TEST_ASSERT( shell_start(s_handle) );
}
Пример #7
0
void testNotUnless(void)
{
    int failed;

    EXPECT_ABORT_BEGIN
    TEST_ASSERT_UNLESS(1);
    EXPECT_ABORT_END

    failed = Unity.CurrentTestFailed;
    Unity.CurrentTestFailed = 0;

    TEST_ASSERT_EQUAL_INT(1U, failed);
    TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);
}
Пример #8
0
TEST(fixed_memorypool, size)
{
	uint8_t *p[BLOCK_COUNT];
	int i, using = 0;

	s_handle = fixedmpool_create(s_pool, s_blocksize, s_blockcount);
	TEST_ASSERT_NOT_NULL( s_handle );

	TEST_ASSERT_EQUAL_UINT32( s_blockcount, fixedmpool_available_blocks(s_handle) );
	TEST_ASSERT_EQUAL_UINT32( 0, fixedmpool_used_blocks(s_handle) );

	for (i=0; i<(int)s_blockcount; i++) {
		p[i] = fixedmpool_allocate(s_handle);
		TEST_ASSERT_NOT_NULL( p[i] );
		using++;
		TEST_ASSERT_EQUAL_UINT32( s_blockcount - using, fixedmpool_available_blocks(s_handle) );
		TEST_ASSERT_EQUAL_UINT32( using, fixedmpool_used_blocks(s_handle) );
	}
	TEST_ASSERT_NULL( fixedmpool_allocate(s_handle) );
	TEST_ASSERT_EQUAL_UINT32( s_blockcount - using, fixedmpool_available_blocks(s_handle) );
	TEST_ASSERT_EQUAL_UINT32( using, fixedmpool_used_blocks(s_handle) );

	{
		int random_idxs[BLOCK_COUNT] = { 3, 1, 2, 0 };
		for (i=0; i<(int)s_blockcount; i++) {
			int idx = random_idxs[i];
			TEST_ASSERT_UNLESS( fixedmpool_free(s_handle, p[idx]) );
			using--;
			TEST_ASSERT_EQUAL_UINT32( s_blockcount - using, fixedmpool_available_blocks(s_handle) );
			TEST_ASSERT_EQUAL_UINT32( using, fixedmpool_used_blocks(s_handle) );
		}
	}
	TEST_ASSERT( fixedmpool_free(s_handle, p[0]) );
	TEST_ASSERT_EQUAL_UINT32( s_blockcount - using, fixedmpool_available_blocks(s_handle) );
	TEST_ASSERT_EQUAL_UINT32( using, fixedmpool_used_blocks(s_handle) );
}
Пример #9
0
void testFalse(void)
{
    TEST_ASSERT_FALSE(0);

    TEST_ASSERT_UNLESS(0);
}
Пример #10
0
void testNotUnless(void)
{
    EXPECT_ABORT_BEGIN
    TEST_ASSERT_UNLESS(1);
    VERIFY_FAILS_END
}
Пример #11
0
static void* thread_shell(void* args)
{
	TEST_ASSERT_UNLESS( shell_start(s_handle) );
	return NULL;
}