예제 #1
0
static void thread_entry(void* parameter)
{
	rt_tick_t tick;
	rt_kprintf("thread inited ok\n");

	tick = rt_tick_get();
	rt_kprintf("thread delay 10 tick\n");
	rt_thread_delay(10);
	if (rt_tick_get() - tick > 10)
	{
		tc_done(TC_STAT_FAILED);
		return;
	}

	tick = rt_tick_get();
	rt_kprintf("thread delay 15 tick\n");
	rt_thread_delay(15);
	if (rt_tick_get() - tick > 15)
	{
		tc_done(TC_STAT_FAILED);
		return;
	}

	rt_kprintf("thread exit\n");

	tc_done(TC_STAT_PASSED);
}
예제 #2
0
static void heap_malloc_init()
{
	rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;

	ptr1 = rt_malloc(1);
	ptr2 = rt_malloc(13);
	ptr3 = rt_malloc(31);
	ptr4 = rt_malloc(127);
	ptr5 = rt_malloc(0);

	memset(ptr1, 1, 1);
	memset(ptr2, 2, 13);
	memset(ptr3, 3, 31);
	memset(ptr4, 4, 127);

	if (mem_check(ptr1, 1, 1)   != RT_FALSE) goto _failed;
	if (mem_check(ptr2, 2, 13)  != RT_FALSE) goto _failed;
	if (mem_check(ptr3, 3, 31)  != RT_FALSE) goto _failed;
	if (mem_check(ptr4, 4, 127) != RT_FALSE) goto _failed;

	rt_free(ptr4);
	rt_free(ptr3);
	rt_free(ptr3);
	rt_free(ptr1);

	if (ptr5 != RT_NULL)
	{
		rt_free(ptr5);
	}

	tc_done(TC_STAT_PASSED);

_failed:
	tc_done(TC_STAT_FAILED);
}
예제 #3
0
/* 线程入口 */
static void thread_entry(void* parameter)
{
	rt_err_t result;
	rt_tick_t tick;

	/* 获得当前的OS Tick */
	tick = rt_tick_get();

	/* 试图持有信号量,最大等待10个OS Tick后返回 */
	result = rt_sem_take(&sem, 10);
	if (result == -RT_ETIMEOUT)
	{
		/* 超时后判断是否刚好是10个OS Tick */
		if (rt_tick_get() - tick != 10)
		{
			tc_done(TC_STAT_FAILED);
			rt_sem_detach(&sem);
			return;
		}
		rt_kprintf("take semaphore timeout\n");
	}
	else
	{
		/* 因为没有其他地方是否信号量,所以不应该成功持有信号量,否则测试失败 */
		tc_done(TC_STAT_FAILED);
		rt_sem_detach(&sem);
		return;
	}

	/* 释放一次信号量 */
	rt_sem_release(&sem);

	/* 永久等待方式持有信号量 */
	result = rt_sem_take(&sem, RT_WAITING_FOREVER);
	if (result != RT_EOK)
	{
		/* 不成功则测试失败 */
		tc_done(TC_STAT_FAILED);
		rt_sem_detach(&sem);
		return;
	}

	/* 测试通过 */
	tc_done(TC_STAT_PASSED);
	/* 脱离信号量对象 */
	rt_sem_detach(&sem);
}
static void thread_entry(void* parameter)
{
    rt_kprintf("thread dynamicly created ok\n");
    rt_thread_delay(10);
    rt_kprintf("thread exit\n");

    tc_done(TC_STAT_PASSED);
}
예제 #5
0
static void _tc_cleanup()
{
	/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
	rt_enter_critical();

	/* 删除定时器对象 */
	rt_timer_delete(timer1);
	timer1 = RT_NULL;

	/* 调度器解锁 */
	rt_exit_critical();

	/* 设置TestCase状态 */
	tc_done(TC_STAT_PASSED);
}
static void _tc_cleanup()
{
    /* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
    rt_enter_critical();

    /* 执行定时器脱离 */
    rt_timer_detach(&timer1);
    rt_timer_detach(&timer2);

    /* 调度器解锁 */
    rt_exit_critical();

    /* 设置TestCase状态 */
    tc_done(TC_STAT_PASSED);
}
static void thread1_entry(void* parameter)
{
	rt_err_t result;

	while (1) {
		result = rt_sem_take(sem, RT_WAITING_FOREVER);
		if (result != RT_EOK) {
			tc_done(TC_STAT_FAILED);
			return;
		}

		t1_count ++;
		rt_kprintf("thread1: got semaphore, count: %d\n", t1_count);
	}
}
예제 #8
0
static void thread2_cleanup(struct rt_thread *tid)
{
	/*
	 * 线程2运行结束后也将自动被删除(线程控制块和线程栈在idle线
	 * 程中释放)
	 */

	if (tid != tid2)
	{
		tc_stat(TC_STAT_END | TC_STAT_FAILED);
		return ;
	}
	rt_kprintf("thread2 end\n");
	tid2 = RT_NULL;
	tc_done(TC_STAT_PASSED);
}
예제 #9
0
static void _tc_cleanup()
{
	/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
	rt_enter_critical();

	/* 删除线程 */
	if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
		rt_thread_delete(tid1);
	if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
		rt_thread_delete(tid2);

	/* 调度器解锁 */
	rt_exit_critical();

	/* 设置TestCase状态 */
	tc_done(TC_STAT_PASSED);
}
static void _tc_cleanup()
{
	/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
	rt_enter_critical();

	/* 执行线程脱离 */
	if (thread1.stat != RT_THREAD_CLOSE)
		rt_thread_detach(&thread1);
	if (thread2.stat != RT_THREAD_CLOSE)
		rt_thread_detach(&thread2);

	/* 调度器解锁 */
	rt_exit_critical();

	/* 设置TestCase状态 */
	tc_done(TC_STAT_PASSED);
}
예제 #11
0
static void _tc_cleanup(void)
{
	/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
	rt_enter_critical();

	/* 执行线程脱离 */
	if (thread.stat != RT_THREAD_CLOSE)
	{
		rt_thread_detach(&thread);

		/* 执行信号量对象脱离 */
		rt_sem_detach(&sem);
	}

	/* 调度器解锁 */
	rt_exit_critical();

	/* 设置TestCase状态 */
	tc_done(TC_STAT_PASSED);
}
static void _tc_cleanup()
{
    /* lock scheduler */
    rt_enter_critical();

    if (thread1.stat != RT_THREAD_CLOSE)
        rt_thread_detach(&thread1);
    if (thread2.stat != RT_THREAD_CLOSE)
        rt_thread_detach(&thread2);

    /* unlock scheduler */
    rt_exit_critical();

    rt_kprintf("t1_count=%d t2_count=%d\n",t1_count,t2_count);

    if (t1_count / t2_count != 2)
        tc_stat(TC_STAT_END | TC_STAT_FAILED);
    else
        tc_done(TC_STAT_PASSED);
}
static void _tc_cleanup()
{
    /* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
    rt_enter_critical();

    /* 删除信号量 */
    if (sem != RT_NULL)
        rt_sem_delete(sem);

    /* 删除线程 */
    if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE)
        rt_thread_delete(tid);
    if (worker != RT_NULL && worker->stat != RT_THREAD_CLOSE)
        rt_thread_delete(worker);

    /* 调度器解锁 */
    rt_exit_critical();

    /* 设置TestCase状态 */
    tc_done(TC_STAT_PASSED);
}
예제 #14
0
static void _tc_cleanup(void)
{
    tc_done(TC_STAT_PASSED);
}