opj_mj2_extract: Avoid segfault for long filenames
[openjpeg.git] / tools / travis-ci / run.sh
index d04d74f9ec8bb607b527aa344653522fb4146e19..97f5f7122f478f59d86b992daf98231ad6a15b1b 100755 (executable)
@@ -8,13 +8,8 @@ case ${MACHTYPE} in
        *) ;;
 esac
 
-if [ "${OPJ_CI_IS_CYGWIN:-}" == "1" ]; then
-       # Hack for appveyor
-       if ! which wget; then
-               # PATH is not yet set up
-               export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
-       fi
-fi
+# Hack for appveyor to get GNU find in path before windows one.
+export PATH=$(dirname ${BASH}):$PATH
 
 # Set-up some bash options
 set -o nounset   ## set -u : exit the script if you try to use an uninitialised variable
@@ -35,6 +30,16 @@ if [ "${OPJ_CI_ABI_CHECK:-}" == "1" ]; then
        exit 0
 fi
 
+if [ "${OPJ_CI_CC:-}" != "" ]; then
+    export CC=${OPJ_CI_CC}
+    echo "Using ${CC}"
+fi
+
+if [ "${OPJ_CI_CXX:-}" != "" ]; then
+    export CXX=${OPJ_CI_CXX}
+    echo "Using ${CXX}"
+fi
+
 # Set-up some variables
 if [ "${OPJ_CI_BUILD_CONFIGURATION:-}" == "" ]; then
        export OPJ_CI_BUILD_CONFIGURATION=Release #default
@@ -50,6 +55,12 @@ if [ "${TRAVIS_REPO_SLUG:-}" != "" ]; then
        if [ "${OPJ_OWNER}" == "uclouvain" ]; then
                OPJ_DO_SUBMIT=1
        fi
+elif [ "${APPVEYOR_REPO_NAME:-}" != "" ]; then
+       OPJ_OWNER=$(echo "${APPVEYOR_REPO_NAME}" | sed 's/\(^.*\)\/.*/\1/')
+       OPJ_SITE="${OPJ_OWNER}.appveyor.com"
+       if [ "${OPJ_OWNER}" == "uclouvain" ]; then
+               OPJ_DO_SUBMIT=1
+       fi
 else
        OPJ_SITE="$(hostname)"
 fi
@@ -67,7 +78,9 @@ if [ "${TRAVIS_OS_NAME:-}" == "" ]; then
                fi
        elif uname -s | grep -i CYGWIN &> /dev/null; then
                TRAVIS_OS_NAME=windows
-       elif uname -s | grep -i MINGW32 &> /dev/null; then
+       elif uname -s | grep -i MINGW &> /dev/null; then
+               TRAVIS_OS_NAME=windows
+       elif [ "${APPVEYOR:-}" == "True" ]; then
                TRAVIS_OS_NAME=windows
        else
                echo "Failed to guess OS"; exit 1
@@ -98,9 +111,46 @@ elif [ "${TRAVIS_OS_NAME}" == "linux" ]; then
        else
                echo "Compiler not supported: ${CC}"; exit 1
        fi
+       if [ "${OPJ_CI_INSTRUCTION_SETS-:}" == "-mavx2" ]; then
+               AVX2_AVAIL=1
+               cat /proc/cpuinfo | grep avx2 >/dev/null || AVX2_AVAIL=0
+               if [[ "${AVX2_AVAIL}" == "1" ]]; then
+                       echo "AVX2 available on CPU"
+               else
+                       echo "AVX2 not available on CPU. Disabling tests"
+                       cat /proc/cpuinfo  | grep flags | head -n 1
+                       export OPJ_CI_SKIP_TESTS=1
+               fi
+        fi
 elif [ "${TRAVIS_OS_NAME}" == "windows" ]; then
        OPJ_OS_NAME=windows
-       OPJ_CC_VERSION=vs2015
+       if which cl > /dev/null; then
+               OPJ_CL_VERSION=$(cl 2>&1 | grep Version | sed 's/.*Version \([0-9]*\).*/\1/')
+               if [ ${OPJ_CL_VERSION} -eq 19 ]; then
+                       OPJ_CC_VERSION=vs2015
+               elif [ ${OPJ_CL_VERSION} -eq 18 ]; then
+                       OPJ_CC_VERSION=vs2013
+               elif [ ${OPJ_CL_VERSION} -eq 17 ]; then
+                       OPJ_CC_VERSION=vs2012
+               elif [ ${OPJ_CL_VERSION} -eq 16 ]; then
+                       OPJ_CC_VERSION=vs2010
+               elif [ ${OPJ_CL_VERSION} -eq 15 ]; then
+                       OPJ_CC_VERSION=vs2008
+               elif [ ${OPJ_CL_VERSION} -eq 14 ]; then
+                       OPJ_CC_VERSION=vs2005
+               else
+                       OPJ_CC_VERSION=vs????
+               fi
+       fi
+       if [ "${OPJ_CI_INSTRUCTION_SETS-:}" == "/arch:AVX2" ]; then
+               cl $PWD/tools/travis-ci/detect-avx2.c
+               if ./detect-avx2.exe; then
+                       echo "AVX2 available on CPU"
+               else
+                       echo "AVX2 not available on CPU. Disabling tests"
+                       export OPJ_CI_SKIP_TESTS=1
+               fi
+       fi
 else
        echo "OS not supported: ${TRAVIS_OS_NAME}"; exit 1
 fi
@@ -156,17 +206,61 @@ set -x
 # travis-ci doesn't dump cmake version in system info, let's print it 
 cmake --version
 
+export TRAVIS_OS_NAME=${TRAVIS_OS_NAME}
 export OPJ_SITE=${OPJ_SITE}
 export OPJ_BUILDNAME=${OPJ_BUILDNAME}
 export OPJ_SOURCE_DIR=$(opjpath -m ${OPJ_SOURCE_DIR})
+export OPJ_BINARY_DIR=$(opjpath -m ${PWD}/build)
 export OPJ_BUILD_CONFIGURATION=${OPJ_CI_BUILD_CONFIGURATION}
 export OPJ_DO_SUBMIT=${OPJ_DO_SUBMIT}
 
-ctest -S ${OPJ_SOURCE_DIR}/tools/ctest_scripts/travis-ci.cmake -V || true
+if [ "${OPJ_SKIP_REBUILD:-}" != "1" ]; then
+    ctest -S ${OPJ_SOURCE_DIR}/tools/ctest_scripts/travis-ci.cmake -V || true
+fi
 # ctest will exit with various error codes depending on version.
 # ignore ctest exit code & parse this ourselves
 set +x
 
+
+
+if [ "${OPJ_CI_CHECK_STYLE:-}" == "1" ]; then
+    export OPJSTYLE=${PWD}/scripts/opjstyle
+    export PATH=${HOME}/.local/bin:${PATH}
+    scripts/verify-indentation.sh
+fi
+
+
+# Deployment if needed
+#---------------------
+if [ "${TRAVIS_TAG:-}" != "" ]; then
+               OPJ_TAG_NAME=${TRAVIS_TAG}
+       elif [ "${APPVEYOR_REPO_TAG:-}" == "true" ]; then
+               OPJ_TAG_NAME=${APPVEYOR_REPO_TAG_NAME}
+       else
+               OPJ_TAG_NAME=""
+       fi
+if [ "${OPJ_CI_INCLUDE_IF_DEPLOY:-}" == "1" ] && [ "${OPJ_TAG_NAME:-}" != "" ]; then
+#if [ "${OPJ_CI_INCLUDE_IF_DEPLOY:-}" == "1" ]; then
+       OPJ_CI_DEPLOY=1         # unused for now
+       OPJ_CUR_DIR=${PWD}
+       if [ "${TRAVIS_OS_NAME:-}" == "linux" ]; then
+               OPJ_PACK_GENERATOR="TGZ" # ZIP generator currently segfaults on linux
+       else
+               OPJ_PACK_GENERATOR="ZIP"
+       fi
+       OPJ_PACK_NAME="openjpeg-${OPJ_TAG_NAME}-${TRAVIS_OS_NAME}-${OPJ_CI_ARCH}"
+       cd ${OPJ_BINARY_DIR}
+       cmake -D CPACK_GENERATOR:STRING=${OPJ_PACK_GENERATOR} -D CPACK_PACKAGE_FILE_NAME:STRING=${OPJ_PACK_NAME} ${OPJ_SOURCE_DIR}
+       cd ${OPJ_CUR_DIR}
+       cmake --build ${OPJ_BINARY_DIR} --target package
+       echo "ready to deploy $(ls ${OPJ_BINARY_DIR}/${OPJ_PACK_NAME}*) to GitHub releases"
+       if [ "${APPVEYOR_REPO_TAG:-}" == "true" ]; then
+               appveyor PushArtifact "${OPJ_BINARY_DIR}/${OPJ_PACK_NAME}.zip"
+       fi
+else
+       OPJ_CI_DEPLOY=0
+fi
+
 # let's parse configure/build/tests for failure
 
 echo "
@@ -250,4 +344,70 @@ New/unknown test failure found!!!
        fi
 fi
 
+if [ "${OPJ_CI_BUILD_FUZZERS:-}" == "1" ]; then
+    cd tests/fuzzers
+    make
+    cd ../..
+fi
+
+if [ "${OPJ_CI_PERF_TESTS:-}" == "1" ]; then
+    cd tests/performance
+    echo "Running performance tests on current version (dry-run)"
+    PATH=../../build/bin:$PATH python ./perf_test.py
+    echo "Running performance tests on current version"
+    PATH=../../build/bin:$PATH python ./perf_test.py -o /tmp/new.csv
+    if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ] && [ -d ../../kdu ]; then
+        echo "Running performances tests with Kakadu"
+        LD_LIBRARY_PATH=../../kdu PATH=../../kdu::$PATH python ./perf_test.py -kakadu -o /tmp/kakadu.csv
+        echo "Comparing current version with Kakadu"
+        python compare_perfs.py /tmp/kakadu.csv /tmp/new.csv || true
+    fi
+    cd ../..
+
+    REF_VERSION=master
+    if [ "${TRAVIS_PULL_REQUEST:-false}" == "false" ]; then
+        REF_VERSION=v2.1.2
+    fi
+    if [ ! -d ref_opj ]; then
+        git clone https://github.com/uclouvain/openjpeg ref_opj
+    fi
+    echo "Building reference version (${REF_VERSION})"
+    cd ref_opj
+    git checkout ${REF_VERSION}
+    mkdir -p build
+    cd build
+    cmake .. -DCMAKE_BUILD_TYPE=${OPJ_BUILD_CONFIGURATION}
+    make -j3
+    cd ../..
+    cd tests/performance
+    echo "Running performance tests on ${REF_VERSION} version (dry-run)"
+    PATH=../../ref_opj/build/bin:$PATH python ./perf_test.py
+    echo "Running performance tests on ${REF_VERSION} version"
+    PATH=../../ref_opj/build/bin:$PATH python ./perf_test.py -o /tmp/ref.csv
+    echo "Comparing current version with ${REF_VERSION} version"
+    # we should normally set OPJ_CI_RESULT=1 in case of failure, but
+    # this is too unreliable
+    python compare_perfs.py /tmp/ref.csv /tmp/new.csv || true
+    cd ../..
+fi
+
+if [ "${OPJ_CI_PROFILE:-}" == "1" ]; then
+    rm -rf build_gprof
+    mkdir build_gprof
+    cd build_gprof
+    # We need static linking for gprof
+    cmake "-DCMAKE_C_FLAGS=-pg -O3" -DCMAKE_EXE_LINKER_FLAGS=-pg -DCMAKE_SHARED_LINKER_FLAGS=-pg -DBUILD_SHARED_LIBS=OFF ..
+    make -j3
+    cd ..
+    build_gprof/bin/opj_decompress -i data/input/nonregression/kodak_2layers_lrcp.j2c -o out.tif > /dev/null
+    echo "Most CPU consuming functions:"
+    gprof build_gprof/bin/opj_decompress gmon.out | head || true
+
+    rm -f massif.out.*
+    valgrind --tool=massif build/bin/opj_decompress -i data/input/nonregression/kodak_2layers_lrcp.j2c -o out.tif >/dev/null 2>/dev/null
+    echo ""
+    echo "Memory consumption profile:"
+    python tests/profiling/filter_massif_output.py massif.out.*
+fi
+
 exit ${OPJ_CI_RESULT}