run.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. #!/bin/bash
  2. # This script executes the script step when running under travis-ci
  3. #if cygwin, check path
  4. case ${MACHTYPE} in
  5. *cygwin*) OPJ_CI_IS_CYGWIN=1;;
  6. *) ;;
  7. esac
  8. # Hack for appveyor to get GNU find in path before windows one.
  9. export PATH=$(dirname ${BASH}):$PATH
  10. # Set-up some bash options
  11. set -o nounset ## set -u : exit the script if you try to use an uninitialised variable
  12. set -o errexit ## set -e : exit the script if any statement returns a non-true return value
  13. set -o pipefail ## Fail on error in pipe
  14. function opjpath ()
  15. {
  16. if [ "${OPJ_CI_IS_CYGWIN:-}" == "1" ]; then
  17. cygpath $1 "$2"
  18. else
  19. echo "$2"
  20. fi
  21. }
  22. # ABI check is done by abi-check.sh
  23. if [ "${OPJ_CI_ABI_CHECK:-}" == "1" ]; then
  24. exit 0
  25. fi
  26. if [ "${OPJ_CI_CC:-}" != "" ]; then
  27. export CC=${OPJ_CI_CC}
  28. echo "Using ${CC}"
  29. fi
  30. if [ "${OPJ_CI_CXX:-}" != "" ]; then
  31. export CXX=${OPJ_CI_CXX}
  32. echo "Using ${CXX}"
  33. fi
  34. # Set-up some variables
  35. if [ "${OPJ_CI_BUILD_CONFIGURATION:-}" == "" ]; then
  36. export OPJ_CI_BUILD_CONFIGURATION=Release #default
  37. fi
  38. OPJ_SOURCE_DIR=$(cd $(dirname $0)/../.. && pwd)
  39. if [ "${OPJ_DO_SUBMIT:-}" == "" ]; then
  40. OPJ_DO_SUBMIT=0 # Do not flood cdash by default
  41. fi
  42. if [ "${TRAVIS_REPO_SLUG:-}" != "" ]; then
  43. OPJ_OWNER=$(echo "${TRAVIS_REPO_SLUG}" | sed 's/\(^.*\)\/.*/\1/')
  44. OPJ_SITE="${OPJ_OWNER}.travis-ci.org"
  45. if [ "${OPJ_OWNER}" == "uclouvain" ]; then
  46. OPJ_DO_SUBMIT=1
  47. fi
  48. elif [ "${APPVEYOR_REPO_NAME:-}" != "" ]; then
  49. OPJ_OWNER=$(echo "${APPVEYOR_REPO_NAME}" | sed 's/\(^.*\)\/.*/\1/')
  50. OPJ_SITE="${OPJ_OWNER}.appveyor.com"
  51. if [ "${OPJ_OWNER}" == "uclouvain" ]; then
  52. OPJ_DO_SUBMIT=1
  53. fi
  54. else
  55. OPJ_SITE="$(hostname)"
  56. fi
  57. if [ "${TRAVIS_OS_NAME:-}" == "" ]; then
  58. # Let's guess OS for testing purposes
  59. echo "Guessing OS"
  60. if uname -s | grep -i Darwin &> /dev/null; then
  61. TRAVIS_OS_NAME=osx
  62. elif uname -s | grep -i Linux &> /dev/null; then
  63. TRAVIS_OS_NAME=linux
  64. if [ "${CC:-}" == "" ]; then
  65. # default to gcc
  66. export CC=gcc
  67. fi
  68. elif uname -s | grep -i CYGWIN &> /dev/null; then
  69. TRAVIS_OS_NAME=windows
  70. elif uname -s | grep -i MINGW &> /dev/null; then
  71. TRAVIS_OS_NAME=windows
  72. elif [ "${APPVEYOR:-}" == "True" ]; then
  73. TRAVIS_OS_NAME=windows
  74. else
  75. echo "Failed to guess OS"; exit 1
  76. fi
  77. echo "${TRAVIS_OS_NAME}"
  78. fi
  79. if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
  80. OPJ_OS_NAME=$(sw_vers -productName | tr -d ' ')$(sw_vers -productVersion | sed 's/\([^0-9]*\.[0-9]*\).*/\1/')
  81. OPJ_CC_VERSION=$(xcodebuild -version | grep -i xcode)
  82. OPJ_CC_VERSION=xcode${OPJ_CC_VERSION:6}
  83. elif [ "${TRAVIS_OS_NAME}" == "linux" ]; then
  84. OPJ_OS_NAME=linux
  85. if which lsb_release > /dev/null; then
  86. OPJ_OS_NAME=$(lsb_release -si)$(lsb_release -sr | sed 's/\([^0-9]*\.[0-9]*\).*/\1/')
  87. fi
  88. if [ -z "${CC##*gcc*}" ]; then
  89. OPJ_CC_VERSION=$(${CC} --version | head -1 | sed 's/.*\ \([0-9.]*[0-9]\)/\1/')
  90. if [ -z "${CC##*mingw*}" ]; then
  91. OPJ_CC_VERSION=mingw${OPJ_CC_VERSION}
  92. # disable testing for now
  93. export OPJ_CI_SKIP_TESTS=1
  94. else
  95. OPJ_CC_VERSION=gcc${OPJ_CC_VERSION}
  96. fi
  97. elif [ -z "${CC##*clang*}" ]; then
  98. OPJ_CC_VERSION=clang$(${CC} --version | grep version | sed 's/.*version \([^0-9.]*[0-9.]*\).*/\1/')
  99. else
  100. echo "Compiler not supported: ${CC}"; exit 1
  101. fi
  102. if [ "${OPJ_CI_INSTRUCTION_SETS-:}" == "-mavx2" ]; then
  103. AVX2_AVAIL=1
  104. cat /proc/cpuinfo | grep avx2 >/dev/null || AVX2_AVAIL=0
  105. if [[ "${AVX2_AVAIL}" == "1" ]]; then
  106. echo "AVX2 available on CPU"
  107. else
  108. echo "AVX2 not available on CPU. Disabling tests"
  109. cat /proc/cpuinfo | grep flags | head -n 1
  110. export OPJ_CI_SKIP_TESTS=1
  111. fi
  112. fi
  113. elif [ "${TRAVIS_OS_NAME}" == "windows" ]; then
  114. OPJ_OS_NAME=windows
  115. if which cl > /dev/null; then
  116. OPJ_CL_VERSION=$(cl 2>&1 | grep Version | sed 's/.*Version \([0-9]*\).*/\1/')
  117. if [ ${OPJ_CL_VERSION} -eq 19 ]; then
  118. OPJ_CC_VERSION=vs2015
  119. elif [ ${OPJ_CL_VERSION} -eq 18 ]; then
  120. OPJ_CC_VERSION=vs2013
  121. elif [ ${OPJ_CL_VERSION} -eq 17 ]; then
  122. OPJ_CC_VERSION=vs2012
  123. elif [ ${OPJ_CL_VERSION} -eq 16 ]; then
  124. OPJ_CC_VERSION=vs2010
  125. elif [ ${OPJ_CL_VERSION} -eq 15 ]; then
  126. OPJ_CC_VERSION=vs2008
  127. elif [ ${OPJ_CL_VERSION} -eq 14 ]; then
  128. OPJ_CC_VERSION=vs2005
  129. else
  130. OPJ_CC_VERSION=vs????
  131. fi
  132. fi
  133. if [ "${OPJ_CI_INSTRUCTION_SETS-:}" == "/arch:AVX2" ]; then
  134. cl $PWD/tools/travis-ci/detect-avx2.c
  135. if ./detect-avx2.exe; then
  136. echo "AVX2 available on CPU"
  137. else
  138. echo "AVX2 not available on CPU. Disabling tests"
  139. export OPJ_CI_SKIP_TESTS=1
  140. fi
  141. fi
  142. else
  143. echo "OS not supported: ${TRAVIS_OS_NAME}"; exit 1
  144. fi
  145. if [ "${OPJ_CI_ARCH:-}" == "" ]; then
  146. echo "Guessing build architecture"
  147. MACHINE_ARCH=$(uname -m)
  148. if [ "${MACHINE_ARCH}" == "x86_64" ]; then
  149. export OPJ_CI_ARCH=x86_64
  150. fi
  151. echo "${OPJ_CI_ARCH}"
  152. fi
  153. if [ "${TRAVIS_BRANCH:-}" == "" ]; then
  154. if [ "${APPVEYOR_REPO_BRANCH:-}" != "" ]; then
  155. TRAVIS_BRANCH=${APPVEYOR_REPO_BRANCH}
  156. else
  157. echo "Guessing branch"
  158. TRAVIS_BRANCH=$(git -C ${OPJ_SOURCE_DIR} branch | grep '*' | tr -d '*[[:blank:]]')
  159. fi
  160. fi
  161. OPJ_BUILDNAME=${OPJ_OS_NAME}-${OPJ_CC_VERSION}-${OPJ_CI_ARCH}-${TRAVIS_BRANCH}
  162. OPJ_BUILDNAME_TEST=${OPJ_OS_NAME}-${OPJ_CC_VERSION}-${OPJ_CI_ARCH}
  163. if [ "${TRAVIS_PULL_REQUEST:-}" != "false" ] && [ "${TRAVIS_PULL_REQUEST:-}" != "" ]; then
  164. OPJ_BUILDNAME=${OPJ_BUILDNAME}-pr${TRAVIS_PULL_REQUEST}
  165. elif [ "${APPVEYOR_PULL_REQUEST_NUMBER:-}" != "" ]; then
  166. OPJ_BUILDNAME=${OPJ_BUILDNAME}-pr${APPVEYOR_PULL_REQUEST_NUMBER}
  167. fi
  168. OPJ_BUILDNAME=${OPJ_BUILDNAME}-${OPJ_CI_BUILD_CONFIGURATION}-3rdP
  169. OPJ_BUILDNAME_TEST=${OPJ_BUILDNAME_TEST}-${OPJ_CI_BUILD_CONFIGURATION}-3rdP
  170. if [ "${OPJ_CI_ASAN:-}" == "1" ]; then
  171. OPJ_BUILDNAME=${OPJ_BUILDNAME}-ASan
  172. OPJ_BUILDNAME_TEST=${OPJ_BUILDNAME_TEST}-ASan
  173. fi
  174. if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ] && [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ] && [ -d kdu ]; then
  175. echo "
  176. Testing will use Kakadu trial binaries. Here's the copyright notice from kakadu:
  177. Copyright is owned by NewSouth Innovations Pty Limited, commercial arm of the UNSW Australia in Sydney.
  178. You are free to trial these executables and even to re-distribute them,
  179. so long as such use or re-distribution is accompanied with this copyright notice and is not for commercial gain.
  180. Note: Binaries can only be used for non-commercial purposes.
  181. "
  182. fi
  183. if [ -d cmake-install ]; then
  184. export PATH=${PWD}/cmake-install/bin:${PATH}
  185. fi
  186. set -x
  187. # This will print configuration
  188. # travis-ci doesn't dump cmake version in system info, let's print it
  189. cmake --version
  190. export TRAVIS_OS_NAME=${TRAVIS_OS_NAME}
  191. export OPJ_SITE=${OPJ_SITE}
  192. export OPJ_BUILDNAME=${OPJ_BUILDNAME}
  193. export OPJ_SOURCE_DIR=$(opjpath -m ${OPJ_SOURCE_DIR})
  194. export OPJ_BINARY_DIR=$(opjpath -m ${PWD}/build)
  195. export OPJ_BUILD_CONFIGURATION=${OPJ_CI_BUILD_CONFIGURATION}
  196. export OPJ_DO_SUBMIT=${OPJ_DO_SUBMIT}
  197. if [ "${OPJ_SKIP_REBUILD:-}" != "1" ]; then
  198. ctest -S ${OPJ_SOURCE_DIR}/tools/ctest_scripts/travis-ci.cmake -V || true
  199. fi
  200. # ctest will exit with various error codes depending on version.
  201. # ignore ctest exit code & parse this ourselves
  202. set +x
  203. if [ "${OPJ_CI_CHECK_STYLE:-}" == "1" ]; then
  204. export OPJSTYLE=${PWD}/scripts/opjstyle
  205. export PATH=${HOME}/.local/bin:${PATH}
  206. scripts/verify-indentation.sh
  207. fi
  208. # Deployment if needed
  209. #---------------------
  210. if [ "${TRAVIS_TAG:-}" != "" ]; then
  211. OPJ_TAG_NAME=${TRAVIS_TAG}
  212. elif [ "${APPVEYOR_REPO_TAG:-}" == "true" ]; then
  213. OPJ_TAG_NAME=${APPVEYOR_REPO_TAG_NAME}
  214. else
  215. OPJ_TAG_NAME=""
  216. fi
  217. if [ "${OPJ_CI_INCLUDE_IF_DEPLOY:-}" == "1" ] && [ "${OPJ_TAG_NAME:-}" != "" ]; then
  218. #if [ "${OPJ_CI_INCLUDE_IF_DEPLOY:-}" == "1" ]; then
  219. OPJ_CI_DEPLOY=1 # unused for now
  220. OPJ_CUR_DIR=${PWD}
  221. if [ "${TRAVIS_OS_NAME:-}" == "linux" ]; then
  222. OPJ_PACK_GENERATOR="TGZ" # ZIP generator currently segfaults on linux
  223. else
  224. OPJ_PACK_GENERATOR="ZIP"
  225. fi
  226. OPJ_PACK_NAME="openjpeg-${OPJ_TAG_NAME}-${TRAVIS_OS_NAME}-${OPJ_CI_ARCH}"
  227. cd ${OPJ_BINARY_DIR}
  228. cmake -D CPACK_GENERATOR:STRING=${OPJ_PACK_GENERATOR} -D CPACK_PACKAGE_FILE_NAME:STRING=${OPJ_PACK_NAME} ${OPJ_SOURCE_DIR}
  229. cd ${OPJ_CUR_DIR}
  230. cmake --build ${OPJ_BINARY_DIR} --target package
  231. echo "ready to deploy $(ls ${OPJ_BINARY_DIR}/${OPJ_PACK_NAME}*) to GitHub releases"
  232. if [ "${APPVEYOR_REPO_TAG:-}" == "true" ]; then
  233. appveyor PushArtifact "${OPJ_BINARY_DIR}/${OPJ_PACK_NAME}.zip"
  234. fi
  235. else
  236. OPJ_CI_DEPLOY=0
  237. fi
  238. # let's parse configure/build/tests for failure
  239. echo "
  240. Parsing logs for failures
  241. "
  242. OPJ_CI_RESULT=0
  243. # 1st configure step
  244. OPJ_CONFIGURE_XML=$(find build -path 'build/Testing/*' -name 'Configure.xml')
  245. if [ ! -f "${OPJ_CONFIGURE_XML}" ]; then
  246. echo "No configure log found"
  247. OPJ_CI_RESULT=1
  248. else
  249. if ! grep '<ConfigureStatus>0</ConfigureStatus>' ${OPJ_CONFIGURE_XML} &> /dev/null; then
  250. echo "Errors were found in configure log"
  251. OPJ_CI_RESULT=1
  252. fi
  253. fi
  254. # 2nd build step
  255. # We must have one Build.xml file
  256. OPJ_BUILD_XML=$(find build -path 'build/Testing/*' -name 'Build.xml')
  257. if [ ! -f "${OPJ_BUILD_XML}" ]; then
  258. echo "No build log found"
  259. OPJ_CI_RESULT=1
  260. else
  261. if grep '<Error>' ${OPJ_BUILD_XML} &> /dev/null; then
  262. echo "Errors were found in build log"
  263. OPJ_CI_RESULT=1
  264. fi
  265. fi
  266. if [ ${OPJ_CI_RESULT} -ne 0 ]; then
  267. # Don't trash output with failing tests when there are configure/build errors
  268. exit ${OPJ_CI_RESULT}
  269. fi
  270. if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then
  271. OPJ_TEST_XML=$(find build -path 'build/Testing/*' -name 'Test.xml')
  272. if [ ! -f "${OPJ_TEST_XML}" ]; then
  273. echo "No test log found"
  274. OPJ_CI_RESULT=1
  275. else
  276. echo "Parsing tests for new/unknown failures"
  277. # 3rd test step
  278. OPJ_FAILEDTEST_LOG=$(find build -path 'build/Testing/Temporary/*' -name 'LastTestsFailed_*.log')
  279. if [ -f "${OPJ_FAILEDTEST_LOG}" ]; then
  280. awk -F: '{ print $2 }' ${OPJ_FAILEDTEST_LOG} > failures.txt
  281. while read FAILEDTEST; do
  282. # Start with common errors
  283. if grep -x "${FAILEDTEST}" $(opjpath -u ${OPJ_SOURCE_DIR})/tools/travis-ci/knownfailures-all.txt > /dev/null; then
  284. continue
  285. fi
  286. if [ -f $(opjpath -u ${OPJ_SOURCE_DIR})/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt ]; then
  287. if grep -x "${FAILEDTEST}" $(opjpath -u ${OPJ_SOURCE_DIR})/tools/travis-ci/knownfailures-${OPJ_BUILDNAME_TEST}.txt > /dev/null; then
  288. continue
  289. fi
  290. fi
  291. echo "${FAILEDTEST}"
  292. OPJ_CI_RESULT=1
  293. done < failures.txt
  294. fi
  295. fi
  296. if [ ${OPJ_CI_RESULT} -eq 0 ]; then
  297. echo "No new/unknown test failure found
  298. "
  299. else
  300. echo "
  301. New/unknown test failure found!!!
  302. "
  303. fi
  304. # 4th memcheck step
  305. OPJ_MEMCHECK_XML=$(find build -path 'build/Testing/*' -name 'DynamicAnalysis.xml')
  306. if [ -f "${OPJ_MEMCHECK_XML}" ]; then
  307. if grep '<Defect Type' ${OPJ_MEMCHECK_XML} 2> /dev/null; then
  308. echo "Errors were found in dynamic analysis log"
  309. OPJ_CI_RESULT=1
  310. fi
  311. fi
  312. fi
  313. if [ "${OPJ_CI_BUILD_FUZZERS:-}" == "1" ]; then
  314. cd tests/fuzzers
  315. make
  316. cd ../..
  317. fi
  318. if [ "${OPJ_CI_PERF_TESTS:-}" == "1" ]; then
  319. cd tests/performance
  320. echo "Running performance tests on current version (dry-run)"
  321. PATH=../../build/bin:$PATH python ./perf_test.py
  322. echo "Running performance tests on current version"
  323. PATH=../../build/bin:$PATH python ./perf_test.py -o /tmp/new.csv
  324. if [ "${OPJ_NONCOMMERCIAL:-}" == "1" ] && [ -d ../../kdu ]; then
  325. echo "Running performances tests with Kakadu"
  326. LD_LIBRARY_PATH=../../kdu PATH=../../kdu::$PATH python ./perf_test.py -kakadu -o /tmp/kakadu.csv
  327. echo "Comparing current version with Kakadu"
  328. python compare_perfs.py /tmp/kakadu.csv /tmp/new.csv || true
  329. fi
  330. cd ../..
  331. REF_VERSION=master
  332. if [ "${TRAVIS_PULL_REQUEST:-false}" == "false" ]; then
  333. REF_VERSION=v2.1.2
  334. fi
  335. if [ ! -d ref_opj ]; then
  336. git clone https://github.com/uclouvain/openjpeg ref_opj
  337. fi
  338. echo "Building reference version (${REF_VERSION})"
  339. cd ref_opj
  340. git checkout ${REF_VERSION}
  341. mkdir -p build
  342. cd build
  343. cmake .. -DCMAKE_BUILD_TYPE=${OPJ_BUILD_CONFIGURATION}
  344. make -j3
  345. cd ../..
  346. cd tests/performance
  347. echo "Running performance tests on ${REF_VERSION} version (dry-run)"
  348. PATH=../../ref_opj/build/bin:$PATH python ./perf_test.py
  349. echo "Running performance tests on ${REF_VERSION} version"
  350. PATH=../../ref_opj/build/bin:$PATH python ./perf_test.py -o /tmp/ref.csv
  351. echo "Comparing current version with ${REF_VERSION} version"
  352. # we should normally set OPJ_CI_RESULT=1 in case of failure, but
  353. # this is too unreliable
  354. python compare_perfs.py /tmp/ref.csv /tmp/new.csv || true
  355. cd ../..
  356. fi
  357. if [ "${OPJ_CI_PROFILE:-}" == "1" ]; then
  358. rm -rf build_gprof
  359. mkdir build_gprof
  360. cd build_gprof
  361. # We need static linking for gprof
  362. cmake "-DCMAKE_C_FLAGS=-pg -O3" -DCMAKE_EXE_LINKER_FLAGS=-pg -DCMAKE_SHARED_LINKER_FLAGS=-pg -DBUILD_SHARED_LIBS=OFF ..
  363. make -j3
  364. cd ..
  365. build_gprof/bin/opj_decompress -i data/input/nonregression/kodak_2layers_lrcp.j2c -o out.tif > /dev/null
  366. echo "Most CPU consuming functions:"
  367. gprof build_gprof/bin/opj_decompress gmon.out | head || true
  368. rm -f massif.out.*
  369. valgrind --tool=massif build/bin/opj_decompress -i data/input/nonregression/kodak_2layers_lrcp.j2c -o out.tif >/dev/null 2>/dev/null
  370. echo ""
  371. echo "Memory consumption profile:"
  372. python tests/profiling/filter_massif_output.py massif.out.*
  373. fi
  374. exit ${OPJ_CI_RESULT}