单元测试
wine中有许多单元测试模块,验证是否符合Windows API行为。
运行单元测试
cd dlls/advapi32/tests
make test
make services.ok
编写单元测试
Wine中的单元测试,也叫一致性测试,是为了保证API效果和Windows API效果一致。
单元测试框架基于CTEST测试框架(是CMake的一部分)。
新建一个.c文件,编写测试内容,并将文件添加到Makefile.in的C_SRCS
环境变量中。
然后就可以使用ok
进行单元测试了。
#include <wine/test.h>
#include <winbase.h>
//测试框架,paths 是在使用 START_TEST 宏时需要定义的一个参数,用于指定测试函数的名称。
START_TEST(paths)
{
ATOM atom = GlobalAddAtomA( "foobar" );
ok( GlobalFindAtomA( "foobar" ) == atom, "could not find atom foobar\n" );
ok( GlobalFindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR\n" );
}
回归测试
Sometimes old programs don’t compile on new systems. Sometimes old programs compile but don’t work on new systems. But what if you know that the old version of the program worked better than new one for a particular task? This is called a regression. The fastest way to find the cause of the regression is to do regression testing. But the usual regression testing procedure will fail to work in some cases: you cannot compile (or run) and test older versions!
有时候新版本会引发旧错误,如果知道在哪个旧版本上已经修复了这个错误,那么可以回溯到历史版本进行回归测试,定位到发生错误的commit-id。
# 设定搜索范围
git bisect start <终点commit-id> <起点commit-id>
# 设定有效
git bisect good
# 设定无效
git bisect bad
# 退出bisect
git bisect reset
git checkout master
详情参考:Reverse_Regression_Testing