[Unittest] Enable unittest coverage anaysis
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 4 Jun 2018 05:09:50 +0000 (14:09 +0900)
committer함명주/동작제어Lab(SR)/Principal Engineer/삼성전자 <myungjoo.ham@samsung.com>
Tue, 5 Jun 2018 08:01:41 +0000 (17:01 +0900)
Use TAOS-CI to generate unittest coverage analysis html pages.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
packaging/nnstreamer.spec

index 0920818..63a6fcf 100644 (file)
@@ -1,3 +1,5 @@
+# Execute gbs with --define "testcoverage 1" in case that you must get unittest coverage statictics
+
 Name:          nnstreamer
 Summary:       gstremaer plugins for neural networks
 Version:       0.0.1
@@ -24,6 +26,15 @@ BuildRequires:       gst-plugins-base
 # and gtest
 BuildRequires: gtest-devel
 
+%if 0%{?testcoverage}
+BuildRequires: taos-ci-unittest-coverage-assessment
+%endif
+
+%package unittest-coverage
+Summary:       NNStreamer UnitTest Coverage Analysis Result
+%description unittest-coverage
+HTML pages of lcov results of NNStreamer generated during rpmbuild
+
 %description
 NNStreamer is a set of gstreamer plugins to support general neural networks
 and their plugins in a gstreamer stream.
@@ -33,6 +44,10 @@ and their plugins in a gstreamer stream.
 cp %{SOURCE1001} .
 
 %build
+%if 0%{?testcoverage}
+CXXFLAGS="${CXXFLAGS} -fprofile-arcs -ftest-coverage"
+CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
+%endif
 
 mkdir -p build
 pushd build
@@ -53,11 +68,35 @@ tar -xf %{SOURCE2001}
 ./runTest.sh -skipgen
 popd
 
+%if 0%{?testcoverage}
+    unittestcoverage.py module $(pwd)
+
+# Get commit info
+    VCS=`cat ${RPM_SOURCE_DIR}/audri.spec | grep "^VCS:" | sed "s|VCS:\\W*\\(.*\\)|\\1|"`                                              
+                                                                                                                                       
+# Create human readable unit test coverate report web page                                                                             
+    # Create null gcda files if gcov didn't create it because there is completely no unit test for them.                               
+    find . -name "*.gcno" -exec sh -c 'touch -a "${1%.gcno}.gcda"' _ {} \;                                                             
+    # Remove gcda for meaningless file (CMake's autogenerated)                                                                         
+    find . -name "CMakeCCompilerId*.gcda" -delete                                                                                      
+    find . -name "CMakeCXXCompilerId*.gcda" -delete                                                                                    
+    #find . -path "/build/*.j                                                                                                          
+    # Generate report
+    lcov -t 'NNStreamer Unit Test Coverage' -o unittest.info -c -d . -b $(pwd) --no-external                                                
+    # Visualize the report                                                                                                             
+    genhtml -o result unittest.info -t "AuDri %{version}-%{release} ${VCS}" --ignore-errors source -p ${RPM_BUILD_DIR}   
+%endif
+
 %install
 pushd build
 %make_install
 popd
 
+%if 0%{?testcoverage}
+mkdir -p %{buildroot}%{_datadir}/nnstreamer/unittest/
+cp -r result %{buildroot}%{_datadir}/nnstreamer/unittest/
+%endif
+
 %files
 %manifest nnstreamer.manifest
 %defattr(-,root,root,-)
@@ -65,6 +104,11 @@ popd
 %license LICENSE.LGPLv2.1
 %{_libdir}/*
 
+%if 0%{?testcoverage}
+%files unittest-coverage
+%{_datadir}/nnstreamer/unittest/*
+%endif
+
 %changelog
 * Fri May 25 2018 MyungJoo Ham <myungjoo.ham@samsung.com>
 - Packaged tensor_convert plugin.