neo's profile十年一场梦 ..BlogListsGuestbookMore Tools Help

Blog


    11/18/2009

    利用perl做c的单元测试

    Xs方式
     
    1)mkdir Mytest /mylib;
                     mylib中放着 xx.c xx.h  C代码
    2)mylibvi Makefile.PL
     
     
    ARmylib目录下的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,’…’);
     
    搞定!~~方法是死的 东西是活的~~
     

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://sh-neo.spaces.live.com/blog/cns!1E3CA285E5F9E122!764.trak
    Weblogs that reference this entry
    • None