Skip to content
Commits on Source (29)
#!/usr/bin/env bash
###########################################################################
# before_install.sh
# ---------------------
# Date : February 2017
# Copyright : (C) 2017 by Denis Rouzaud
# Email : denis.rouzaud@gmail.com
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
pip install autopep8 nose2 mock termcolor
export PERL_MM_USE_DEFAULT=1
export PERL_EXTUTILS_AUTOINSTALL="--defaultdeps"
cpanm --notest App::Licensecheck
#!/usr/bin/env bash
###########################################################################
# before_script.sh
# ---------------------
# Date : February 2017
# Copyright : (C) 2017 by Denis Rouzaud
# Email : denis.rouzaud@gmail.com
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
#!/usr/bin/env bash
###########################################################################
# install.sh
# ---------------------
# Date : February 2017
# Copyright : (C) 2017 by Denis Rouzaud
# Email : denis.rouzaud@gmail.com
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
export CORES=2
mkdir build
pushd build || exit
cmake -DWITH_SERVER=ON -DUSE_CCACHE=OFF -DWITH_CORE=OFF -DWITH_APIDOC=ON -DWITH_ASTYLE=ON -DENABLE_TESTS=ON ..
popd || exit
#!/usr/bin/env bash
###########################################################################
# script.sh
# ---------------------
# Date : February 2017
# Copyright : (C) 2017 by Denis Rouzaud
# Email : denis.rouzaud@gmail.com
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
set -e
pushd build
export CTEST_BUILD_DIR=${TRAVIS_BUILD_DIR}
export CTEST_BUILD_COMMAND="/usr/bin/make -j3 -i -k"
python3 "${TRAVIS_BUILD_DIR}/.ci/travis/scripts/ctest2travis.py" xvfb-run ctest -VV --output-on-failure -S "${TRAVIS_BUILD_DIR}/.ci/travis/travis.ctest"
popd
#!/usr/bin/env bash
###########################################################################
# before_install.sh
# ---------------------
# Date : March 2016
# Copyright : (C) 2016 by Matthias Kuhn
# Email : matthias at opengis dot ch
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
#pip3 install termcolor
#!/usr/bin/env bash
###########################################################################
# before_script.sh
# ---------------------
# Date : August 2015
# Copyright : (C) 2015 by Nyall Dawson
# Email : nyall dot dawson at gmail dot com
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
set -e
pushd .docker
DOCKER_DEPS_PUSH=$( [[ $TRAVIS_REPO_SLUG =~ qgis/QGIS ]] && [[ "${TRAVIS_EVENT_TYPE}" != "pull_request" ]] && echo "true" || echo "false" )
DOCKER_DEPS_IMAGE_REBUILD=$( [[ $TRAVIS_COMMIT_MESSAGE =~ '[docker] update dependencies' ]] && echo "true" || echo "false" )
echo "travis_fold:start:travis_env"
echo "${bold}Travis environment variables${endbold}"
echo "TRAVIS_BRANCH: $TRAVIS_BRANCH"
echo "TRAVIS_EVENT_TYPE: $TRAVIS_EVENT_TYPE"
echo "DOCKER_TAG: $DOCKER_TAG"
echo "TRAVIS_COMMIT_MESSAGE: $TRAVIS_COMMIT_MESSAGE"
echo "DOCKER_DEPS_PUSH: $DOCKER_DEPS_PUSH"
echo "DOCKER_DEPS_IMAGE_REBUILD: $DOCKER_DEPS_IMAGE_REBUILD"
echo "DOCKER_BUILD_QGIS_IMAGE: $DOCKER_BUILD_QGIS_IMAGE"
echo "DOCKER_BUILD_DEPS_FILE: $DOCKER_BUILD_DEPS_FILE"
echo "TRAVIS_TIMESTAMP: $TRAVIS_TIMESTAMP"
echo "travis_fold:end:travis_env"
echo "travis_fold:start:docker_build"
echo "${bold}Docker build deps${endbold}"
docker --version
if [[ $DOCKER_BUILD_QGIS_IMAGE =~ false ]]; then
docker-compose --version
docker-compose -f ${TRAVIS_BUILD_DIR}/.docker/docker-compose.travis.yml config
fi
if [[ $DOCKER_DEPS_IMAGE_REBUILD =~ true ]]; then
docker build --no-cache -t "qgis/qgis3-build-deps:${DOCKER_TAG}" -f ${DOCKER_BUILD_DEPS_FILE} .
else
docker pull "qgis/qgis3-build-deps:${DOCKER_TAG}" || true
docker build --cache-from "qgis/qgis3-build-deps:${DOCKER_TAG}" -t "qgis/qgis3-build-deps:${DOCKER_TAG}" -f ${DOCKER_BUILD_DEPS_FILE} .
fi
echo "travis_fold:end:docker_build"
echo "travis_fold:start:docker_push"
echo "${bold}Docker push deps${endbold}"
# image should be pushed even if QGIS build fails
# but push is achieved only on branches (not for PRs)
if [[ $DOCKER_DEPS_PUSH =~ true ]]; then
echo "push to qgis/qgis3-build-deps:${DOCKER_TAG}"
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
#docker tag "qgis/qgis3-build-deps:${DOCKER_TAG}" "qgis/qgis3-build-deps:latest"
docker push "qgis/qgis3-build-deps:${DOCKER_TAG}"
fi
echo "travis_fold:end:docker_push"
popd
# black list
PyQgsJsonUtils
PyQgsLocalServer
PyQgsPalLabelingServer
qgis_composermapgridtest
qgis_composerutils
PyQgsAppStartup
# code layout tests are run on separate build
qgis_spelling
qgis_sipify
qgis_sip_include
qgis_sip_uptodate
# flaky
qgis_filedownloader
qgis_openstreetmaptest
qgis_wcsprovidertest
PyQgsWFSProviderGUI
qgis_ziplayertest
# Flaky, see https://dash.orfeo-toolbox.org/testDetails.php?test=63061783&build=297405
PyQgsSpatialiteProvider
# Flaky, the ms odbc driver crashes a lot on the ubuntu docker image. Retest when
# the docker base image is upgraded
PyQgsMssqlProvider
# Need a local postgres installation
PyQgsAuthManagerPKIPostgresTest
PyQgsAuthManagerPasswordPostgresTest
PyQgsAuthManagerOgrPostgresTest
PyQgsDbManagerPostgis
# Needs an OpenCL device, the library is not enough
qgis_openclutilstest
#!/usr/bin/env bash
set -e
##############
# Setup ccache
##############
export CCACHE_TEMPDIR=/tmp
ccache -M 1G
# Temporarily uncomment to debug ccache issues
# export CCACHE_LOGFILE=/tmp/cache.debug
ccache -z
############################
# Setup the (c)test environment
############################
export LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
export SEGFAULT_SIGNALS="abrt segv"
export CTEST_BUILD_COMMAND="/usr/bin/ninja"
export CTEST_PARALLEL_LEVEL=1
##############################
# Variables for output styling
##############################
bold=$(tput bold)
endbold=$(tput sgr0)
###########
# Configure
###########
pushd /root/QGIS > /dev/null
mkdir -p build
pushd build > /dev/null
echo "travis_fold:start:cmake"
echo "${bold}Running cmake...${endbold}"
cmake \
-GNinja \
-DUSE_CCACHE=OFF \
-DWITH_QUICK=ON \
-DWITH_3D=ON \
-DWITH_STAGED_PLUGINS=ON \
-DWITH_GRASS=OFF \
-DSUPPRESS_QT_WARNINGS=ON \
-DENABLE_MODELTEST=ON \
-DENABLE_PGTEST=ON \
-DENABLE_MSSQLTEST=ON \
-DWITH_QSPATIALITE=ON \
-DWITH_QWTPOLAR=OFF \
-DWITH_APIDOC=OFF \
-DWITH_ASTYLE=OFF \
-DWITH_DESKTOP=ON \
-DWITH_BINDINGS=ON \
-DWITH_SERVER=ON \
-DDISABLE_DEPRECATED=ON \
-DPYTHON_TEST_WRAPPER="timeout -sSIGSEGV 55s"\
-DCXX_EXTRA_FLAGS="${CLANG_WARNINGS}" \
-DWERROR=TRUE \
-DQT5_3DEXTRA_LIBRARY="/usr/lib/x86_64-linux-gnu/libQt53DExtras.so" \
-DQT5_3DEXTRA_INCLUDE_DIR="/root/QGIS/external/qt3dextra-headers" \
-DCMAKE_PREFIX_PATH="/root/QGIS/external/qt3dextra-headers/cmake" \
..
echo "travis_fold:end:cmake"
#######
# Build
#######
# Calculate the timeout for building.
# The tests should be aborted before travis times out, in order to allow uploading
# the ccache and therefore speedup subsequent e builds.
#
# Travis will kill the job after approx 150 minutes, we subtract 5 minutes for
# uploading and subtract the bootstrapping time from that.
# Hopefully clocks are in sync :)
TRAVIS_TIME=150
UPLOAD_TIME=5
CURRENT_TIME=$(date +%s)
TIMEOUT=$((( TRAVIS_TIME - UPLOAD_TIME ) * 60 - CURRENT_TIME + TRAVIS_TIMESTAMP))
TIMEOUT=$(( TIMEOUT < 300 ? 300 : TIMEOUT ))
echo "Timeout: ${TIMEOUT}s (started at ${TRAVIS_TIMESTAMP}, current: ${CURRENT_TIME})"
# echo "travis_fold:start:ninja-build.1"
echo "${bold}Building QGIS...${endbold}"
timeout ${TIMEOUT}s ${CTEST_BUILD_COMMAND}
# echo "travis_fold:end:ninja-build.1"
rv=$?
if [ $rv -eq 124 ] ; then
printf '\n\n${bold}Build and test timeout. Please restart the build for meaningful results.${endbold}\n'
exit #$rv
fi
# Temporarily uncomment to debug ccache issues
# echo "travis_fold:start:ccache-debug"
# cat /tmp/cache.debug
# echo "travis_fold:end:ccache-debug"
############################
# Restore postgres test data
############################
printf "[qgis_test]\nhost=postgres\nport=5432\ndbname=qgis_test\nuser=docker\npassword=docker" > ~/.pg_service.conf
export PGUSER=docker
export PGHOST=postgres
export PGPASSWORD=docker
export PGDATABASE=qgis_test
pushd /root/QGIS > /dev/null
/root/QGIS/tests/testdata/provider/testdata_pg.sh
popd > /dev/null # /root/QGIS
##############################
# Restore SQL Server test data
##############################
echo "Importing SQL Server test data..."
export SQLUSER=sa
export SQLHOST=mssql
export SQLPORT=1433
export SQLPASSWORD='<YourStrong!Passw0rd>'
export SQLDATABASE=qgis_test
export PATH=$PATH:/opt/mssql-tools/bin
pushd /root/QGIS > /dev/null
/root/QGIS/tests/testdata/provider/testdata_mssql.sh
popd > /dev/null # /root/QGIS
echo "Setting up DSN for test SQL Server"
cat <<EOT > /etc/odbc.ini
[ODBC Data Sources]
testsqlserver = ODBC Driver 17 for SQL Server
[testsqlserver]
Driver = ODBC Driver 17 for SQL Server
Description = Test SQL Server
Server = mssql
EOT
###########
# Run tests
###########
CURRENT_TIME=$(date +%s)
TIMEOUT=$((( TRAVIS_TIME - UPLOAD_TIME) * 60 - CURRENT_TIME + TRAVIS_TIMESTAMP))
echo "Timeout: ${TIMEOUT}s (started at ${TRAVIS_TIMESTAMP}, current: ${CURRENT_TIME})"
timeout ${TIMEOUT}s python3 /root/QGIS/.ci/travis/scripts/ctest2travis.py xvfb-run ctest -V -E "$(cat /root/QGIS/.ci/travis/linux/blacklist.txt | sed -r '/^(#.*?)?$/d' | paste -sd '|' -)" -S /root/QGIS/.ci/travis/travis.ctest --output-on-failure
rv=$?
if [ $rv -eq 124 ] ; then
printf '\n\n${bold}Build and test timeout. Please restart the build for meaningful results.${endbold}\n'
exit #$rv
fi
########################
# Show ccache statistics
########################
echo "travis_fold:start:ccache.stats"
echo "ccache statistics"
ccache -s
echo "travis_fold:end:ccache.stats"
popd > /dev/null # build
popd > /dev/null # /root/QGIS
[ -r /tmp/ctest-important.log ] && cat /tmp/ctest-important.log || true
#!/usr/bin/env bash
###########################################################################
# install.sh
# ---------------------
# Date : March 2016
# Copyright : (C) 2016 by Matthias Kuhn
# Email : matthias at opengis dot ch
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
shopt -s expand_aliases
alias python=python3
#!/usr/bin/env bash
###########################################################################
# script.sh
# ---------------------
# Date : March 2016
# Copyright : (C) 2016 by Matthias Kuhn
# Email : matthias at opengis dot ch
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
set -e
mkdir -p "$CCACHE_DIR"
if [[ ${DOCKER_BUILD_QGIS_IMAGE} =~ true ]]; then
# copy ccache dir within QGIS source so it can be accessed from docker
cp -r ${CCACHE_DIR} ${TRAVIS_BUILD_DIR}/.ccache
# building docker images
DIR=$(git rev-parse --show-toplevel)/.docker
pushd "${DIR}"
echo "${bold}Building QGIS Docker image '${DOCKER_TAG}'...${endbold}"
docker build --build-arg DOCKER_TAG="${DOCKER_TAG}" \
--cache-from "qgis/qgis:${DOCKER_TAG}" \
-t "qgis/qgis:${DOCKER_TAG}" \
-f qgis.dockerfile ..
echo "${bold}Pushing image to docker hub...${endbold}"
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
docker push "qgis/qgis:${DOCKER_TAG}"
popd
else
# running tests
docker-compose -f ${TRAVIS_BUILD_DIR}/.docker/docker-compose.travis.yml run --rm qgis-deps
fi
#!/usr/bin/env bash
ccache -s
#!/usr/bin/env bash
###########################################################################
# before_install.sh
# ---------------------
# Date : August 2015
# Copyright : (C) 2015 by Nyall Dawson
# Email : nyall dot dawson at gmail dot com
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
date +%s > /tmp/travis_timestamp
brew tap osgeo/osgeo4mac
brew update
brew install python3
pip3 install \
numpy \
psycopg2 \
numpy \
nose2 \
pyyaml \
mock \
future \
termcolor \
oauthlib
brew install \
qscintilla2 \
qt \
qt5-webkit \
qca \
qwtpolar \
gsl \
sqlite \
expat \
proj \
gdal2-python --with-python3 \
spawn-fcgi \
lighttpd \
poppler \
bison \
expat \
bison \
flex \
ninja \
ccache \
spatialindex \
fastcgi \
qtkeychain \
gnu-sed \
libzip
mkdir -p "${HOME}/Library/Python/3.6/lib/python/site-packages"
echo 'import site; site.addsitedir("/usr/local/opt/gdal2-python/lib/python3.6/site-packages")' >> "${HOME}/Library/Python/3.6/lib/python/site-packages/gdal2.pth"
# layout tests are run on separate build
qgis_spelling
qgis_sipify
qgis_sip_uptodate
qgis_openstreetmaptest
qgis_wcsprovidertest
PyQgsServer
PyQgsOfflineEditingWFS
ProcessingGdalAlgorithmsTest
ProcessingGrass7AlgorithmsImageryTest
ProcessingGrass7AlgorithmsRasterTest
qgis_composerhtmltest
PyQgsOfflineEditingWFS
qgis_authconfigtest
qgis_atlascompositiontest
qgis_composerlabeltest
qgis_composerrotationtest
qgis_composerscalebartest
qgis_composerutilstest
qgis_composertablev2test
qgis_diagramtest
qgis_fontmarkertest
qgis_labelingenginetest
qgis_legendrenderertest
qgis_maprotationtest
qgis_composerhtmltest
qgis_mapcanvastest
qgis_filedownloader
PyQgsAnnotation
PyQgsAtlasComposition
PyQgsComposerLegend
PyQgsComposerMapGrid
PyQgsDistanceArea
PyQgsPalLabelingBase
PyQgsPalLabelingPlacement
PyQgsPalLabelingComposer
ProcessingQgisAlgorithmsTest
qgis_composermapgridtest
qgis_composerpicturetest
qgis_taskmanagertest
PyQgsPalLabelingCanvas
PyQgsTextRenderer
PyQgsSpatialiteProvider
PyQgsSymbolLayer
PyQgsVectorFileWriter
PyQgsVirtualLayerProvider
PyQgsWFSProvider
PyQgsWFSProviderGUI
PyQgsLayerDependencies
PyQgsDBManagerGpkg
PyQgsFileDownloader
PyQgsSettings
PyQgsConsole
PyQgsLocator
PyQgsAuthManagerPasswordOWSTest
#!/usr/bin/env bash
###########################################################################
# install.sh
# ---------------------
# Date : August 2015
# Copyright : (C) 2015 by Nyall Dawson
# Email : nyall dot dawson at gmail dot com
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
mkdir build
pushd build || exit
export PATH=/usr/local/opt/ccache/libexec:$PATH
HB=$(brew --prefix)
# force looking in HB/opt paths first, so headers in HB/include are not found first
prefixes="qt5
qt5-webkit
qscintilla2
qwt
qwtpolar
qca
qtkeychain
gdal2
gsl
geos
proj
libspatialite
spatialindex
fcgi
expat
sqlite
flex
bison
libzip"
full_prefixes=""
for p in ${prefixes}; do
full_prefixes+="${HB}/opt/${p};"
done
#no PGTEST for OSX - can't get postgres to start with brew install
#no APIDOC for OSX - doxygen tests and warnings are covered by linux build
#no deprecated-declarations warnings... requires QGIS ported to Cocoa
cmake \
-G 'Ninja' \
-DCMAKE_FIND_FRAMEWORK:STRING=LAST \
-DCMAKE_PREFIX_PATH:STRING="${full_prefixes}" \
-DWITH_SERVER=OFF \
-DWITH_DESKTOP=OFF \
-DWITH_STAGED_PLUGINS=ON \
-DENABLE_MODELTEST=ON \
-DENABLE_PGTEST=OFF \
-DWITH_QWTPOLAR=OFF \
-DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations" \
..
popd || exit
#!/usr/bin/env bash
###########################################################################
# script.sh
# ---------------------
# Date : August 2015
# Copyright : (C) 2015 by Nyall Dawson
# Email : nyall dot dawson at gmail dot com
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "$PATH"
export PATH=/usr/bin:${PATH}
ccache -M 500M
ccache -z
# Calculate the timeout for the tests.
# The tests should be aborted before travis times out, in order to allow uploading
# the ccache and therefore speedup subsequent e builds.
#
# Travis will kill the job after approx 48 minutes, we subtract 8 minutes for
# uploading and initialization (40) and subtract the bootstrapping time from that.
TIMEOUT=$((40 * 60 - $(date +%s) + $(cat /tmp/travis_timestamp)))
export CTEST_BUILD_COMMAND=/usr/local/bin/ninja
export CTEST_BUILD_DIR=${TRAVIS_BUILD_DIR}
gtimeout "${TIMEOUT}s" ctest -V -E "$(cat "${DIR}"/blacklist.txt | gsed -r '/^(#.*?)?$/d' | gpaste -sd '|' -)" -S "${DIR}/../travis.ctest" --output-on-failure
rv=$?
if [ $rv -eq 124 ] ; then
printf '\n\n\033[0;33mBuild and test timeout. Please restart the build for meaningful results.\033[0m\n'
fi
exit $rv
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
***************************************************************************
ctest2travis.py
---------------------
Date : March 2017
Copyright : (C) 2017 by Matthias Kuhn
Email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Matthias Kuhn'
__date__ = 'March 2017'
__copyright__ = '(C) 2017, Matthias Kuhn'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '89ee6f6e2334c1350c78a845ca36a46fe14bf012'
# This script parses output from ctest and injects
#
# - Colors for failing unit tests and test cases
#
# - `travis_fold` control sequences to hide uninteresting output by default
import sys
import re
import shlex
import subprocess
from termcolor import colored
fold_stack = list()
def start_fold(tag):
sys.stdout.write('travis_fold:start:{}\n'.format(tag))
fold_stack.append(tag)
def end_fold():
try:
tag = fold_stack.pop()
sys.stdout.write('travis_fold:end:{}\n'.format(tag))
except IndexError:
updated_line = colored("======================", 'magenta')
updated_line += colored("ctest2travis error when processing the following line:", 'magenta')
updated_line += colored("----------------------", 'magenta')
updated_line += colored(updated_line, 'magenta')
updated_line += colored("----------------------", 'magenta')
updated_line += colored("Tried to end fold, but fold was never started.", 'magenta')
updated_line += colored("======================", 'magenta')
test_count = 0
def start_test_fold():
global test_count
sys.stdout.write('Running tests')
start_fold('test.{}'.format(test_count))
test_count += 1
in_failing_test = False
in_failure = False
p = subprocess.Popen(sys.argv[1:], stdout=subprocess.PIPE)
for line in p.stdout:
updated_line = line.decode('utf-8')
if re.match('Run dashboard with model Experimental', updated_line):
start_fold('build')
updated_line = '{title}\n{line}'.format(title=colored('Running tests...', 'yellow', attrs=['bold']), line=updated_line)
elif re.match('Test project /home/travis/build/qgis/QGIS/build', updated_line):
end_fold() # tag=build
start_test_fold()
if re.search('\*\*\*Failed', updated_line) or re.search('\*\*\*Timeout', updated_line):
end_fold()
updated_line = colored(updated_line, 'red')
in_failing_test = True
if in_failing_test:
if re.match(' Start', updated_line):
start_test_fold()
in_failing_test = False
elif in_failure:
if re.match('PASS', updated_line) or re.match('Ran', updated_line):
in_failure = False
else:
updated_line = colored(updated_line, 'yellow')
elif re.search('\*\*\* Segmentation fault', updated_line):
start_fold('segfault')
updated_line = colored(updated_line, 'magenta')
elif re.match(' Test failed: Segmentation fault', updated_line):
end_fold()
else:
if re.match('(FAIL|ERROR)[:\!].*', updated_line):
updated_line = colored(updated_line, 'yellow')
in_failure = True
if not in_failing_test and re.search('[0-9]+% tests passed, [0-9]+ tests failed out of', updated_line):
end_fold()
if re.search('100% tests passed', updated_line):
updated_line = colored(updated_line, 'green')
if re.match('Submit files', updated_line):
start_fold('submit')
elif re.search('Test results submitted to', updated_line):
end_fold()
sys.stdout.write(updated_line)
exit(p.wait())
SET (CTEST_SOURCE_DIRECTORY $ENV{CTEST_BUILD_DIR})
SET (CTEST_BINARY_DIRECTORY $ENV{CTEST_BUILD_DIR}/build)
#SET (CTEST_SOURCE_DIRECTORY /usr/src/QGIS)
#SET (CTEST_BINARY_DIRECTORY /usr/src/qgis-build)
SET (CTEST_CMAKE_COMMAND "cmake")
SET (CTEST_BUILD_COMMAND $ENV{CTEST_BUILD_COMMAND})
SET (CTEST_SITE "travis-ci.org")
IF ($ENV{TRAVIS_PULL_REQUEST} STREQUAL "false")
# No pull request
SET (CTEST_BUILD_NAME "$ENV{TRAVIS_BRANCH} ($ENV{BUILD}) ($ENV{TRAVIS_COMMIT})")
ELSE()
SET (CTEST_BUILD_NAME "PR: $ENV{TRAVIS_PULL_REQUEST} / $ENV{TRAVIS_BRANCH} ($ENV{BUILD}) ($ENV{TRAVIS_COMMIT})")
ENDIF()
SET (CTEST_BUILD_CONFIGURATION "Release")
IF ($ENV{TRAVIS_CONFIG} STREQUAL "code_layout")
SET (CTEST_TEST_TIMEOUT 600) # 600 seconds, spelling test might take some time
ELSE()
SET (CTEST_TEST_TIMEOUT 60) # 60 seconds
ENDIF()
IF(DEFINED ENV{CTEST_PARALLEL_LEVEL})
SET(PARALLEL_LEVEL $ENV{CTEST_PARALLEL_LEVEL})
ELSE(DEFINED ENV{CTEST_PARALLEL_LEVEL})
SET(PARALLEL_LEVEL 2)
ENDIF(DEFINED ENV{CTEST_PARALLEL_LEVEL})
SET (INITIAL_CACHE "
BUILDNAME:STRING=${CTEST_BUILD_NAME}
SITE:STRING=${CTEST_SITE}
CTEST_USE_LAUNCHERS:BOOL=ON
")
SET (CTEST_NOTES_FILES
${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}
${CTEST_BINARY_DIRECTORY}/CMakeCache.txt
)
IF(NOT WIN32)
STRING(ASCII 27 Esc)
SET(ColorReset "${Esc}[m")
SET(ColorBold "${Esc}[1m")
SET(Red "${Esc}[31m")
SET(Green "${Esc}[32m")
SET(Yellow "${Esc}[33m")
SET(Blue "${Esc}[34m")
SET(Magenta "${Esc}[35m")
SET(Cyan "${Esc}[36m")
SET(White "${Esc}[37m")
SET(BoldRed "${Esc}[1;31m")
SET(BoldGreen "${Esc}[1;32m")
SET(BoldYellow "${Esc}[1;33m")
SET(BoldBlue "${Esc}[1;34m")
SET(BoldMagenta "${Esc}[1;35m")
SET(BoldCyan "${Esc}[1;36m")
SET(BoldWhite "${Esc}[1;37m")
ENDIF(NOT WIN32)
# Requires a track on the CDash server
#ctest_start(Experimental TRACK Travis)
ctest_start(Experimental)
ctest_build (BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE BUILDRES NUMBER_WARNINGS NUMWARN NUMBER_ERRORS NUMERR)
# Create link to test results
# CDash on OTB requires the date to be set for the search to work and that's the timezone this requires
SET(ENV{TZ} "UTC-6")
EXECUTE_PROCESS(COMMAND date +%Y-%m-%d OUTPUT_VARIABLE CDASH_DATE)
SET(RESULT_LINK "http://dash.orfeo-toolbox.org/index.php?project=QGIS&filtercount=1&showfilters=1&field1=buildname/string&compare1=63&value1=$ENV{TRAVIS_COMMIT}&date=${CDASH_DATE}")
EXECUTE_PROCESS(COMMAND curl --data-urlencode "url=${RESULT_LINK}" -s http://tinyurl.com/api-create.php
OUTPUT_VARIABLE SHORTURL)
SET(IGNORE_BUILD_FAILURES $ENV{IGNORE_BUILD_FAILURES})
IF(NOT IGNORE_BUILD_FAILURES)
IF(NOT ${BUILDRES} EQUAL 0 OR NOT ${NUMERR} EQUAL 0)
ctest_submit (RETRY_COUNT 3 RETRY_DELAY 30)
MESSAGE("")
MESSAGE(" ${Yellow}Test results submitted to${ColorReset}")
MESSAGE(" ${BoldYellow}${SHORTURL}${ColorReset}")
MESSAGE("")
MESSAGE( FATAL_ERROR " ${Red}Build failed. Not running tests.${ColorReset}" )
MESSAGE("")
ENDIF(NOT ${BUILDRES} EQUAL 0 OR NOT ${NUMERR} EQUAL 0)
ENDIF(NOT IGNORE_BUILD_FAILURES)
ctest_test (BUILD "${CTEST_BINARY_DIRECTORY}" PARALLEL_LEVEL ${PARALLEL_LEVEL} RETURN_VALUE TESTRES)
IF(NOT ${NUMWARN} EQUAL 0 OR NOT ${TESTRES} EQUAL 0)
ctest_submit (RETRY_COUNT 3 RETRY_DELAY 30)
MESSAGE("")
MESSAGE(" ${Yellow}Test results submitted to${ColorReset}")
MESSAGE(" ${BoldYellow}${SHORTURL}${ColorReset}" )
MESSAGE("")
SET(LEVEL "")
IF(NOT ${TESTRES} EQUAL 0)
SET(TESTRES_MESSAGE " Tests failed.")
SET(LEVEL FATAL_ERROR)
ENDIF(NOT ${TESTRES} EQUAL 0)
IF(NOT ${NUMWARN} EQUAL 0)
SET(WARNING_MESSAGE " Build warnings found.")
IF(NOT IGNORE_BUILD_FAILURES)
SET(LEVEL FATAL_ERROR)
ENDIF(NOT IGNORE_BUILD_FAILURES)
ENDIF(NOT ${NUMWARN} EQUAL 0)
MESSAGE( ${LEVEL} " ${Red}${TESTRES_MESSAGE} ${WARNING_MESSAGE}${ColorReset}" )
ENDIF(NOT ${NUMWARN} EQUAL 0 OR NOT ${TESTRES} EQUAL 0)
IF(NOT ${TESTRES} EQUAL 0)
MESSAGE("")
MESSAGE(" ${BoldGreen}Success${ColorReset}")
MESSAGE(" ${Green}All tests passed successfully.${ColorReset}")
MESSAGE("")
ENDIF(NOT ${TESTRES} EQUAL 0)
QGIS Docker images
==================
The QGIS project provides a few official docker images that can be
used for testing purposes.
These dockers are currently used to run continuous integration
tests for the QGIS project itself and to run continuous integration
tests for several third party Python plugins.
The images are automatically built every day and pushed on docker hub
to the QGIS account: https://hub.docker.com/r/qgis/
# Available images
## Dependencies image
`qgis/qgis3-build-deps`
This is a simple base image that contains all the dependencies required to build
QGIS, it is used by the other images.
Multiple versions of this image may be available: the suffix in the image name indicates the Ubuntu version they are based on.
## Main QGIS image
`qgis/qgis`
This is the main image containing a build of QGIS.
The docker tags for this image are assigned for each point release (prefixed with `final-`), for the active development branches (prefixed with `release-`) while the `latest` tag refers to a build of the current master branch.
### Features
The docker file builds QGIS from the current directory and
sets up a testing environment suitable for running tests
inside QGIS.
You can use this docker image to test QGIS and/or to run unit tests inside
QGIS, `xvfb` (A fake X server) is available and running as a service inside
the container to allow for fully automated headless testing in CI pipelines
such as Travis or Circle-CI.
### Building
You can build the image from the main directory of the QGIS source tree with:
```
$ docker build -t qgis/qgis:latest \
--build-arg DOCKER_TAG=latest \
-f .docker/qgis.dockerfile \
.
```
The `DOCKER_TAG` argument, can be used to specify the tag of the dependencies image.
### Running QGIS
You can also use this image to run QGIS on your desktop.
To run a QGIS container, assuming that you want to use your current
display to use QGIS and the image is tagged `qgis/qgis:latest` you can use a script like the one here below:
```bash
# Allow connections from any host
$ xhost +
$ docker run --rm -it --name qgis \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
qgis/qgis:latest qgis
```
This code snippet will launch QGIS inside a container and display the
application on your screen.
### Running unit tests inside QGIS
Suppose that you have local directory containing the tests you want to execute into QGIS:
```
/my_tests/travis_tests/
├── __init__.py
└── test_TravisTest.py
```
To run the tests inside the container, you must mount the directory that
contains the tests (e.g. your local directory `/my_tests`) into a volume
that is accessible by the container, see `-v /my_tests/:/tests_directory`
in the example below:
```bash
$ docker run -d --name qgis -v /tmp/.X11-unix:/tmp/.X11-unix \
-v /my_tests/:/tests_directory \
-e DISPLAY=:99 \
qgis/qgis:latest
```
Here is an extract of `test_TravisTest.py`:
```python
# -*- coding: utf-8 -*-
import sys
from qgis.testing import unittest
class TestTest(unittest.TestCase):
def test_passes(self):
self.assertTrue(True)
def run_all():
"""Default function that is called by the runner if nothing else is specified"""
suite = unittest.TestSuite()
suite.addTests(unittest.makeSuite(TestTest, 'test'))
unittest.TextTestRunner(verbosity=3, stream=sys.stdout).run(suite)
```
When done, you can invoke the test runnner by specifying the test
that you want to run, for instance:
```
$ docker exec -it qgis sh -c "cd /tests_directory && qgis_testrunner.sh travis_tests.test_TravisTest.run_fail"
```
The test can be specified by using a dotted notation, similar to Python
import notation, by default the function named `run_all` will be executed
but you can pass another function name as the last item in the dotted syntax:
```bash
# Call the default function "run_all" inside test_TravisTest module
qgis_testrunner.sh travis_tests.test_TravisTest
# Call the function "run_fail" inside test_TravisTest module
qgis_testrunner.sh travis_tests.test_TravisTest.run_fail
```
Please note that in order to make the test script accessible to Python
the calling command must ensure that the tests are in Python path.
Common patterns are:
- change directory to the one containing the tests (like in the examples above)
- add to `PYTHONPATH` the directory containing the tests
#### Running tests for a Python plugin
All the above considerations applies to this case too, however in order
to simulate the installation of the plugin inside QGIS, you'll need to
make an additional step: call `qgis_setup.sh <YourPluginName>` in the
docker container before actually running the tests (see the paragraph
about Running on Travis for a complete example).
The `qgis_setup.sh` script prepares QGIS to run in headless mode and
simulate the plugin installation process:
- creates the QGIS profile folders
- "installs" the plugin by making a symbolic link from the profiles folder to the plugin folder
- installs `startup.py` monkey patches to prevent blocking dialogs
- enables the plugin
Please note that depending on your plugin repository internal directory structure
you may need to adjust (remove and create) the symbolic link created by `qgis_setup.sh`,
this is required in particular if the real plugin code in your repository is contained
in the main directory and not in a subdirectory with the same name of the plugin
internal name (the name in `metadata.txt`).
#### Options for the test runner
The env var `QGIS_EXTRA_OPTIONS` defaults to an empty string and can
contains extra parameters that are passed to QGIS by the test runner.
#### Running on Travis
Here is a simple example for running unit tests of a small QGIS plugin (named *QuickWKT*), assuming that the tests are in `tests/test_Plugin.py` under
the main directory of the QuickWKT plugin:
```yml
services:
- docker
install:
- docker run -d --name qgis-testing-environment -v ${TRAVIS_BUILD_DIR}:/tests_directory -e DISPLAY=:99 qgis/qgis:latest
- sleep 10 # This is required to allow xvfb to start
# Setup qgis and enables the plugin
- docker exec -it qgis-testing-environment sh -c "qgis_setup.sh QuickWKT"
# Additional steps (for example make or paver setup) here
# Fix the symlink created by qgis_setup.sh
- docker exec -it qgis-testing-environment sh -c "rm -f /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/QuickWKT"
- docker exec -it qgis-testing-environment sh -c "ln -s /tests_directory/ /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/QuickWKT"
script:
- docker exec -it qgis-testing-environment sh -c "cd /tests_directory && qgis_testrunner.sh tests.test_Plugin"
```
Please note that `cd /tests_directory && ` before the call to `qgis_testrunner.sh` could be avoided here, because QGIS automatically
adds the plugin main directory to Python path.
#### Running on Circle-CI
Here is an example for running unit tests of a small QGIS plugin (named *QuickWKT*), assuming
that the tests are in `tests/test_Plugin.py` under the main directory of the QuickWKT plugin:
```yml
version: 2
jobs:
build:
docker:
- image: qgis/qgis:latest
environment:
DISPLAY: ":99"
working_directory: /tests_directory
steps:
- checkout
- run:
name: Setup plugin
command: |
qgis_setup.sh QuickWKT
- run:
name: Fix installation path created by qgis_setup.s
command: |
rm -f /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/QuickWKT
ln -s /tests_directory/ /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/qgisce
- run:
name: run tests
command: |
sh -c "/usr/bin/Xvfb :99 -screen 0 1024x768x24 -ac +extension GLX +render -noreset -nolisten tcp &"
qgis_testrunner.sh tests.test_Plugin
```
#### Implementation notes
The main goal of the test runner in this image is to execute unit tests
inside a real instance of QGIS (not a mocked one).
The QGIS tests should be runnable from a Travis/Circle-CI CI job.
The implementation is:
- run the docker, mounting as volumes the unit tests folder in `/tests_directory`
(or the QGIS plugin folder if the unit tests belong to a plugin and the
plugin is needed to run the tests)
- execute `qgis_setup.sh MyPluginName` script in docker that sets up QGIS to
avoid blocking modal dialogs and installs the plugin into QGIS if needed
- create config and python plugin folders for QGIS
- enable the plugin in the QGIS configuration file
- install the `startup.py` script to disable python exception modal dialogs
- execute the tests by running `qgis_testrunner.sh MyPluginName.tests.tests_MyTestModule.run_my_tests_function`
- the output of the tests is captured by the `test_runner.sh` script and
searched for `FAILED` (that is in the standard unit tests output) and other
string that indicate a failure or success condition, if a failure condition
is identified, the script exits with `1` otherwise it exits with `0`.
`qgis_testrunner.sh` accepts a dotted notation path to the test module that
can end with the function that has to be called inside the module to run the
tests. The last part (`.run_my_tests_function`) can be omitted and defaults to
`run_all`.
version: '3'
services:
postgres:
image: kartoza/postgis:9.5-2.2
environment:
- ALLOW_IP_RANGE="172.18.0.0/16"
mssql:
image: microsoft/mssql-server-linux:2017-latest
environment:
ACCEPT_EULA: Y
SA_PASSWORD: <YourStrong!Passw0rd>
qgis-deps:
tty: true
image: qgis/qgis3-build-deps:${DOCKER_TAG}
volumes:
- ${TRAVIS_BUILD_DIR}:/root/QGIS
- ${CCACHE_DIR}:/root/.ccache # if changed, also change env var
links:
- postgres
- mssql
environment:
- CCACHE_DIR=/root/.ccache
- CTEST_BUILD_DIR=/root/QGIS
- TRAVIS_BRANCH=${TRAVIS_BRANCH}
- TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST}
- TRAVIS_PULL_REQUEST_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH}
- TRAVIS_COMMIT_RANGE=${TRAVIS_COMMIT_RANGE}
- TRAVIS_OS_NAME=${TRAVIS_OS_NAME}
- TRAVIS_CONFIG=${TRAVIS_CONFIG}
- TRAVIS=${TRAVIS}
- TRAVIS_TIMESTAMP=${TRAVIS_TIMESTAMP}
- QGIS_DISABLE_MESSAGE_HOOKS=1
- QGIS_NO_OVERRIDE_IMPORT=1