Ubuntu 16.04 安装CUnit
一、CUnit-2.1-3,下载地址
https://sourceforge.net/projects/cunit/
二、解压
#tar jxvf CUnit-2.1-3.tar.bz2
三、安装
进入CUnit-2.1-3目录,执行以下命令:
autoscan
mv configure.in configure.ac
aclocal
autoheader
libtoolize --automake --copy --debug --force 【由于automake会出错,故先执行该条,至于什么错看下面】
automake
autoconf
./configure 【./configure --prefix <Your choice of directory for installation> example: ./configure --prefix /usr/unittest】
make
sudo make install
【automake出错记录】
当执行到automake的时候,会提示出错:
error:required file ‘./compile’ not found
error :required file ‘./install-sh’ not found
error :required file ‘./missing’ not found
error :required file ‘./depcomp’ not found
根据出错的提示,执行
automake --add-missing
又提示出错了
error :required file ‘./ltmain.sh’ not found
解决方法如下
libtoolize --automake --copy --debug --force
/*
zhuchengxiaoliu@mn-ThinkServer:~/test/CUnit-2.1-3$ autoscan
configure.in: warning: missing AC_CHECK_FUNCS([memset]) wanted by: CUnit/Sources/Framework/Util.c:271
configure.in: warning: missing AC_CHECK_FUNCS([strerror]) wanted by: CUnit/Sources/Framework/MyMem.c:339
configure.in: warning: missing AC_CHECK_HEADERS([limits.h]) wanted by: CUnit/Sources/Automated/Automated.c:56
configure.in: warning: missing AC_CHECK_HEADER_STDBOOL wanted by: CUnit/Sources/Curses/Curses.c:173
configure.in: warning: missing AC_FUNC_MALLOC wanted by: CUnit/Sources/Framework/TestRun.c:1066
configure.in: warning: missing AC_FUNC_REALLOC wanted by: CUnit/Sources/Framework/MyMem.c:312
configure.in: warning: missing AC_PROG_CXX wanted by: CUnit/Sources/wxWidget/wxWidget.cpp
configure.in: warning: missing AC_TYPE_SIZE_T wanted by: CUnit/Headers/CUnit.h.in:276
zhuchengxiaoliu@mn-ThinkServer:~/test/CUnit-2.1-3$ mv configure.in configure.ac
zhuchengxiaoliu@mn-ThinkServer:~/test/CUnit-2.1-3$ aclocal
zhuchengxiaoliu@mn-ThinkServer:~/test/CUnit-2.1-3$ autoheader
zhuchengxiaoliu@mn-ThinkServer:~/test/CUnit-2.1-3$ automake
configure.ac:4: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.ac:4: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:158: error: required file './compile' not found
configure.ac:158: 'automake --add-missing' can install 'compile'
configure.ac:4: error: required file './install-sh' not found
configure.ac:4: 'automake --add-missing' can install 'install-sh'
configure.ac:161: error: required file './ltmain.sh' not found
configure.ac:4: error: required file './missing' not found
configure.ac:4: 'automake --add-missing' can install 'missing'
CUnit/Sources/Automated/Makefile.am: error: required file './depcomp' not found
CUnit/Sources/Automated/Makefile.am: 'automake --add-missing' can install 'depcomp'
CUnit/Sources/Framework/Makefile.am:20: warning: '%'-style pattern rules are a GNU make extension
CUnit/Sources/Test/Makefile.am:12: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
Examples/AutomatedTest/Makefile.am:13: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
Examples/BasicTest/Makefile.am:13: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
Examples/ConsoleTest/Makefile.am:13: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
Examples/CursesTest/Makefile.am:13: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
zhuchengxiaoliu@mn-ThinkServer:~/test/CUnit-2.1-3$
四、拷贝CUnit官网上的样例代码
http://cunit.sourceforge.net/example.html
代码位置:cunit_example_shmpool\example\example.c
编译和运行
gcc -o example example.c -lcunit
./example
【如出错,看下面的解决方法】
zhuchengxiaoliu@mn-ThinkServer:~/test/learn$ gcc -o example example.c -lcunit
example.c: In function ‘testFPRINTF’:
example.c:73:3: warning: zero-length gnu_printf format string [-Wformat-zero-length]
CU_ASSERT(0 == fprintf(temp_file, ""));
^
zhuchengxiaoliu@mn-ThinkServer:~/test/learn$ ls
GobiNet python_ctypes example example.c tags test test1.txt test2.txt
zhuchengxiaoliu@mn-ThinkServer:~/test/learn$ ./example
./example: error while loading shared libraries: libcunit.so.1: cannot open shared object file: No such file or directory
【上面出错了.】
默认安装位置的,共享库文件安装到了/usr/local/lib(很多开源的共享库都会安装到该目录下)或其它"非/lib或/usr/lib"目录下,
那么在执行ldconfig命令前, 还要把新共享库目录加入到共享库配置文件/etc/ld.so.conf中, 如下:
# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# sudo echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig
【再执行./example,即可正常】
zhuchengxiaoliu@mn-ThinkServer:~/learn/cunit/atest_Shmpool/example$ ./example
CUnit - A unit testing framework for C - Version 2.1-3
http://cunit.sourceforge.net/
Suite: Suite_1
Test: test of fprintf() ...passed
Test: test of fread() ...passed
Run Summary: Type Total Ran Passed Failed Inactive
suites 1 1 n/a 0 0
tests 2 2 2 0 0
asserts 5 5 5 0 n/a
Elapsed time = 0.000 seconds
zhuchengxiaoliu@mn-ThinkServer:~/learn/cunit/atest_Shmpool/example$
五、xml格式报表打开
直接生成XML格式的报表,先make,然后运行后,在当前目录下生成两个报表
TestMax-Listing.xml和TestMax-Results.xml(前者是测试用例的列表,后者是测试用例的测试结果) ,但这两个文件是不能直接观看的,要查看这两个文件,
需要使用如下xsl和dtd文件:CUnit-List.dtd和CUnit-List.xsl用于解析列表文件, CUnit-Run.dtd和CUnit-Run.xsl用于解析结果文件。
这四个文件在CUnit包里面有提供,安装之后在$(PREFIX) /share/CUnit目录下,默认安装的话在/home/lirui/local/share/CUnit目录下。
在查看结果之前,需要把这六 个文件:TestMax-Listing.xml, TestMax-Results.xml, CUnit-List.dtd, CUnit-List.xsl, CUnit-Run.dtd, CUnit-Run.xsl拷贝到一个目录下,
然后用浏览器打开两个结果的xml文件就可以了。
六、看cunit_example_shmpool文件夹下的readme.txt
linux共享内容的实例,下载地址:http://download.csdn.net/detail/cupedy/9894226