neo's profile十年一场梦 ..BlogListsGuestbookMore ![]() | Help |
|
|
11/18/2009 利用perl做c的单元测试Xs方式
1)mkdir Mytest /mylib;
mylib中放着 xx.c xx.h C代码
2)在mylib中vi Makefile.PL
AR将mylib目录下的test1.o test2.o 编译为静态库libmylib.a ,通过RANLIB更新静态库libmylib.a
3)在mylib目录的上级目录中执行
h2xs –A –O –n Mytest ./Mytest/mylib/test.h 生成扩展接口文件
4)在Mytest目录下修改Makefile.PL
Postamble中可有有写错的地方,会多执行一次 make 不影响
5)修改MANIFEST
mylib/Makefile.PL
mylib/xxx.c
mylib/xxx.h
6)修改Mytest.xs
留意 c函数接口
7)在Mytest下 perl Makefile.PL
在mylib下 make
在Mytest下 make
make install
8)写在测试脚本
#!/usr/bin/perl
use Mytest;
use Test::More test=>1;
my $sum=&Mytest::add(1,2);
is($sum,3,’…’);
搞定!~~方法是死的 东西是活的~~
TrackbacksThe trackback URL for this entry is: http://sh-neo.spaces.live.com/blog/cns!1E3CA285E5F9E122!764.trak Weblogs that reference this entry
|
|
|