DirectFB压力测试工具
DirectFB压力测试工具
转载时请注明出处和作者联系方式
作者联系方式:李先静 <xianjimli at hotmail dot com>
GUI应用程序自动测试一直是个难题,通常的做法就是先把人工测试过程录制下来,然后去重放这个测试过程。这种方法的主要缺点是很难自动检测运行结果的正确性,所以很多人都不屑去使用它。其实工具总是有它的局限性,它能不能发挥它应有的作用,还依赖于人的灵活运用。即不能过分依赖于工具,也不能盲目排斥工具。
在质量保证的过程中,人无疑是最重要的,没有什么比一次性写出高质量代码就有效的了。但事实是即使有良好的架构设计,辅之于单元测试和代码评审等一些有效实践,仍然有些BUG成为漏网之鱼,更何况很多团队这些工作做得并到位。单一工具和方法很难包医百病,但各种方法和工具综合起来使用的效果就大不一样了。
前段时间一位同事开发了一个GUI自动测试工具,我们把它用于BUG重现和压力测试中,取得了不错的效果。这里介绍一下DirectFB里面事件录制和重放的方法:
获得键盘设备:
dfb_input_enumerate_devices ((InputDeviceCallback)device_callback,
&context->keyboard_device, DICAPS_KEYS);
获得鼠标或触摸屏设备:
dfb_input_enumerate_devices ((InputDeviceCallback)device_callback,
&context->mouse_device, DICAPS_AXES | DICAPS_BUTTONS);
向设备注册事件监听函数:
dfb_input_attach (context->mouse_device,
input_device_listener, context, &context->mouse_reaction);
dfb_input_attach (context->keyboard_device,
input_device_listener, context, &context->keyboard_reaction);
事件监听函数:
static ReactionResult input_device_listener (const void *msg_data, void *ctx)
{
DFBContext *context = (DFBContext*)ctx;
DFBInputEvent *event = (DFBInputEvent*)msg_data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
event->locks = 0;
event->flags &= ~DIEF_LOCKS;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (fwrite (msg_data, sizeof (DFBInputEvent), 1, context->file) != 1)
{
printf ("[%s]: fwrite Error errno = %d ", __func__, errno);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g_main_loop_quit (context->loop);
}
fflush(context->file);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return RS_OK;
}
事件重放函数:
static gboolean replay_one_event (gpointer user_data)
{
DFBContext *context = (DFBContext*)user_data;
off_t cur = 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DFBInputEvent event = context->event;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(event.type == DIET_KEYPRESS || event.type == DIET_KEYRELEASE)
{
dfb_input_dispatch (context->keyboard_device, &event);
}
else
{
dfb_input_dispatch (context->mouse_device, &event);
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (fread (&context->event, sizeof (DFBInputEvent), 1, context->file) == 1)
{
guint ms = (context->event.timestamp.tv_sec - event.timestamp.tv_sec) * 1000
+ (context->event.timestamp.tv_usec - event.timestamp.tv_usec)/1000;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g_timeout_add (ms, replay_one_event, user_data);
}
else
{
g_main_loop_quit (context->loop);
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return FALSE;
}
注意:DirectFB中的笔点事件是以相对坐标方式表示的,所以要保证重放时光标在同样的初始位置。如果DirectFB以多进程的方式运行,这个程序可以是一个独立的进程,否则要放到应用程序的进程中才行。
~~end~~
转载时请注明出处和作者联系方式
作者联系方式:李先静 <xianjimli at hotmail dot com>
GUI应用程序自动测试一直是个难题,通常的做法就是先把人工测试过程录制下来,然后去重放这个测试过程。这种方法的主要缺点是很难自动检测运行结果的正确性,所以很多人都不屑去使用它。其实工具总是有它的局限性,它能不能发挥它应有的作用,还依赖于人的灵活运用。即不能过分依赖于工具,也不能盲目排斥工具。
在质量保证的过程中,人无疑是最重要的,没有什么比一次性写出高质量代码就有效的了。但事实是即使有良好的架构设计,辅之于单元测试和代码评审等一些有效实践,仍然有些BUG成为漏网之鱼,更何况很多团队这些工作做得并到位。单一工具和方法很难包医百病,但各种方法和工具综合起来使用的效果就大不一样了。
前段时间一位同事开发了一个GUI自动测试工具,我们把它用于BUG重现和压力测试中,取得了不错的效果。这里介绍一下DirectFB里面事件录制和重放的方法:
获得键盘设备:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
获得鼠标或触摸屏设备:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
向设备注册事件监听函数:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
事件监听函数:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
事件重放函数:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
注意:DirectFB中的笔点事件是以相对坐标方式表示的,所以要保证重放时光标在同样的初始位置。如果DirectFB以多进程的方式运行,这个程序可以是一个独立的进程,否则要放到应用程序的进程中才行。
~~end~~