From: <svn...@op...> - 2009-08-13 21:00:22
|
Author: scriptor Date: Thu Aug 13 23:00:08 2009 New Revision: 5714 URL: http://www.opensync.org/changeset/5714 Log: 1. I have added "make coverage". 2. I have written a workaround for the problem, that INCLUDE(OpenSyncInternal) sets the CMAKE_BUILD_TYPE for the plugin to the value that is being used for libopensync itself, regardless of what has been defined on the cmake command line for the plugin. With this workaround -DCMAKE_BUILD_TYPE works again. Added: plugins/ldap-sync/tests/coverage.sh.cmake (contents, props changed) Modified: plugins/ldap-sync/CMakeLists.txt Modified: plugins/ldap-sync/CMakeLists.txt ============================================================================== --- plugins/ldap-sync/CMakeLists.txt Wed Aug 12 22:40:23 2009 (r5713) +++ plugins/ldap-sync/CMakeLists.txt Thu Aug 13 23:00:08 2009 (r5714) @@ -45,6 +45,7 @@ FIND_PACKAGE( LibGCrypt REQUIRED ) FIND_PACKAGE( LibSASL2 REQUIRED ) FIND_PACKAGE( LibGSSAPIV2 ) +FIND_PACKAGE( Check ) # By default use openldap, if available. @@ -100,18 +101,42 @@ +# Test configuration +OPTION( ENABLE_UNITTESTS "Should the test suite be built? " OFF ) +IF ( CHECK_FOUND ) + SET( ENABLE_UNITTESTS ON ) +ELSE ( CHECK_FOUND ) + SET( ENABLE_UNITTESTS OFF ) +ENDIF ( CHECK_FOUND ) + + +# Workaround for wrong setting of CMAKE_BUILD_TYPE: First of two steps: +IF (CMAKE_BUILD_TYPE) + SET(CORRECT_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "The CMAKE_BUILD_TYPE definition in /usr/local/share/libopensync1/cmake/modules/OpenSyncInternal.cmake overrides even the command line settings here. This variable aims to fix this." FORCE ) +ENDIF (CMAKE_BUILD_TYPE) +# Set some defaults INCLUDE( Testing ) +INCLUDE( ShowStatus ) INCLUDE( OpenSyncInternal ) +# Now, that CMAKE_BUILD_TYPE has been corrupted by OpenSyncInternal.cmake +# we reset it to the what has been configured here: +IF (CORRECT_CMAKE_BUILD_TYPE) + SET( CMAKE_BUILD_TYPE "${CORRECT_CMAKE_BUILD_TYPE}" ) +ENDIF (CORRECT_CMAKE_BUILD_TYPE) + + SET( LDAP_PLUGIN_OPENSYNC_CONFIGDIR "${SHARE_INSTALL_DIR}/libopensync1/defaults" CACHE PATH "OpenSync plugin configuration directory: Where the style sheets can be found." ) SET( LDAP_PLUGIN_OPENSYNC_SCHEMASDIR "${SHARE_INSTALL_DIR}/libopensync1/schemas" CACHE PATH "OpenSync XML schemata directory." ) ADD_SUBDIRECTORY( src ) -ADD_SUBDIRECTORY( tests ) +IF (ENABLE_UNITTESTS) + ADD_SUBDIRECTORY( tests ) +ENDIF (ENABLE_UNITTESTS) ADD_SUBDIRECTORY( misc ) @@ -130,6 +155,11 @@ CONFIGURE_FILE( "config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/config.h" ) +################### make coverage ########################## +CONFIGURE_FILE( "tests/coverage.sh.cmake" "${CMAKE_CURRENT_BINARY_DIR}/tests/coverage.sh") +ADD_CUSTOM_TARGET(coverage + "${CMAKE_CURRENT_BINARY_DIR}/tests/coverage.sh") + ######## The MacroEnsureOutOfSourceBuild.cmake fails sometimes... ######### MESSAGE(STATUS "CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}" ) @@ -152,8 +182,11 @@ ##################### debugging cmake... ################################# # "cmake ... -DCMAKE_BUILD_TYPE=Whatever" sometimes does not work. +# Actually, it NEVER works here...What's going on? MESSAGE(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}" ) - +SHOW_STATUS( ENABLE_UNITTESTS "Build the test suite:\t\t" ) +SHOW_STATUS( RUN_LONG_TESTS "Run rather time consuming tests, as well:" ) +SHOW_STATUS( RUN_AUTH_TESTS "Run the authentication specific tests, too:" ) ########################################################################## Added: plugins/ldap-sync/tests/coverage.sh.cmake ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ plugins/ldap-sync/tests/coverage.sh.cmake Thu Aug 13 23:00:08 2009 (r5714) @@ -0,0 +1,92 @@ +#!/bin/sh + +SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" +BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" + + + +if test -z "$SOURCE_DIR"; then + echo "ERROR: \$SOURCE_DIR is empty. Exiting." + exit 1 +fi + +if test -z "$BINARY_DIR"; then + echo "ERROR: \$BINARY_DIR is empty. Exiting." + exit 1 +fi + + +echo -n "Checking Code Coverage of unit tests" +DATE=$( date +%Y%m%d%H%M%S ) + +if [ -d .svn ]; then + REV=`LANG=C svn info | grep Revision | cut -c 11-` + echo " for SVN Revision: $REV" + TITLE="ldap_plugin_SVN_"$REV"_"$DATE +else + echo ":" + TITLE="ldap_plugin_"$DATE +fi +echo $TITLE + +if ! [ -d $BINARY_DIR/coverage/html ]; then + mkdir -p $BINARY_DIR/coverage/html +fi + +## create gcda files +RESULT=`find $BINARY_DIR -name "*.gcda" -print | wc -l` +if [ "$RESULT" == "0" ]; then + ctest -R . +fi + +## analyze statistics +lcov \ + --test-name "$TITLE" \ + --base-directory $SOURCE_DIR \ + --directory $BINARY_DIR \ + --quiet \ + --capture \ + --output-file $BINARY_DIR/coverage/$TITLE.info +genhtml --legend -t "$TITLE" -o $BINARY_DIR/coverage/html/$TITLE $BINARY_DIR/coverage/$TITLE.info &> /dev/null + +if test -d "$BINARY_DIR/coverage/html"; then + cd $BINARY_DIR/coverage/html/ + if [ -e LATEST ]; + then rm -f LATEST; + fi + ln -s $TITLE LATEST + cd $BINARY_DIR +else + echo "WARNING: \"$BINARY_DIR/coverage/html\" does not exist. Ignoring for now." +fi + +## cleanup gcda files +#lcov \ +# --test-name "$TITLE" \ +# --base-directory $SOURCE_DIR \ +# --directory $BINARY_DIR \ +# --quiet \ +# --zerocounters \ +# --output-file coverage/$TITLE.info + +echo -n "Code Coverage is: " +grep " %</td>" coverage/html/$TITLE/index.html | sed -e "s/^[^>]*>//g" -e "s/<[^>]*>//g" +echo "" + +if test -e "$BINARY_DIR/coverage/html/$TITLE/index.html"; then + echo "Now, have a look at " + echo + echo -e "\t$BINARY_DIR/coverage/html/$TITLE/index.html" +else + echo "ERROR: $BINARY_DIR/coverage/html/$TITLE/index.html has not been created. So the lcov command must have failed." +fi + +echo +echo -e "\nTroubleshooting:\n If the Code Coverage number is quite low (less then 51%):" +echo -e "\t-Did you run any unit tests before $0?" +echo -e "\t-Did you build with -DCMAKE_BUILD_TYPE=\"Profiling\"?" +echo -e "\t-Run ALL available unit tests!" +echo -e "\t-Check if testcases in unit test are disabled!" +echo -e "\t-Fix unit tests and their test cases!" +echo -e "\t-Write new and more test cases!" +exit 0 |