[Libreoffice-commits] buildbot.git: lcov-report/lcov-report.sh lcov-report/README

Maarten Hoes hoes.maarten at gmail.com
Sun Nov 16 11:43:12 PST 2014


 lcov-report/README         |   93 +++++++++-
 lcov-report/lcov-report.sh |  386 +++++++++++++++++++--------------------------
 2 files changed, 249 insertions(+), 230 deletions(-)

New commits:
commit 2082cf5aacd8171b9d9369b2edcf7c40cc5fab31
Author: Maarten Hoes <hoes.maarten at gmail.com>
Date:   Sun Nov 16 14:01:52 2014 +0100

    Allow for separate src and build dirs, updated README.
    
    Change-Id: I334f967bae349abaf1c40907138d005a37344729
    Reviewed-on: https://gerrit.libreoffice.org/12475
    Reviewed-by: Norbert Thiebaud <nthiebaud at gmail.com>
    Tested-by: Norbert Thiebaud <nthiebaud at gmail.com>

diff --git a/lcov-report/README b/lcov-report/README
index 542d718..200ff9e 100644
--- a/lcov-report/README
+++ b/lcov-report/README
@@ -1,12 +1,16 @@
+NAME
+        lcov-report.sh
 
-lcov-report.sh
 
-	A small script to create gcov/lcov code coverage reports of tests run
-	on the libreoffice source code.
+DESCRIPTION
 
+        A small script to create gcov/lcov code coverage reports of tests run
+        on the libreoffice source code.
 
-Usage: lcov-report.sh [-a|-b|-c] -s [DIRECTORY] -t [DIRECTORY] -w [DIRECTORY]
 
+SYNOPSIS
+
+        lcov-report.sh [-a|-b|-c] -s [DIRECTORY] -t [DIRECTORY] -w [DIRECTORY]
 
 -b
         Run lcov commands before you run your tests. This creates a
@@ -15,27 +19,98 @@ Usage: lcov-report.sh [-a|-b|-c] -s [DIRECTORY] -t [DIRECTORY] -w [DIRECTORY]
 
 -a
         Run lcov commands after you run your tests. This creates a
-        tracefile that contains the resukts of your tests, and combines
+        tracefile that contains the results of your tests, and combines
         it with the baseline. You can only supply one of '-a', '-b' or
         '-c' simultaneously.
 
 -c
-        Specifies to build the libreoffice sources in the location
+        Specifies to compile the libreoffice sources in the location
         specified by the '-s' flag. This flag is optional. If you
         choose to omit it, you must make sure the libreoffice source
         code is built using the appropriate FLAGS ('-fprofile-arcs
         -ftest-coverage'). You can only supply one of '-a', '-b' or
         '-c' simultaneously.
 
+-C
+        Specifies the location the sourcecode gets compiled in.
+
 -s
         Specify the location where the libreoffice source code is
-        located. This flag is mandatory.
+        located. This flag is mandatory when you run '-c' or '-a'.
 
 -t
         Specifies the directory in which to contain the lcov
-        tracefile's. This flag is mandatory.
+        tracefile's. This flag is mandatory when you run '-a' or '-b'.
 
 -w
         Specifies the directory in which to contain the generated HTML
-        report files. This flag is mandatory.
+        report files. This flag is mandatory when you run '-b'.
+
+
+EXAMPLE
+
+        Summary.
+
+                In essence, you run the following commands:
+
+                1.) Compile LibreOffice.
+                2.) Run 'lcov-report.sh' before you run your tests.
+                3.) Run your tests.
+                4.) Run 'lcov-report.sh' after your tests.
+
+                That's it.
+
+
+        1.) Compile LibreOffice.
+
+                The first step is to compile the libreoffice code using
+                the appropriate FLAGS and options to autogen.sh and/or
+                ./configure.  You can do this with lcov-report.sh in
+                the following way:
+
+                lcov-report.sh -c -C /home/user/build -s \
+                /home/user/src/libreoffice
+
+                '-c' specifies that you want to compile the code.
+
+                If you choose to build libreoffice yourself instead, make
+                sure to set these FLAGS: LDFLAGS+='-fprofile-arcs'
+                CFLAGS+='-fprofile-arcs -ftest-coverage'
+                CXXFLAGS+='-fprofile-arcs -ftest-coverage'
+                CPPFLAGS+='-fprofile-arcs -ftest-coverage'. Also, you
+                need to supply --disable-online-update to autogen.sh
+                and/or configure.
+
+
+        2.) Run 'lcov-report.sh -b'.
+
+                The next step is to create a gcov/lcov baseline. You
+                run this command ('-b') before you run your tests.
+
+                lcov-report.sh -b -C /home/user/build -t \
+                /home/user/traces
+
+
+        3.) Run tests.
+
+                Now you can run the tests for which you want to report
+                code coverage. This could be as simple as 'make check'
+                in the build directory.
+
+
+        4.) Run 'lcov-report.sh -a'.
+
+                The last step is to create a lcov/gcov tracefile that
+                contains the data about the tests that were run, and
+                to create the html report. You run this command ('-a')
+                after you have completed running your tests.
+
+                lcov-report.sh -a -C /home/user/build \
+                -s /home/user/src/libreoffice -t \
+                /home/user/traces -w /home/user/html
+
+                Make sure that you specify the same directory for the
+                tracefiles ('-t') as you did when running the command
+                '-b' befpre your tests, as lcov needs access to the
+                baseline file that was created in that step.
 
diff --git a/lcov-report/lcov-report.sh b/lcov-report/lcov-report.sh
index c3f6420..4d7046a 100755
--- a/lcov-report/lcov-report.sh
+++ b/lcov-report/lcov-report.sh
@@ -1,4 +1,5 @@
-#!/bin/sh
+#!/usr/bin/env bash
+# -*- tab-width : 4; indent-tabs-mode : nil -*-
 #
 # This file is part of the LibreOffice project.
 #
@@ -7,279 +8,222 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #
 
-
 #
 # Functions
 #
 
+#
+# Display an error message and exit
+#
+die()
+{
+    echo "Error:" "$@" >&2
+    exit -1;
+}
 
 init()
-{ 
-if [ -n "$SOURCE_COMPILE" -a -n "$BEFORE" -o -n "$SOURCE_COMPILE" -a -n "$AFTER" -o -n "$BEFORE" -a -n "$AFTER" ]
-then
-	echo "ERROR: You can only supply one of '-a', '-b' or '-c' simultaneously." >&2
-	exit 1
-fi
-
-if [ -n "$AFTER" -a -z "$HTML_DIR" ]
-then
-	echo "ERROR: When specifying '-a', you also need to specify '-w'." >&2
-	exit 1
-fi
-
-if [ -n "$AFTER" -a -z "$SRC_DIR" ]
-then
-	echo "ERROR: When specifying '-a', you also need to specify '-s'." >&2
-	exit 1
-fi
-
-if [ -n "$BEFORE" -a -z "$SRC_DIR" ]
-then
-	echo "ERROR: When specifying '-b', you also need to specify '-s'." >&2
-	exit 1
-fi
-
-if [ -n "$BEFORE" -o -n "$AFTER" ]
-then
-	if [ -z "$TRACEFILE_DIR" ]
-	then
-		echo "ERROR: When specifying '-a' or '-b', you also need to specify '-t'." >&2
-		exit 1
-	fi
-fi
-
-if [ "$SRC_DIR" = "/" -o "$TRACEFILE_DIR" = "/" -o "$HTML_DIR" = "/" ]
-then
-	echo "ERROR: Dont use the root '/' directory for storage." >&2
-	exit 1
-fi
-
-if [ ! -d "$SRC_DIR" ]
-then
-	echo "ERROR: Failed to locate source code directory $SRC_DIR." >&2
-	exit 1
-fi
-
-if [ ! -d "$SRC_DIR"/.git ]
-then
-	echo "ERROR: $SRC_DIR is not a git repository." >&2
-	exit 1
-fi
-
-if [ -n "$BEFORE" -a ! -d "$TRACEFILE_DIR" ]
-then
-	mkdir "$TRACEFILE_DIR"
-	if [ "$?" != "0" ]
-	then
-		echo "ERROR: Failed to create tracefile directory $TRACEFILE_DIR." >&2
-		exit 1
-	fi
-fi
-
-if [ -n "$BEFORE" -a -d "$TRACEFILE_DIR" ]
-then
-	rm -rf "$TRACEFILE_DIR"
-	mkdir "$TRACEFILE_DIR"
-	if [ "$?" != "0" ]
-	then
-		echo "ERROR: Failed to create tracefile directory $TRACEFILE_DIR." >&2
-		exit 1
-	fi
-	
-fi
-
-if [ -n "$AFTER" -a ! -d "$HTML_DIR" ]
-then
-	mkdir "$HTML_DIR"
-	if [ "$?" != "0" ]
-	then
-		echo "ERROR: Failed to create html directory $HTML_DIR." >&2
-		exit 1
-	fi
-fi
-
-if [ -n "$AFTER" -a -d "$HTML_DIR" ]
-then
-	rm -rf "$HTML_DIR"
-	mkdir "$HTML_DIR"
-	if [ "$?" != "0" ]
-	then
-		echo "ERROR: Failed to create html directory $HTML_DIR." >&2
-		exit 1
-	fi
-fi
+{
+    if [ "${SOURCE_COMPILE?}${AFTER?}${BEFORE?}" != "TRUE" ] ; then
+        die "You can only supply one of '-a', '-b' or '-c' simultaneously."
+    fi
+
+    if [ -n "${SRC_DIR?}" ] ; then
+        if [ ! -d "${SRC_DIR?}" ] ; then
+            die "Failed to locate source code directory $SRC_DIR."
+        fi
+
+        if [ ! -d "${SRC_DIR?}/.git" ] ; then
+            die "${SRC_DIR?} is not a git repository."
+        fi
+
+        if [ "${SRC_DIR?}" = "${BUILD_DIR?}" ] ; then
+            die "Cannot set the source directory to the same value as the build directory."
+        fi
+    fi
+
+    if [ "${AFTER?}" = "TRUE" ] ; then
+        if [ -z "${HTML_DIR?}" ] ; then
+            die  "When specifying '-a', you also need to specify '-w'."
+        fi
+
+        if [ -z "${BUILD_DIR?}" ] ; then
+            die "When specifying '-a', you also need to specify '-C'."
+        fi
+
+        if [ -z "${SRC_DIR?}" ] ; then
+            die "When specifying '-a', you also need to specify '-s'."
+        fi
+        if [ -d "${HTML_DIR?}" ] ; then
+            mkdir "${HTML_DIR?}" || die "Failed to create html directory ${HTML_DIR?}."
+        else
+            rm -rf "${HTML_DIR?}"
+            mkdir "${HTML_DIR?}" || die "Failed to create html directory ${HTML_DIR?}."
+        fi
+    fi
+
+    if [ "${BEFORE?}" = "TRUE" -o "${AFTER?}" = "TRUE" ] ; then
+        if [ -z "${TRACEFILE_DIR?}" ] ; then
+            die "When specifying '-a' or '-b', you also need to specify '-t'."
+        fi
+        if [ ! -d "${TRACEFILE_DIR?}" ] ; then
+            mkdir "${TRACEFILE_DIR?}" || die "Failed to create tracefile directory ${TRACEFILE_DIR?}."
+        else
+            rm -rf "${TRACEFILE_DIR?}"
+            mkdir "${TRACEFILE_DIR?}" || die "Failed to create tracefile directory ${TRACEFILE_DIR?}."
+        fi
+    fi
+
+    if [ "${SOURCE_COMPILE?}" = "TRUE" ] ; then
+        if [ -z "${BUILD_DIR?}" ] ; then
+            die "When specifying '-c', you also need to specify '-C'."
+        fi
+
+        if [ -z "${SRC_DIR?}" ] ; then
+            die "When specifying '-c', you also need to specify '-s'."
+        fi
+        if [ ! -d "$BUILD_DIR" ] ; then
+            mkdir "$BUILD_DIR" || die "Failed to create source compile directory $BUILD_DIR."
+        else
+            rm -rf "$BUILD_DIR"
+            mkdir "$BUILD_DIR" || die "Failed to create source compile directory $BUILD_DIR."
+        fi
+    fi
 }
 
 lcov_cleanup()
 {
-lcov --zerocounters --directory "$SRC_DIR"
+    lcov --zerocounters --directory "${SRC_DIR?}"
 }
 
 source_build()
 {
-cd "$SRC_DIR"
-make distclean
-MY_EXITCODE=$?
-if [ "$MY_EXITCODE" != "0" ]
-then
-	echo "ERROR: make distclean failed with exitcode $MY_EXITCODE." >&2
-	exit "$MY_EXITCODE"
-fi
-
-./autogen.sh
+    cd "${BUILD_DIR?}"
 
-LDFLAGS+='-fprofile-arcs' CFLAGS+='-fprofile-arcs -ftest-coverage' CXXFLAGS+='-fprofile-arcs -ftest-coverage' CPPFLAGS+='-fprofile-arcs -ftest-coverage' ./configure --disable-online-update --without-system-libs --without-system-headers
-MY_EXITCODE=$?
-if [ "$MY_EXITCODE" != "0" ]
-then
-	echo "ERROR: configure failed with exitcode $MY_EXITCODE." >&2
-	exit "$MY_EXITCODE"
-fi
+    LDFLAGS+='-fprofile-arcs' CFLAGS+='-fprofile-arcs -ftest-coverage' CXXFLAGS+='-fprofile-arcs -ftest-coverage' CPPFLAGS+='-fprofile-arcs -ftest-coverage' \
+    "${SRC_DIR?}/autogen.sh" --disable-online-update --without-system-libs --without-system-headers \
+    || die "autogen.sh failed."
 
-make build-nocheck
-MY_EXITCODE=$?
-if [ "$MY_EXITCODE" != "0" ]
-then
-	echo "ERROR: make build-nocheck failed with exitcode $MY_EXITCODE." >&2
-	exit "$MY_EXITCODE"
-fi
+    make build-nocheck || die "make build-nocheck failed."
 }
 
 lcov_tracefile_baseline()
 {
-lcov --rc geninfo_auto_base=1 --no-external --capture --initial --directory "$SRC_DIR" --output-file "$TRACEFILE_DIR"/lcov_base.info
-MY_EXITCODE=$?
-if [ "$MY_EXITCODE" != "0" ]
-then
-	echo "ERROR: tracefile $TRACEFILE_DIR/lcov_base.info generation failed with exitcode $MY_EXITCODE." >&2
-	exit "$MY_EXITCODE"
-fi
+    lcov --rc geninfo_auto_base=1 --capture --initial --directory "${BUILD_DIR?}" --output-file "${TRACEFILE_DIR?}/lcov_base.info" \
+    || die "Tracefile ${TRACEFILE_DIR?}/lcov_base.info generation failed."
 }
 
 lcov_tracefile_tests()
 {
-lcov --rc geninfo_auto_base=1 --no-external --capture --directory "$SRC_DIR" --output-file "$TRACEFILE_DIR"/lcov_test.info
-MY_EXITCODE=$?
-if [ "$MY_EXITCODE" != "0" ]
-then
-	echo "ERROR: tracefile $TRACEFILE_DIR/lcov_test.info generation failed with exitcode $MY_EXITCODE." >&2
-	exit "$MY_EXITCODE"
-fi
+    lcov --rc geninfo_auto_base=1 --capture --directory "${BUILD_DIR?}" --output-file "${TRACEFILE_DIR?}/lcov_test.info" \
+    || die "Tracefile ${TRACEFILE_DIR?}/lcov_test.info generation failed."
 }
 
 lcov_tracefile_join()
 {
-lcov --rc geninfo_auto_base=1 --add-tracefile "$TRACEFILE_DIR"/lcov_base.info --add-tracefile "$TRACEFILE_DIR"/lcov_test.info --output-file "$TRACEFILE_DIR"/lcov_total.info
-MY_EXITCODE=$?
-if [ "$MY_EXITCODE" != "0" ]
-then
-	echo "ERROR: tracefile generation $TRACEFILE_DIR/lcov_total.info failed with exitcode $MY_EXITCODE." >&2
-	exit "$MY_EXITCODE"
-fi
+    lcov --rc geninfo_auto_base=1 --add-tracefile "${TRACEFILE_DIR?}/lcov_base.info" \
+    --add-tracefile "${TRACEFILE_DIR?}/lcov_test.info" --output-file "${TRACEFILE_DIR?}/lcov_total.info" \
+    || die "Tracefile generation $TRACEFILE_DIR/lcov_total.info failed."
 }
 
 lcov_tracefile_cleanup()
 {
-lcov --rc geninfo_auto_base=1 --remove "$TRACEFILE_DIR"/lcov_total.info  "/usr/include/*" "/usr/lib/*" "$SRC_DIR/*/UnpackedTarball/*" "$SRC_DIR/workdir/*" "$SRC_DIR/instdir/*" "$SRC_DIR/external/*" -o "$TRACEFILE_DIR"/lcov_filtered.info
-MY_EXITCODE=$?
-if [ "$MY_EXITCODE" != "0" ]
-then
-	echo "ERROR: tracefile generation $TRACEFILE_DIR/lcov_filtered.info failed with exitcode $MY_EXITCODE." >&2
-	exit "$MY_EXITCODE"
-fi
+    lcov --rc geninfo_auto_base=1 --remove "${TRACEFILE_DIR?}/lcov_total.info" \
+    "/usr/include/*" "/usr/lib/*" "${SRC_DIR?}/*/UnpackedTarball/*" "${SRC_DIR?}/workdir/*" \
+    "${BUILD_DIR?}/workdir/*" "${SRC_DIR?}/instdir/*" "${SRC_DIR?}/external/*" \
+    -o "${TRACEFILE_DIR?}lcov_filtered.info" \
+    || die "tracefile generation ${TRACEFILE_DIR?}/lcov_filtered.info failed."
 }
 
 lcov_mkhtml()
 {
-cd "$SRC_DIR"
-
-COMMIT_SHA1=$(git log --date=iso | head -3 | awk '/^commit/ {print $2}')
-COMMIT_DATE=$(git log --date=iso | head -3 | awk '/^Date/ {print $2}')
-COMMIT_TIME=$(git log --date=iso | head -3 | awk '/^Date/ {print $3}')
-
-mkdir "$HTML_DIR"/master~"$COMMIT_DATE"_"$COMMIT_TIME"
-MY_EXITCODE=$?
-if [ ! -d "$HTML_DIR"/master~"$COMMIT_DATE"_"$COMMIT_TIME" ]
-then
-	echo >&2 ERROR: failed to create subdirectory in $HTML_DIR/master~"$COMMIT_DATE"_"$COMMIT_TIME" with exitcode $MY_EXITCODE
-	exit "$MY_EXITCODE"
-fi
+    cd "$SRC_DIR"
 
-genhtml --rc geninfo_auto_base=1 --prefix "$SRC_DIR" --ignore-errors source "$TRACEFILE_DIR"/lcov_filtered.info --legend --title "commit $COMMIT_SHA1" --output-directory="$HTML_DIR"/master~"$COMMIT_DATE"_"$COMMIT_TIME"
-MY_EXITCODE=$?
-if [ "$MY_EXITCODE" != "0" ]
-then
-	echo >&2 ERROR: Generation of html files in $HTML_DIR/master~"$COMMIT_DATE"_"$COMMIT_TIME" failed with exitcode $MY_EXITCODE.
-	exit "$MY_EXITCODE"
-fi
+    COMMIT_SHA1=$(git log --date=iso | head -3 | awk '/^commit/ {print $2}')
+    COMMIT_DATE=$(git log --date=iso | head -3 | awk '/^Date/ {print $2}')
+    COMMIT_TIME=$(git log --date=iso | head -3 | awk '/^Date/ {print $3}')
+
+    mkdir "${HTML_DIR?}/master~${COMMIT_DATE?}_${COMMIT_TIME?}" || die "Failed to create subdirectory in ${HTML_DIR?}/master~${COMMIT_DATE?}_${COMMIT_TIME?}"
+
+    genhtml --rc geninfo_auto_base=1 --prefix "${SRC_DIR?}" --ignore-errors source "${TRACEFILE_DIR?}/lcov_filtered.info" \
+    --legend --title "commit ${COMMIT_SHA1?}" \
+    --output-directory="${HTML_DIR?}/master~${COMMIT_DATE?}_${COMMIT_TIME?}" \
+    || die "ERROR: Generation of html files in ${HTML_DIR?}/master~${COMMIT_DATE?}_${COMMIT_TIME?} failed."
 }
 
 usage()
 {
-	echo >&2 "Usage: lcov-report.sh [-a|-b|-c] -s [DIRECTORY] -t [DIRECTORY] -w [DIRECTORY]
-	-b	run lcov commands before your tests
-	-a	run lcov commands after your tests
-	-c	compile libreoffice sources
-	-s	source code directory
-	-t 	tracefile directory
-	-w 	html (www) directory"
-	exit 1
+    echo >&2 "Usage: lcov-report.sh [-a|-b|-c] -s [DIRECTORY] -C [DIRECTORY] -t [DIRECTORY] -w [DIRECTORY]
+        -b    run lcov commands before your tests
+        -a    run lcov commands after your tests
+        -c    compile libreoffice sources
+        -C    build directory to compile libreoffice sources in
+        -s    source code directory
+        -t    tracefile directory
+        -w    html (www) directory"
+    exit 1
 }
 
 #
 # Main
 #
 
-if [ "$#" = "0" ]
-then
-	usage
-fi
-
-while getopts ":s:t:w:abc" opt
-do
-	case $opt in
-		s)
-			export SRC_DIR="$OPTARG"
-			;;
-		t)
-			export TRACEFILE_DIR="$OPTARG"
-			;;
-		w)
-			export HTML_DIR="$OPTARG"
-			;;
-		c)
-			export SOURCE_COMPILE=TRUE
-			;;
-		b)
-			export BEFORE=TRUE
-			;;
-		a)
-			export AFTER=TRUE
-			;;
-		*)
-			usage
-			;;
-	esac
+SOURCE_COMPILE=
+BEFORE=
+AFTER=
+SRC_DIR=
+TRACEFILE_DIR=
+HTML_DIR=
+BUIILD_DIR=
+
+if [ "$#" = "0" ] ; then
+    usage
+fi
+
+while getopts ":s:t:w:C:abc" opt ; do
+    case "$opt" in
+    s)
+        SRC_DIR="$OPTARG"
+        ;;
+    t)
+        TRACEFILE_DIR="$OPTARG"
+        ;;
+    w)
+        HTML_DIR="$OPTARG"
+        ;;
+    c)
+        SOURCE_COMPILE=TRUE
+        ;;
+    C)
+        BUILD_DIR="$OPTARG"
+        ;;
+    b)
+        BEFORE=TRUE
+        ;;
+    a)
+        AFTER=TRUE
+        ;;
+    *)
+        usage
+        ;;
+    esac
 done
 
+echo "foo"
+
 init
 
-if [ "$BEFORE" = "TRUE" ]
-then
-	lcov_cleanup
-	lcov_tracefile_baseline
+if [ "${BEFORE?}" = "TRUE" ] ; then
+    lcov_cleanup
+    lcov_tracefile_baseline
 fi
 
-if [ "$SOURCE_COMPILE" = "TRUE" ]
-then
-	source_build
+if [ "${SOURCE_COMPILE?}" = "TRUE" ] ; then
+    source_build
 fi
 
-if [ "$AFTER" = "TRUE" ]
-then
-	lcov_tracefile_tests
-	lcov_tracefile_join
-	lcov_tracefile_cleanup
-
-	lcov_mkhtml
+if [ "${AFTER?}" = "TRUE" ] ; then
+    lcov_tracefile_tests
+    lcov_tracefile_join
+    lcov_tracefile_cleanup
+    lcov_mkhtml
 fi


More information about the Libreoffice-commits mailing list