From 7243d8e7b8af8c1ab40f4bcca1e70f4d349f51df Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 2 Feb 2019 21:42:03 +0800 Subject: [PATCH] CI: Support codecov --- .circleci/config.yml | 2 +- trunk/auto/coverage.sh | 27 +++++++++++++++++++ trunk/auto/options.sh | 17 +++++++----- trunk/configure | 8 ++++++ .../srs_xcode.xcodeproj/project.pbxproj | 2 ++ 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 trunk/auto/coverage.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index e06bed4b4..8115af858 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,7 +11,7 @@ jobs: - image: ossrs/dev steps: - checkout - - run: cd trunk && ./configure && make && ./objs/srs_utest + - run: cd trunk && ./configure --gcov --without-research --without-librtmp && make && bash auto/coverage.sh workflows: version: 2 build_and_test: diff --git a/trunk/auto/coverage.sh b/trunk/auto/coverage.sh new file mode 100644 index 000000000..21a399117 --- /dev/null +++ b/trunk/auto/coverage.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# In .circleci/config.yml, generate *.gcno with +# ./configure --gcov --without-research --without-librtmp + +# Generate *.gcda +./objs/srs_utest +ret=$?; if [[ $ret -ne 0 ]]; then echo "Run SRS utest failed, ret=$ret"; exit $ret; fi + +# Collect all *.gcno and *.gcda to objs/cover. +(mkdir -p objs/cover && cd objs/cover && +cp -R ../../src . && +for file in `find ../src -name "*.gcno"`; do cp $file .; done && +for file in `find ../src -name "*.gcda"`; do cp $file .; done) +ret=$?; if [[ $ret -ne 0 ]]; then echo "Collect *.gcno and *.gcda failed, ret=$ret"; exit $ret; fi + +# Generate *.gcov to objs/cover +for file in `find src -name "*.cpp"`; do + (mkdir -p objs/cover && cd objs/cover && gcov ../../$file -o .) + ret=$?; if [[ $ret -ne 0 ]]; then echo "Collect $file failed, ret=$ret"; exit $ret; fi +done + +# Upload report with *.gcov +export CODECOV_TOKEN="493bba46-c468-4e73-8b45-8cdd8ff62d96" && +mkdir -p objs/cover && cd objs/cover && +bash <(curl -s https://codecov.io/bash) +exit 0 diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index dd8959095..6787d89cf 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -43,16 +43,18 @@ SRS_DVR=YES # ################################################################ # libraries -SRS_FFMPEG_STUB=RESERVED +SRS_FFMPEG_STUB=NO # arguments SRS_PREFIX=/usr/local/srs SRS_JOBS=1 -SRS_STATIC=RESERVED +SRS_STATIC=NO +# whether enable the gcov +SRS_GCOV=NO # whether enable the log verbose/info/trace level. # always enable the warn/error level. -SRS_LOG_VERBOSE=RESERVED -SRS_LOG_INFO=RESERVED -SRS_LOG_TRACE=RESERVED +SRS_LOG_VERBOSE=NO +SRS_LOG_INFO=NO +SRS_LOG_TRACE=NO # ################################################################ # experts @@ -154,7 +156,8 @@ Options: --without-mips-ubuntu12 do not cross build srs on ubuntu12 for mips. --prefix= The absolute installation path for srs. Default: $SRS_PREFIX - --static whether add '-static' to link options. + --static Whether add '-static' to link options. + --gcov Whether enable the GCOV compiler options. --jobs[=N] Allow N jobs at once; infinite jobs with no arg. used for make in the configure, for example, to make ffmpeg. --log-verbose whether enable the log verbose level. default: no. @@ -267,6 +270,7 @@ function parse_user_option() { --log-verbose) SRS_LOG_VERBOSE=YES ;; --log-info) SRS_LOG_INFO=YES ;; --log-trace) SRS_LOG_TRACE=YES ;; + --gcov) SRS_GCOV=YES ;; --x86-x64) SRS_X86_X64=YES ;; --x86-64) SRS_X86_X64=YES ;; @@ -640,6 +644,7 @@ SRS_AUTO_CONFIGURE="--prefix=${SRS_PREFIX}" if [ $SRS_LOG_VERBOSE = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-verbose"; fi if [ $SRS_LOG_INFO = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-info"; fi if [ $SRS_LOG_TRACE = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-trace"; fi + if [ $SRS_GCOV = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gcov"; fi echo "User config: $SRS_AUTO_USER_CONFIGURE" echo "Detail config: ${SRS_AUTO_CONFIGURE}" } diff --git a/trunk/configure b/trunk/configure index 1f0c96d72..f3267cc91 100755 --- a/trunk/configure +++ b/trunk/configure @@ -104,6 +104,10 @@ CXXFLAGS="${CXXFLAGS} ${CppStd}${WarnLevel}${GDBDebug}${LibraryCompile}${SrsGpro if [ $SRS_GPERF = YES ]; then CXXFLAGS="${CXXFLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free"; fi +# For coverage. +if [[ $SRS_GCOV == YES ]]; then + CXXFLAGS="${CXXFLAGS} -fprofile-arcs -ftest-coverage"; +fi # Start to generate the Makefile. cat << END > ${SRS_OBJS}/${SRS_MAKEFILE} GCC = gcc @@ -153,6 +157,10 @@ fi if [ $SRS_MIPS_UBUNTU12 = YES ]; then SrsLinkOptions="${SrsLinkOptions} -lgcc_eh"; fi +# For coverage. +if [[ $SRS_GCOV == YES ]]; then + SrsLinkOptions="${SrsLinkOptions} -fprofile-arcs -ftest-coverage"; +fi ##################################################################################### # Modules, compile each module, then link to binary diff --git a/trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj b/trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj index df8a6a5ff..cdc8708bf 100644 --- a/trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj +++ b/trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj @@ -303,6 +303,7 @@ 3C1232F21AAEAC7000CE8F6C /* srs-api */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "srs-api"; path = "../../../etc/init.d/srs-api"; sourceTree = ""; }; 3C1232F31AAEAC7000CE8F6C /* srs-demo */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "srs-demo"; path = "../../../etc/init.d/srs-demo"; sourceTree = ""; }; 3C1232F41AAEAC7000CE8F6C /* srs-demo-19350 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "srs-demo-19350"; path = "../../../etc/init.d/srs-demo-19350"; sourceTree = ""; }; + 3C1CDBFB2205CE0300A8C08E /* coverage.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = coverage.sh; path = ../../../auto/coverage.sh; sourceTree = ""; }; 3C1EE6AC1AB1055800576EE9 /* srs_app_hds.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_hds.cpp; path = ../../../src/app/srs_app_hds.cpp; sourceTree = ""; }; 3C1EE6AD1AB1055800576EE9 /* srs_app_hds.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_hds.hpp; path = ../../../src/app/srs_app_hds.hpp; sourceTree = ""; }; 3C1EE6B01AB1080900576EE9 /* bandwidth.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = bandwidth.conf; path = ../../../conf/bandwidth.conf; sourceTree = ""; }; @@ -731,6 +732,7 @@ 3C1232BB1AAE827E00CE8F6C /* apps.sh */, 3C1232BC1AAE827E00CE8F6C /* auto_headers.sh */, 3C1232BD1AAE827E00CE8F6C /* build_ffmpeg.sh */, + 3C1CDBFB2205CE0300A8C08E /* coverage.sh */, 3C1232BE1AAE827E00CE8F6C /* depends.sh */, 3C1232BF1AAE827E00CE8F6C /* generate_header.sh */, 3C1232C01AAE827E00CE8F6C /* generate-srs-librtmp-project.sh */,