lcov-report/README                   |   33 ++++++
 lcov-report/lcov-report.cmds.example |    8 +
 lcov-report/lcov-report.sh           |  178 +++++++++++++++++++++++++----------
 3 files changed, 172 insertions(+), 47 deletions(-)

New commits:
commit dc7ef6b14866d787fe5fad9969de93c32536a2e3
Author: Maarten Hoes <[email protected]>
Date:   Thu Nov 13 12:22:54 2014 +0100

    Split script up in functions. Added example commandfile and README on usage.
    
    Change-Id: I34c6bb1793e39dbc6ecc9336f34c086fc1803a24
    Reviewed-on: https://gerrit.libreoffice.org/12404
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Caolán McNamara <[email protected]>

diff --git a/lcov-report/README b/lcov-report/README
new file mode 100644
index 0000000..e73f51a
--- /dev/null
+++ b/lcov-report/README
@@ -0,0 +1,33 @@
+
+A small script to create gcov/lcov code coverage reports of tests run
+on the libreoffice source code.
+
+
+Usage: lcov-report.sh [-b] -c [FILE] -s [DIRECTORY] -t [DIRECTORY] -w 
[DIRECTORY]
+
+
+-s
+        Specify the location where the libreoffice source code is
+        located. This flag is mandatory.
+
+-c
+        Specify the file containing the libreoffice test commands to run.
+        In it's simplest form, this file could contain a single line
+        reading something like 'cd $SRCDIR && make check'. This flag
+        is mandatory.
+
+-b
+        Specifies to build 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').
+
+-t
+        Specifies the directory in which to contain the lcov
+        tracefile's. This flag is mandatory.
+
+-w
+        Specifies the directory in which to contain the generated HTML
+        report files. This flag is mandatory.
+
diff --git a/lcov-report/lcov-report.cmds.example 
b/lcov-report/lcov-report.cmds.example
new file mode 100644
index 0000000..a577fde
--- /dev/null
+++ b/lcov-report/lcov-report.cmds.example
@@ -0,0 +1,8 @@
+cd "$SRC_DIR"
+make check
+MY_EXITCODE=$?
+if [ "$MY_EXITCODE" != "0" ]
+then
+       echo "ERROR: make check failed with exitcode $MY_EXITCODE" >&2
+       exit "$MY_EXITCODE"
+fi
diff --git a/lcov-report/lcov-report.sh b/lcov-report/lcov-report.sh
index 5adee75..607405e 100755
--- a/lcov-report/lcov-report.sh
+++ b/lcov-report/lcov-report.sh
@@ -7,41 +7,23 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #
 
-usage()
-{
-       echo "Usage: lcov-report.sh -s [DIRECTORY] -t [DIRECTORY] -w [DIRECTORY]
-       -s      source code directory
-       -t      tracefile directory
-       -w      html (www) directory"
-       exit 1
-}
 
-if [ "$#" != "6" ]
+#
+# Functions
+#
+
+
+init()
+{ 
+if [ "$SRC_DIR" = "/" -o "$TRACEFILE_DIR" = "/" -o "$HTML_DIR" = "/" ]
 then
-       usage
+       echo "ERROR: Dont use the root '/' directory for storage." >&2
+       exit 1
 fi
 
-while getopts ":s:t:w:" opt
-do
-       case $opt in
-               s)
-                       SRC_DIR="$OPTARG"
-                       ;;
-               t)
-                       TRACEFILE_DIR="$OPTARG"
-                       ;;
-               w)
-                       HTML_DIR="$OPTARG"
-                       ;;
-               *)
-                       usage
-                       ;;
-       esac
-done
-
 if [ ! -d "$SRC_DIR" ]
 then
-       echo "ERROR: Failed to locate directory $SRC_DIR" >&2
+       echo "ERROR: Failed to locate directory $SRC_DIR." >&2
        exit 1
 fi
 
@@ -50,25 +32,37 @@ rm -rf "$TRACEFILE_DIR" "$HTML_DIR"
 mkdir "$TRACEFILE_DIR"
 if [ "$?" != "0" ]
 then
-       echo "ERROR: Failed to create directory $TRACEFILE_DIR" >&2
+       echo "ERROR: Failed to create directory $TRACEFILE_DIR." >&2
        exit 1
 fi
 
 mkdir "$HTML_DIR"
 if [ "$?" != "0" ]
 then
-       echo "ERROR: Failed to create directory $HTML_DIR" >&2
+       echo "ERROR: Failed to create directory $HTML_DIR." >&2
+       exit 1
+fi
+
+if [ ! -f "$TEST_CMDS_FILE" ]
+then
+       echo "ERROR: Failed to find test command file $TEST_CMDS_FILE." >&2
        exit 1
 fi
+}
 
+lcov_cleanup()
+{
 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
+       echo "ERROR: make distclean failed with exitcode $MY_EXITCODE." >&2
        exit "$MY_EXITCODE"
 fi
 
@@ -78,7 +72,7 @@ LDFLAGS+='-fprofile-arcs' CFLAGS+='-fprofile-arcs 
-ftest-coverage' CXXFLAGS+='-f
 MY_EXITCODE=$?
 if [ "$MY_EXITCODE" != "0" ]
 then
-       echo "ERROR: configure failed with exitcode $MY_EXITCODE" >&2
+       echo "ERROR: configure failed with exitcode $MY_EXITCODE." >&2
        exit "$MY_EXITCODE"
 fi
 
@@ -86,55 +80,80 @@ make build-nocheck
 MY_EXITCODE=$?
 if [ "$MY_EXITCODE" != "0" ]
 then
-       echo "ERROR: make build-nocheck failed with exitcode $MY_EXITCODE" >&2
+       echo "ERROR: make build-nocheck failed with exitcode $MY_EXITCODE." >&2
        exit "$MY_EXITCODE"
 fi
+}
 
-
-lcov --rc geninfo_auto_base=1 --no-external --capture --initial --directory 
"$SRC_DIR" --output-file "$TRACEFILE_DIR"/libreoffice_base.info
+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/libreoffice_base.info generation 
failed with exitcode $MY_EXITCODE" >&2
+       echo "ERROR: tracefile $TRACEFILE_DIR/lcov_base.info generation failed 
with exitcode $MY_EXITCODE." >&2
        exit "$MY_EXITCODE"
 fi
+}
 
-make check
+run_tests()
+{
+/bin/sh "$TEST_CMDS_FILE"
 MY_EXITCODE=$?
 if [ "$MY_EXITCODE" != "0" ]
 then
-       echo "ERROR: make check failed with exitcode $MY_EXITCODE" >&2
+       echo "ERROR: failed to run tests from testfile $TEST_CMDS_FILE with 
exitcode $MY_EXITCODE." >&2
        exit "$MY_EXITCODE"
 fi
+}
+
 
-lcov --rc geninfo_auto_base=1 --no-external --capture --directory "$SRC_DIR" 
--output-file "$TRACEFILE_DIR"/libreoffice_test.info
+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/libreoffice_test.info generation 
failed with exitcode $MY_EXITCODE" >&2
+       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 --add-tracefile 
"$TRACEFILE_DIR"/libreoffice_base.info --add-tracefile 
"$TRACEFILE_DIR"/libreoffice_test.info --output-file 
"$TRACEFILE_DIR"/libreoffice_total.info
+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/libreoffice_total.info 
failed with exitcode $MY_EXITCODE" >&2
+       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 --remove "$TRACEFILE_DIR"/libreoffice_total.info 
 "/usr/include/*" "/usr/lib/*" "$SRC_DIR/*/UnpackedTarball/*" 
"$SRC_DIR/workdir/*" "$SRC_DIR/instdir/*" "$SRC_DIR/external/*" -o 
"$TRACEFILE_DIR"/libreoffice_filtered.info
+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/libreoffice_filtered.info failed with exitcode $MY_EXITCODE" >&2
+       echo "ERROR: tracefile generation $TRACEFILE_DIR/lcov_filtered.info 
failed with exitcode $MY_EXITCODE." >&2
        exit "$MY_EXITCODE"
 fi
+}
 
+lcov_mkhtml()
+{
 cd "$SRC_DIR"
+if [ ! -d "$SRC_DIR"/.git ]
+then
+       echo "ERROR: $SRC_DIR is not a git repository." >&2
+       exit 1
+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"
 MY_EXITCODE=$?
 if [ ! -d "$HTML_DIR"/master~"$COMMIT_DATE"_"$COMMIT_TIME" ]
@@ -143,11 +162,76 @@ then
        exit "$MY_EXITCODE"
 fi
 
-genhtml --rc geninfo_auto_base=1 --prefix "$SRC_DIR" --ignore-errors source 
"$TRACEFILE_DIR"/libreoffice_filtered.info --legend --title "commit 
$COMMIT_SHA1" 
--output-directory="$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"
 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
+       echo >&2 ERROR: Generation of html files in 
$HTML_DIR/master~"$COMMIT_DATE"_"$COMMIT_TIME" failed with exitcode 
$MY_EXITCODE.
        exit "$MY_EXITCODE"
 fi
+}
+
+usage()
+{
+       echo >&2 "Usage: lcov-report.sh [-b] -c [FILE] -s [DIRECTORY] -t 
[DIRECTORY] -w [DIRECTORY]
+       -b      build libreoffice sources
+       -c      file containing test commands to run
+       -s      source code directory
+       -t      tracefile directory
+       -w      html (www) directory"
+       exit 1
+}
+
+#
+# Main
+#
+
+if [ "$#" = "0" ]
+then
+       usage
+fi
+
+while getopts ":s:t:w:c:b" opt
+do
+       case $opt in
+               s)
+                       export SRC_DIR="$OPTARG"
+                       ;;
+               t)
+                       export TRACEFILE_DIR="$OPTARG"
+                       ;;
+               w)
+                       export HTML_DIR="$OPTARG"
+                       ;;
+               b)
+                       export SOURCE_BUILD=TRUE
+                       ;;
+               c)
+                       export TEST_CMDS_FILE="$OPTARG"
+                       ;;
+               *)
+                       usage
+                       ;;
+       esac
+done
+
+
+init
+
+lcov_cleanup
+
+if [ "$SOURCE_BUILD" = "TRUE" ]
+then
+       source_build
+fi
+
+lcov_tracefile_baseline
+
+run_tests
+
+lcov_tracefile_tests
+lcov_tracefile_join
+lcov_tracefile_cleanup
+
+lcov_mkhtml
 
_______________________________________________
Libreoffice-commits mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to