1. 程式人生 > >linux上CUnit 2.1.3安裝-使用-示例-安裝不上的解決方法

linux上CUnit 2.1.3安裝-使用-示例-安裝不上的解決方法

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


/*
[email protected]
:~/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


[email protected]
:~/test/CUnit-2.1-3$ mv configure.in configure.ac
[email protected]:~/test/CUnit-2.1-3$ aclocal
[email protected]:~/test/CUnit-2.1-3$ autoheader
[email protected]:~/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')
[email protected]
:~/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


【如出錯,看下面的解決方法】
[email protected]:~/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, ""));
   ^
[email protected]:~/test/learn$ ls
GobiNet  python_ctypes  example  example.c  tags  test  test1.txt  test2.txt


[email protected]:~/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,即可正常】
[email protected]:~/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
[email protected]:~/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