spice测试程序01-test-loop.c
来源:互联网 发布:软件质量保证书 编辑:程序博客网 时间:2024/06/08 04:16
spice-server测试程序,开个头:
/root/spice-0.13.3/server/tests/test-loop.c
static void ignore_sigpipe(void){ struct sigaction act; /* struct sigaction{ //信号处理函数,或是SIG_IGN,或是SIG_DFL void (*sa_handler)(int); //增加阻塞信号 sigset_t sa_mask; //信号选项 int sa_flags; void (*sa_sigaction)(int, siginfo_t *, void *); } */ memset(&act, 0, sizeof(act)); //初始化&act.sa_mask指向的信号集,使其包括所有的信号 sigfillset(&act.sa_mask); //遇到SIGPIPE信号时,本进程忽略。 act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); /* SIGPIPE: <1>.如果在写到管道时读进程已经终止,则产生此信号。 <2>.当类型为SOCK_STREAM的套接字已不再连接时,进程写到该套接字也产生此信号 《UNIX环境高级编程》 */}SpiceCoreInterface *basic_event_loop_init(void){ ignore_sigpipe(); spice_assert(main_context == NULL); main_context = g_main_context_new(); base_core_interface = event_loop_core; base_core_interface.main_context = main_context; return &core;}int main(int argc, char **argv){ SpiceTimer *timer, *timers[10]; int i, rc; memset(timers, 0, sizeof(timers)); core = basic_event_loop_init();// i = 0; /* add a timer and delete to check is correctly deleted */ timer = core->timer_add(timer_err, NULL); core->timer_start(timer, 1); core->timer_remove(timer); /* create timer, should not be executed */ timer = timers[i++] = core->timer_add(timer_err, NULL); /* add a timer and cancel to check is not executed */ timer = timers[i++] = core->timer_add(timer_err, NULL); core->timer_start(timer, 1); core->timer_cancel(timer); /* check we can remove timer inside a timer */ timer = to_delete_timer = core->timer_add(timer_del, NULL); spice_assert(to_delete_timer != NULL); core->timer_start(timer, 1); /* create a timer that does something */ timer = timers[i++] = core->timer_add(timer_exit, NULL); core->timer_start(timer, 10); /* test events are not called when freed */ timer = twice_timers_remove[0] = core->timer_add(timer_not_twice_remove, NULL); spice_assert(timer != NULL); core->timer_start(timer, 2); timer = twice_timers_remove[1] = core->timer_add(timer_not_twice_remove, NULL); spice_assert(timer != NULL); core->timer_start(timer, 2); /* test events are not called when cancelled */ timer = timers[i++] = twice_timers_cancel[0] = core->timer_add(timer_not_twice, core); spice_assert(timer != NULL); core->timer_start(timer, 4); timer = timers[i++] = twice_timers_cancel[1] = core->timer_add(timer_not_twice, core); spice_assert(timer != NULL); core->timer_start(timer, 4); /* run the loop */ loop = g_main_loop_new(basic_event_loop_get_context(), FALSE); alarm(1); rc = pthread_create(&loop_thread, NULL, loop_func, NULL); spice_assert(rc == 0); rc = pthread_join(loop_thread, NULL); spice_assert(rc == 0); alarm(0); g_main_loop_unref(loop); /* delete executed ? */ spice_assert(to_delete_timer == NULL); /* cleanup */ for (i = 0; i < G_N_ELEMENTS(timers); ++i) { if (timers[i]) { core->timer_remove(timers[i]); timers[i] = NULL; } } basic_event_loop_destroy(); return 0;}
//信号测试:
#include <stdlib.h>#include <stdio.h>#include <signal.h>#include <string.h>void handler(int signo){ printf("sig: %d\n", signo);}static void ignore_sigpipe(void){ struct sigaction act; memset(&act, 0, sizeof(act)); //sigemptyset(&act.sa_mask); sigfillset(&act.sa_mask); act.sa_handler = handler; sigaction(SIGPIPE, &act, NULL); //sigaction(SIGINT, &act, NULL);//ctrl +c}int main(){ ignore_sigpipe(); while(1);}
阅读全文
0 0
- spice测试程序01-test-loop.c
- 001test 测试程序
- 001test 测试程序
- 001test 测试程序
- 001test 测试程序
- 001test 测试程序
- SOAPUI读取Excel数据执行循环测试(loop test)
- 循环开销(loop overhead)测试程序
- spice测试工程
- C loop
- dpdk测试用例,test程序
- spice
- C测试小程序
- C指针测试程序
- C---测试程序1
- 测试双层loop
- 【测试】loop率低
- 打算写一款spice电路仿真程序
- 用代码实现以下需求
- Redis 高可用架构最佳实践
- stm32学习笔记(五)独立看门狗
- 我的teamtalk学习历程 -- (1)安装,编译及配置
- 线程和进程简介
- spice测试程序01-test-loop.c
- 打造属于自己的支持版本迭代的Asp.Net Web Api Route
- 推荐系统的几种相似度计算
- HDU 2084 数塔
- 我的第一个完整的小说爬虫
- Spring 与jdbc
- Dubbo入门
- Angular4.0分页组件
- synchronized