3 # This script executes the script step when running under travis-ci
7 *cygwin*) OPJ_CI_IS_CYGWIN=1;;
11 # Hack for appveyor to get GNU find in path before windows one.
12 export PATH=$(dirname ${BASH}):$PATH
14 # Set-up some bash options
15 set -o nounset ## set -u : exit the script if you try to use an uninitialised variable
16 set -o errexit ## set -e : exit the script if any statement returns a non-true return value
17 set -o pipefail ## Fail on error in pipe
21 if [ "${OPJ_CI_IS_CYGWIN:-}" == "1" ]; then
28 # ABI check is done by abi-check.sh
29 if [ "${OPJ_CI_ABI_CHECK:-}" == "1" ]; then
33 if [ "${OPJ_CI_CC:-}" != "" ]; then
34 export CC=${OPJ_CI_CC}
38 if [ "${OPJ_CI_CXX:-}" != "" ]; then
39 export CXX=${OPJ_CI_CXX}
43 # Set-up some variables
44 if [ "${OPJ_CI_BUILD_CONFIGURATION:-}" == "" ]; then
45 export OPJ_CI_BUILD_CONFIGURATION=Release #default
47 OPJ_SOURCE_DIR=$(cd $(dirname $0)/../.. && pwd)
49 if [ "${OPJ_DO_SUBMIT:-}" == "" ]; then
50 OPJ_DO_SUBMIT=0 # Do not flood cdash by default
52 if [ "${TRAVIS_REPO_SLUG:-}" != "" ]; then
53 OPJ_OWNER=$(echo "${TRAVIS_REPO_SLUG}" | sed 's/\(^.*\)\/.*/\1/')
54 OPJ_SITE="${OPJ_OWNER}.travis-ci.org"
55 if [ "${OPJ_OWNER}" == "uclouvain" ]; then
58 elif [ "${APPVEYOR_REPO_NAME:-}" != "" ]; then
59 OPJ_OWNER=$(echo "${APPVEYOR_REPO_NAME}" | sed 's/\(^.*\)\/.*/\1/')
60 OPJ_SITE="${OPJ_OWNER}.appveyor.com"
61 if [ "${OPJ_OWNER}" == "uclouvain" ]; then
65 OPJ_SITE="$(hostname)"
68 if [ "${TRAVIS_OS_NAME:-}" == "" ]; then
69 # Let's guess OS for testing purposes
71 if uname -s | grep -i Darwin &> /dev/null; then
73 elif uname -s | grep -i Linux &> /dev/null; then
75 if [ "${CC:-}" == "" ]; then
79 elif uname -s | grep -i CYGWIN &> /dev/null; then
80 TRAVIS_OS_NAME=windows
81 elif uname -s | grep -i MINGW &> /dev/null; then
82 TRAVIS_OS_NAME=windows
83 elif [ "${APPVEYOR:-}" == "True" ]; then
84 TRAVIS_OS_NAME=windows
86 echo "Failed to guess OS"; exit 1
88 echo "${TRAVIS_OS_NAME}"
91 if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
92 OPJ_OS_NAME=$(sw_vers -productName | tr -d ' ')$(sw_vers -productVersion | sed 's/\([^0-9]*\.[0-9]*\).*/\1/')
93 OPJ_CC_VERSION=$(xcodebuild -version | grep -i xcode)
94 OPJ_CC_VERSION=xcode${OPJ_CC_VERSION:6}
95 elif [ "${TRAVIS_OS_NAME}" == "linux" ]; then
97 if which lsb_release > /dev/null; then
98 OPJ_OS_NAME=$(lsb_release -si)$(lsb_release -sr | sed 's/\([^0-9]*\.[0-9]*\).*/\1/')
100 if [ -z "${CC##*gcc*}" ]; then
101 OPJ_CC_VERSION=$(${CC} --version | head -1 | sed 's/.*\ \([0-9.]*[0-9]\)/\1/')
102 if [ -z "${CC##*mingw*}" ]; then
103 OPJ_CC_VERSION=mingw${OPJ_CC_VERSION}
104 # disable testing for now
105 export OPJ_CI_SKIP_TESTS=1
107 OPJ_CC_VERSION=gcc${OPJ_CC_VERSION}
109 elif [ -z "${CC##*clang*}" ]; then
110 OPJ_CC_VERSION=clang$(${CC} --version | grep version | sed 's/.*version \([^0-9.]*[0-9.]*\).*/\1/')
112 echo "Compiler not supported: ${CC}"; exit 1
114 if [ "${OPJ_CI_INSTRUCTION_SETS-:}" == "-mavx2" ]; then
116 cat /proc/cpuinfo | grep avx2 >/dev/null || AVX2_AVAIL=0
117 if [[ "${AVX2_AVAIL}" == "1" ]]; then
118 echo "AVX2 available on CPU"
120 echo "AVX2 not available on CPU. Disabling tests"
121 cat /proc/cpuinfo | grep flags | head -n 1
122 export OPJ_CI_SKIP_TESTS=1
125 elif [ "${TRAVIS_OS_NAME}" == "windows" ]; then
127 if which cl > /dev/null; then
128 OPJ_CL_VERSION=$(cl 2>&1 | grep Version | sed 's/.*Version \([0-9]*\).*/\1/')
129 if [ ${OPJ_CL_VERSION} -eq 19 ]; then
130 OPJ_CC_VERSION=vs2015
131 elif [ ${OPJ_CL_VERSION} -eq 18 ]; then
132 OPJ_CC_VERSION=vs2013
133 elif [ ${OPJ_CL_VERSION} -eq 17 ]; then
134 OPJ_CC_VERSION=vs2012
135 elif [ ${OPJ_CL_VERSION} -eq 16 ]; then
136 OPJ_CC_VERSION=vs2010
137 elif [ ${OPJ_CL_VERSION} -eq 15 ]; then
138 OPJ_CC_VERSION=vs2008
139 elif [ ${OPJ_CL_VERSION} -eq 14 ]; then
140 OPJ_CC_VERSION=vs2005
142 OPJ_CC_VERSION=vs????
145 if [ "${OPJ_CI_INSTRUCTION_SETS-:}" == "/arch:AVX2" ]; then
146 cl $PWD/tools/travis-ci/detect-avx2.c
147 if ./detect-avx2.exe; then
148 echo "AVX2 available on CPU"
150 echo "AVX2 not available on CPU. Disabling tests"
151 export OPJ_CI_SKIP_TESTS=1
155 echo "OS not supported: ${TRAVIS_OS_NAME}"; exit 1
158 if [ "${OPJ_CI_ARCH:-}" == "" ]; then
159 echo "Guessing build architecture"
160 MACHINE_ARCH=$(uname -m)
161 if [ "${MACHINE_ARCH}" == "x86_64" ]; then
162 export OPJ_CI_ARCH=x86_64
164 echo "${OPJ_CI_ARCH}"
167 if [ "${TRAVIS_BRANCH:-}" == "" ]; then
168 if [ "${APPVEYOR_REPO_BRANCH:-}" != "" ]; then
169 TRAVIS_BRANCH=${APPVEYOR_REPO_BRANCH}
171 echo "Guessing branch"
172 TRAVIS_BRANCH=$(git -C ${OPJ_SOURCE_DIR} branch | grep '*' | tr -d '*[[:blank:]]')
176 OPJ_BUILDNAME=${OPJ_OS_NAME}-${OPJ_CC_VERSION}-${OPJ_CI_ARCH}-${TRAVIS_BRANCH}
177 OPJ_BUILDNAME_TEST=${OPJ_OS_NAME}-${OPJ_CC_VERSION}-${OPJ_CI_ARCH}
178 if [ "${TRAVIS_PULL_REQUEST:-}" != "false" ] && [ "${TRAVIS_PULL_REQUEST:-}" != "" ]; then
179 OPJ_BUILDNAME=${OPJ_BUILDNAME}-pr${TRAVIS_PULL_REQUEST}
180 elif [ "${APPVEYOR_PULL_REQUEST_NUMBER:-}" != "" ]; then
181 OPJ_BUILDNAME=${OPJ_BUILDNAME}-pr${APPVEYOR_PULL_REQUEST_NUMBER}
183 OPJ_BUILDNAME=${OPJ_BUILDNAME}-${OPJ_CI_BUILD_CONFIGURATION}-3rdP
184 OPJ_BUILDNAME_TEST=${OPJ_BUILDNAME_TEST}-${OPJ_CI_BUILD_CONFIGURATION}-3rdP
185 if [ "${OPJ_CI_ASAN:-}" == "1" ]; then
186 OPJ_BUILDNAME=${OPJ_BUILDNAME}-ASan
187 OPJ_BUILDNAME_TEST=${OPJ_BUILDNAME_TEST}-ASan
190 if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ] && [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ] && [ -d kdu ]; then
192 Testing will use Kakadu trial binaries. Here's the copyright notice from kakadu:
193 Copyright is owned by NewSouth Innovations Pty Limited, commercial arm of the UNSW Australia in Sydney.
194 You are free to trial these executables and even to re-distribute them,
195 so long as such use or re-distribution is accompanied with this copyright notice and is not for commercial gain.
196 Note: Binaries can only be used for non-commercial purposes.
200 if [ -d cmake-install ]; then
201 export PATH=${PWD}/cmake-install/bin:${PATH}
205 # This will print configuration
206 # travis-ci doesn't dump cmake version in system info, let's print it
209 export TRAVIS_OS_NAME=${TRAVIS_OS_NAME}
210 export OPJ_SITE=${OPJ_SITE}
211 export OPJ_BUILDNAME=${OPJ_BUILDNAME}
212 export OPJ_SOURCE_DIR=$(opjpath -m ${OPJ_SOURCE_DIR})
213 export OPJ_BINARY_DIR=$(opjpath -m ${PWD}/build)
214 export OPJ_BUILD_CONFIGURATION=${OPJ_CI_BUILD_CONFIGURATION}
215 export OPJ_DO_SUBMIT=${OPJ_DO_SUBMIT}
217 if [ "${OPJ_SKIP_REBUILD:-}" != "1" ]; then
218 ctest -S ${OPJ_SOURCE_DIR}/tools/ctest_scripts/travis-ci.cmake -V || true
220 # ctest will exit with various error codes depending on version.
221 # ignore ctest exit code & parse this ourselves
226 if [ "${OPJ_CI_CHECK_STYLE:-}" == "1" ]; then
227 export OPJSTYLE=${PWD}/scripts/opjstyle
228 export PATH=${HOME}/.local/bin:${PATH}
229 scripts/verify-indentation.sh
233 # Deployment if needed
234 #---------------------
235 if [ "${TRAVIS_TAG:-}" != "" ]; then
236 OPJ_TAG_NAME=${TRAVIS_TAG}
237 elif [ "${APPVEYOR_REPO_TAG:-}" == "true" ]; then
238 OPJ_TAG_NAME=${APPVEYOR_REPO_TAG_NAME}
242 if [ "${OPJ_CI_INCLUDE_IF_DEPLOY:-}" == "1" ] && [ "${OPJ_TAG_NAME:-}" != "" ]; then
243 #if [ "${OPJ_CI_INCLUDE_IF_DEPLOY:-}" == "1" ]; then
244 OPJ_CI_DEPLOY=1 # unused for now
246 if [ "${TRAVIS_OS_NAME:-}" == "linux" ]; then
247 OPJ_PACK_GENERATOR="TGZ" # ZIP generator currently segfaults on linux
249 OPJ_PACK_GENERATOR="ZIP"
251 OPJ_PACK_NAME="openjpeg-${OPJ_TAG_NAME}-${TRAVIS_OS_NAME}-${OPJ_CI_ARCH}"
253 cmake -D CPACK_GENERATOR:STRING=${OPJ_PACK_GENERATOR} -D CPACK_PACKAGE_FILE_NAME:STRING=${OPJ_PACK_NAME} ${OPJ_SOURCE_DIR}
255 cmake --build ${OPJ_BINARY_DIR} --target package
256 echo "ready to deploy $(ls ${OPJ_BINARY_DIR}/${OPJ_PACK_NAME}*) to GitHub releases"
257 if [ "${APPVEYOR_REPO_TAG:-}" == "true" ]; then
258 appveyor PushArtifact "${OPJ_BINARY_DIR}/${OPJ_PACK_NAME}.zip"
264 # let's parse configure/build/tests for failure
267 Parsing logs for failures
272 OPJ_CONFIGURE_XML=$(find build -path 'build/Testing/*' -name 'Configure.xml')
273 if [ ! -f "${OPJ_CONFIGURE_XML}" ]; then
274 echo "No configure log found"
277 if ! grep '<ConfigureStatus>0</ConfigureStatus>' ${OPJ_CONFIGURE_XML} &> /dev/null; then
278 echo "Errors were found in configure log"
284 # We must have one Build.xml file
285 OPJ_BUILD_XML=$(find build -path 'build/Testing/*' -name 'Build.xml')
286 if [ ! -f "${OPJ_BUILD_XML}" ]; then
287 echo "No build log found"
290 if grep '<Error>' ${OPJ_BUILD_XML} &> /dev/null; then
291 echo "Errors were found in build log"
296 if [ ${OPJ_CI_RESULT} -ne 0 ]; then
297 # Don't trash output with failing tests when there are configure/build errors
298 exit ${OPJ_CI_RESULT}
301 if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then
302 OPJ_TEST_XML=$(find build -path 'build/Testing/*' -name 'Test.xml')
303 if [ ! -f "${OPJ_TEST_XML}" ]; then
304 echo "No test log found"
307 echo "Parsing tests for new/unknown failures"
309 OPJ_FAILEDTEST_LOG=$(find build -path 'build/Testing/Temporary/*' -name 'LastTestsFailed_*.log')
310 if [ -f "${OPJ_FAILEDTEST_LOG}" ]; then
311 awk -F: '{ print $2 }' ${OPJ_FAILEDTEST_LOG} > failures.txt
312 while read FAILEDTEST; do
313 # Start with common errors
314 if grep -x "${FAILEDTEST}" $(opjpath -u ${OPJ_SOURCE_DIR})/tools/travis-ci/knownfailures-all.txt > /dev/null; then
317 if [ -f $(opjpath -u ${OPJ_SOURCE_DIR})/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt ]; then
318 if grep -x "${FAILEDTEST}" $(opjpath -u ${OPJ_SOURCE_DIR})/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt > /dev/null; then
328 if [ ${OPJ_CI_RESULT} -eq 0 ]; then
329 echo "No new/unknown test failure found
333 New/unknown test failure found!!!
338 OPJ_MEMCHECK_XML=$(find build -path 'build/Testing/*' -name 'DynamicAnalysis.xml')
339 if [ -f "${OPJ_MEMCHECK_XML}" ]; then
340 if grep '<Defect Type' ${OPJ_MEMCHECK_XML} 2> /dev/null; then
341 echo "Errors were found in dynamic analysis log"
347 if [ "${OPJ_CI_PERF_TESTS:-}" == "1" ]; then
349 echo "Running performance tests on current version (dry-run)"
350 PATH=../../build/bin:$PATH python ./perf_test.py
351 echo "Running performance tests on current version"
352 PATH=../../build/bin:$PATH python ./perf_test.py -o /tmp/new.csv
353 if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ] && [ -d ../../kdu ]; then
354 echo "Running performances tests with Kakadu"
355 LD_LIBRARY_PATH=../../kdu PATH=../../kdu::$PATH python ./perf_test.py -kakadu -o /tmp/kakadu.csv
356 echo "Comparing current version with Kakadu"
357 python compare_perfs.py /tmp/kakadu.csv /tmp/new.csv || true
362 if [ "${TRAVIS_PULL_REQUEST:-false}" == "false" ]; then
365 if [ ! -d ref_opj ]; then
366 git clone https://github.com/uclouvain/openjpeg ref_opj
368 echo "Building reference version (${REF_VERSION})"
370 git checkout ${REF_VERSION}
373 cmake .. -DCMAKE_BUILD_TYPE=${OPJ_BUILD_CONFIGURATION}
377 echo "Running performance tests on ${REF_VERSION} version (dry-run)"
378 PATH=../../ref_opj/build/bin:$PATH python ./perf_test.py
379 echo "Running performance tests on ${REF_VERSION} version"
380 PATH=../../ref_opj/build/bin:$PATH python ./perf_test.py -o /tmp/ref.csv
381 echo "Comparing current version with ${REF_VERSION} version"
382 # we should normally set OPJ_CI_RESULT=1 in case of failure, but
383 # this is too unreliable
384 python compare_perfs.py /tmp/ref.csv /tmp/new.csv || true
388 if [ "${OPJ_CI_PROFILE:-}" == "1" ]; then
392 # We need static linking for gprof
393 cmake "-DCMAKE_C_FLAGS=-pg -O3" -DCMAKE_EXE_LINKER_FLAGS=-pg -DCMAKE_SHARED_LINKER_FLAGS=-pg -DBUILD_SHARED_LIBS=OFF ..
396 build_gprof/bin/opj_decompress -i data/input/nonregression/kodak_2layers_lrcp.j2c -o out.tif > /dev/null
397 echo "Most CPU consuming functions:"
398 gprof build_gprof/bin/opj_decompress gmon.out | head || true
401 valgrind --tool=massif build/bin/opj_decompress -i data/input/nonregression/kodak_2layers_lrcp.j2c -o out.tif >/dev/null 2>/dev/null
403 echo "Memory consumption profile:"
404 python tests/profiling/filter_massif_output.py massif.out.*
407 exit ${OPJ_CI_RESULT}