IMPALA-3572: FE unit test coverage report with Jacoco. This patch integrates Jacoco into Impala's FE test runs for getting a code coverage report.
The instrumentation and reporting functionality is disabled by default, and must be enabled explicitly, e.g., like this: mvn test -DcodeCoverage The code coverage report is stored in this location: $IMPALA_HOME/logs/fe_tests/coverage With additional changes, Jacoco can also be used to get code coverage reports for our end-to-end tests, but that is left for future work. Change-Id: Id5e4f1b8afb91210d40622aadd3d21d7ed94c2a7 Reviewed-on: http://gerrit.cloudera.org:8080/3151 Reviewed-by: Alex Behm <[email protected]> Tested-by: Internal Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/9d23f4a6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/9d23f4a6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/9d23f4a6 Branch: refs/heads/master Commit: 9d23f4a65d1c9d1dfadca6316c34304fbcb20ef6 Parents: 9a5e701 Author: Alex Behm <[email protected]> Authored: Wed May 18 13:40:21 2016 -0700 Committer: Tim Armstrong <[email protected]> Committed: Mon May 23 08:40:19 2016 -0700 ---------------------------------------------------------------------- bin/impala-config.sh | 6 ++-- bin/run-all-tests.sh | 13 +++++++-- buildall.sh | 14 ++++++---- fe/pom.xml | 71 +++++++++++++++++++++++++++++++++++++---------- 4 files changed, 81 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9d23f4a6/bin/impala-config.sh ---------------------------------------------------------------------- diff --git a/bin/impala-config.sh b/bin/impala-config.sh index 53ca315..ac1da08 100755 --- a/bin/impala-config.sh +++ b/bin/impala-config.sh @@ -187,14 +187,16 @@ export IMPALA_CLUSTER_LOGS_DIR=${IMPALA_LOGS_DIR}/cluster export IMPALA_DATA_LOADING_LOGS_DIR=${IMPALA_LOGS_DIR}/data_loading export IMPALA_DATA_LOADING_SQL_DIR=${IMPALA_DATA_LOADING_LOGS_DIR}/sql export IMPALA_FE_TEST_LOGS_DIR=${IMPALA_LOGS_DIR}/fe_tests +export IMPALA_FE_TEST_COVERAGE_DIR=${IMPALA_FE_TEST_LOGS_DIR}/coverage export IMPALA_BE_TEST_LOGS_DIR=${IMPALA_LOGS_DIR}/be_tests export IMPALA_EE_TEST_LOGS_DIR=${IMPALA_LOGS_DIR}/ee_tests export IMPALA_CUSTOM_CLUSTER_TEST_LOGS_DIR=${IMPALA_LOGS_DIR}/custom_cluster_tests # List of all Impala log dirs and create them. export IMPALA_ALL_LOGS_DIRS="${IMPALA_CLUSTER_LOGS_DIR} ${IMPALA_DATA_LOADING_LOGS_DIR} ${IMPALA_DATA_LOADING_SQL_DIR} - ${IMPALA_EE_TEST_LOGS_DIR} ${IMPALA_BE_TEST_LOGS_DIR} - ${IMPALA_EE_TEST_LOGS_DIR} ${IMPALA_CUSTOM_CLUSTER_TEST_LOGS_DIR}" + ${IMPALA_EE_TEST_LOGS_DIR} ${IMPALA_FE_TEST_COVERAGE_DIR} + ${IMPALA_BE_TEST_LOGS_DIR} ${IMPALA_EE_TEST_LOGS_DIR} + ${IMPALA_CUSTOM_CLUSTER_TEST_LOGS_DIR}" mkdir -p $IMPALA_ALL_LOGS_DIRS # Create symlinks Testing/Temporary and be/Testing/Temporary that point to the BE test http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9d23f4a6/bin/run-all-tests.sh ---------------------------------------------------------------------- diff --git a/bin/run-all-tests.sh b/bin/run-all-tests.sh index 7f4d5a7..ef7a121 100755 --- a/bin/run-all-tests.sh +++ b/bin/run-all-tests.sh @@ -57,9 +57,11 @@ if [[ "${TARGET_FILESYSTEM}" == "local" ]]; then else TEST_START_CLUSTER_ARGS="${TEST_START_CLUSTER_ARGS} --cluster_size=3" fi +# Indicates whether code coverage reports should be generated. +: ${CODE_COVERAGE:=false} # parse command line options -while getopts "e:n:" OPTION +while getopts "e:n:c" OPTION do case "$OPTION" in e) @@ -68,10 +70,14 @@ do n) NUM_TEST_ITERATIONS=$OPTARG ;; + c) + CODE_COVERAGE=true + ;; ?) echo "run-all-tests.sh [-e <exploration_strategy>] [-n <num_iters>]" echo "[-e] The exploration strategy to use. Default exploration is 'core'." echo "[-n] The number of times to run the tests. Default is 1." + echo "[-c] Set this option to generate code coverage reports." exit 1; ;; esac @@ -127,7 +133,10 @@ do MVN_ARGS="" if [[ "${TARGET_FILESYSTEM}" == "s3" ]]; then # When running against S3, only run the S3 frontend tests. - MVN_ARGS="-Dtest=S3*" + MVN_ARGS="-Dtest=S3* " + fi + if [[ "$CODE_COVERAGE" == true ]]; then + MVN_ARGS+="-DcodeCoverage" fi if ! ${IMPALA_HOME}/bin/mvn-quiet.sh -fae test ${MVN_ARGS}; then TEST_RET_CODE=1 http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9d23f4a6/buildall.sh ---------------------------------------------------------------------- diff --git a/buildall.sh b/buildall.sh index 08a3ceb..c7bff96 100755 --- a/buildall.sh +++ b/buildall.sh @@ -46,7 +46,7 @@ IMPALA_KERBERIZE=0 SNAPSHOT_FILE= METASTORE_SNAPSHOT_FILE= MAKE_IMPALA_ARGS="" -BUILD_COVERAGE=0 +CODE_COVERAGE=0 BUILD_ASAN=0 BUILD_FE_ONLY=0 MAKE_CMD=make @@ -98,7 +98,7 @@ do CMAKE_BUILD_TYPE=Release ;; -codecoverage) - BUILD_COVERAGE=1 + CODE_COVERAGE=1 ;; -asan) BUILD_ASAN=1 @@ -207,7 +207,7 @@ Examples of common tasks: done # Adjust CMAKE_BUILD_TYPE for ASAN and code coverage, if necessary. -if [[ ${BUILD_COVERAGE} -eq 1 ]]; then +if [[ ${CODE_COVERAGE} -eq 1 ]]; then case ${CMAKE_BUILD_TYPE} in Debug) CMAKE_BUILD_TYPE=CODE_COVERAGE_DEBUG @@ -218,7 +218,7 @@ if [[ ${BUILD_COVERAGE} -eq 1 ]]; then esac fi if [[ ${BUILD_ASAN} -eq 1 ]]; then - # The next check also catches cases where BUILD_COVERAGE=1, which is not supported + # The next check also catches cases where CODE_COVERAGE=1, which is not supported # together with BUILD_ASAN=1. if [[ "${CMAKE_BUILD_TYPE}" != "Debug" ]]; then echo "Address sanitizer build not supported for build type: ${CMAKE_BUILD_TYPE}" @@ -399,7 +399,11 @@ if [ $TESTDATA_ACTION -eq 1 ]; then fi if [ $TESTS_ACTION -eq 1 ]; then - ${IMPALA_HOME}/bin/run-all-tests.sh -e $EXPLORATION_STRATEGY + if [ $CODE_COVERAGE -eq 0 ]; then + ${IMPALA_HOME}/bin/run-all-tests.sh -e $EXPLORATION_STRATEGY + else + ${IMPALA_HOME}/bin/run-all-tests.sh -e $EXPLORATION_STRATEGY -c + fi fi # Generate list of files for Cscope to index http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/9d23f4a6/fe/pom.xml ---------------------------------------------------------------------- diff --git a/fe/pom.xml b/fe/pom.xml index 82f820c..78dffc3 100644 --- a/fe/pom.xml +++ b/fe/pom.xml @@ -27,6 +27,9 @@ <properties> <surefire.reports.dir>${env.IMPALA_LOGS_DIR}/fe_tests</surefire.reports.dir> + <jacoco.skip>true</jacoco.skip> + <jacoco.data.file>${env.IMPALA_FE_TEST_COVERAGE_DIR}/jacoco.exec</jacoco.data.file> + <jacoco.report.dir>${env.IMPALA_FE_TEST_COVERAGE_DIR}</jacoco.report.dir> <test.hive.testdata>${project.basedir}/../testdata/target/AllTypes.txt</test.hive.testdata> <backend.library.path>${env.IMPALA_HOME}/be/build/debug/service:${env.IMPALA_HOME}/be/build/release/service</backend.library.path> <beeswax_port>21000</beeswax_port> @@ -356,6 +359,7 @@ <artifactId>javax.json</artifactId> <version>1.0.2</version> </dependency> + </dependencies> <reporting> @@ -460,7 +464,7 @@ <configuration> <reportsDirectory>${surefire.reports.dir}</reportsDirectory> <redirectTestOutputToFile>true</redirectTestOutputToFile> - <argLine>-Djava.library.path=${java.library.path}:${backend.library.path}</argLine> + <argLine>-Djava.library.path=${java.library.path}:${backend.library.path} ${surefireJacocoArg}</argLine> <systemProperties> <property> <name>testExecutionMode</name> @@ -479,19 +483,6 @@ </plugin> <plugin> - <groupId>com.atlassian.maven.plugins</groupId> - <artifactId>maven-clover2-plugin</artifactId> - <version>3.0.2</version> - <configuration> - <generateHtml>true</generateHtml> - <generateXml>true</generateXml> - <excludes> - <exclude>**/jdbc/*.java</exclude> - </excludes> - </configuration> - </plugin> - - <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.5</version> @@ -541,6 +532,41 @@ </systemProperties> </configuration> </plugin> + + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.7.6.201602180812</version> + <executions> + <execution> + <id>prepare-jacoco-agent</id> + <goals> + <goal>prepare-agent</goal> + </goals> + <configuration> + <destFile>${jacoco.data.file}</destFile> + <propertyName>surefireJacocoArg</propertyName> + </configuration> + </execution> + <execution> + <id>jacoco-report</id> + <phase>test</phase> + <goals> + <goal>report</goal> + </goals> + <configuration> + <dataFile>${jacoco.data.file}</dataFile> + <outputDirectory>${jacoco.report.dir}</outputDirectory> + </configuration> + </execution> + </executions> + <configuration> + <!-- Code coverage reporting is disabled by default and must be enabled + when running tests like this: mvn test -DcodeCoverage --> + <skip>${jacoco.skip}</skip> + </configuration> + </plugin> + </plugins> <pluginManagement> <plugins> @@ -714,5 +740,22 @@ <thrift.executable>${env.THRIFT_HOME}/bin/thrift</thrift.executable> </properties> </profile> + <profile> + <id>jacoco-code-coverage</id> + <activation> + <property> + <!-- Enable code coverage if the 'codeCoverage' property is set. + Usage: mvn test -DcodeCoverage --> + <name>codeCoverage</name> + </property> + </activation> + <properties> + <jacoco.skip>false</jacoco.skip> + <!-- Due to Jacoco's runtime instrumentation some tests could fail. + In order to still produce a coverage report it is recommended + to ignore test failures. --> + <maven.test.failure.ignore>true</maven.test.failure.ignore> + </properties> + </profile> </profiles> </project>
