travis_linux_script.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. #!/bin/bash
  2. set -e
  3. # Sonar code quality
  4. if ! [ -z ${SONAR+x} ]; then
  5. if ([ "${TRAVIS_REPO_SLUG}" != "open62541/open62541" ] ||
  6. [ "${TRAVIS_PULL_REQUEST}" != "false" ] ||
  7. [ "${TRAVIS_BRANCH}" != "master" ]); then
  8. echo "Skipping Sonarcloud on forks"
  9. # Skip on forks
  10. exit 0;
  11. fi
  12. git fetch --unshallow
  13. mkdir -p build && cd build
  14. build-wrapper-linux-x86-64 --out-dir ../bw-output cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON \
  15. -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON \
  16. -DUA_ENABLE_ENCRYPTION .. \
  17. && make -j
  18. cd ..
  19. sonar-scanner
  20. exit 0
  21. fi
  22. # Docker build test
  23. if ! [ -z ${DOCKER+x} ]; then
  24. docker build -t open62541 .
  25. docker run -d -p 127.0.0.1:80:80 --name open62541 open62541 /bin/sh
  26. docker ps | grep -q open62541
  27. # disabled since it randomly fails
  28. # docker ps | grep -q open62541
  29. exit 0
  30. fi
  31. # Cpplint checking
  32. if ! [ -z ${LINT+x} ]; then
  33. mkdir -p build
  34. cd build
  35. cmake ..
  36. make cpplint
  37. if [ $? -ne 0 ] ; then exit 1 ; fi
  38. exit 0
  39. fi
  40. # Fuzzer build test
  41. if ! [ -z ${FUZZER+x} ]; then
  42. # Test the corpus generator and use new corpus for fuzz test
  43. ./tests/fuzz/generate_corpus.sh
  44. if [ $? -ne 0 ] ; then exit 1 ; fi
  45. cd build_fuzz
  46. make && make run_fuzzer
  47. if [ $? -ne 0 ] ; then exit 1 ; fi
  48. exit 0
  49. fi
  50. if [ $ANALYZE = "true" ]; then
  51. echo "=== Running static code analysis ===" && echo -en 'travis_fold:start:script.analyze\\r'
  52. if ! case $CC in clang*) false;; esac; then
  53. mkdir -p build
  54. cd build
  55. scan-build-6.0 cmake -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON ..
  56. scan-build-6.0 -enable-checker security.FloatLoopCounter \
  57. -enable-checker security.insecureAPI.UncheckedReturn \
  58. --status-bugs -v \
  59. make -j
  60. cd .. && rm build -rf
  61. mkdir -p build
  62. cd build
  63. scan-build-6.0 cmake -DUA_ENABLE_PUBSUB=ON -DUA_ENABLE_PUBSUB_DELTAFRAMES=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL=ON ..
  64. scan-build-6.0 -enable-checker security.FloatLoopCounter \
  65. -enable-checker security.insecureAPI.UncheckedReturn \
  66. --status-bugs -v \
  67. make -j
  68. cd .. && rm build -rf
  69. mkdir -p build
  70. cd build
  71. scan-build-6.0 cmake -DUA_ENABLE_AMALGAMATION=OFF ..
  72. scan-build-6.0 -enable-checker security.FloatLoopCounter \
  73. -enable-checker security.insecureAPI.UncheckedReturn \
  74. --status-bugs -v \
  75. make -j
  76. cd .. && rm build -rf
  77. else
  78. cppcheck --template "{file}({line}): {severity} ({id}): {message}" \
  79. --enable=style --force --std=c++11 -j 8 \
  80. --suppress=duplicateBranch \
  81. --suppress=incorrectStringBooleanError \
  82. --suppress=invalidscanf --inline-suppr \
  83. -I include src plugins examples 2> cppcheck.txt
  84. if [ -s cppcheck.txt ]; then
  85. echo "====== CPPCHECK Static Analysis Errors ======"
  86. cat cppcheck.txt
  87. # flush output
  88. sleep 5
  89. exit 1
  90. fi
  91. fi
  92. echo -en 'travis_fold:end:script.analyze\\r'
  93. else
  94. echo -en "\r\n=== Building ===\r\n"
  95. echo -e "\r\n== Documentation and certificate build ==" && echo -en 'travis_fold:start:script.build.doc\\r'
  96. mkdir -p build
  97. cd build
  98. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_SELFSIGNED_CERTIFICATE=ON ..
  99. make doc
  100. make doc_pdf
  101. make selfsigned
  102. cp -r doc ../../
  103. cp -r doc_latex ../../
  104. cp ./examples/server_cert.der ../../
  105. cd .. && rm build -rf
  106. echo -en 'travis_fold:end:script.build.doc\\r'
  107. echo -e "\r\n== Full Namespace 0 Generation ==" && echo -en 'travis_fold:start:script.build.ns0\\r'
  108. mkdir -p build
  109. cd build
  110. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Debug -DUA_NAMESPACE_ZERO=FULL -DUA_BUILD_EXAMPLES=ON \
  111. -DUA_ENABLE_SUBSCRIPTIONS_EVENTS=ON ..
  112. make -j
  113. if [ $? -ne 0 ] ; then exit 1 ; fi
  114. cd .. && rm build -rf
  115. echo -en 'travis_fold:end:script.build.ns0\\r'
  116. # cross compilation only with gcc
  117. if ! [ -z ${MINGW+x} ]; then
  118. echo -e "\r\n== Cross compile release build for MinGW 32 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw32\\r'
  119. mkdir -p build && cd build
  120. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/open62541-win32 -DUA_ENABLE_AMALGAMATION=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON ..
  121. make -j
  122. if [ $? -ne 0 ] ; then exit 1 ; fi
  123. make install
  124. if [ $? -ne 0 ] ; then exit 1 ; fi
  125. cd ..
  126. zip -r open62541-win32.zip ../doc_latex/open62541.pdf LICENSE AUTHORS README.md open62541-win32/*
  127. rm build -rf
  128. echo -en 'travis_fold:end:script.build.cross_mingw32\\r'
  129. echo -e "\r\n== Cross compile release build for MinGW 64 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw64\\r'
  130. mkdir -p build && cd build
  131. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw64.cmake -DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/open62541-win64 -DUA_ENABLE_AMALGAMATION=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON ..
  132. make -j
  133. if [ $? -ne 0 ] ; then exit 1 ; fi
  134. make install
  135. if [ $? -ne 0 ] ; then exit 1 ; fi
  136. cd ..
  137. zip -r open62541-win64.zip ../doc_latex/open62541.pdf LICENSE AUTHORS README.md open62541-win64/*
  138. rm build -rf
  139. echo -en 'travis_fold:end:script.build.cross_mingw64\\r'
  140. echo -e "\r\n== Cross compile release build for 32-bit linux ==" && echo -en 'travis_fold:start:script.build.cross_linux\\r'
  141. mkdir -p build && cd build
  142. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-gcc-m32.cmake -DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/open62541-linux32 -DUA_ENABLE_AMALGAMATION=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON ..
  143. make -j
  144. if [ $? -ne 0 ] ; then exit 1 ; fi
  145. make install
  146. if [ $? -ne 0 ] ; then exit 1 ; fi
  147. cd ..
  148. tar -pczf open62541-linux32.tar.gz ../doc_latex/open62541.pdf LICENSE AUTHORS README.md open62541-linux32/*
  149. rm build -rf
  150. echo -en 'travis_fold:end:script.build.cross_linux\\r'
  151. echo -e "\r\n== Cross compile release build for RaspberryPi ==" && echo -en 'travis_fold:start:script.build.cross_raspi\\r'
  152. mkdir -p build && cd build
  153. git clone https://github.com/raspberrypi/tools
  154. export PATH=$PATH:./tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
  155. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/open62541-raspberrypi -DUA_ENABLE_AMALGAMATION=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_BUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON ..
  156. make -j
  157. if [ $? -ne 0 ] ; then exit 1 ; fi
  158. make install
  159. if [ $? -ne 0 ] ; then exit 1 ; fi
  160. cd ..
  161. tar -pczf open62541-raspberrypi.tar.gz ../doc_latex/open62541.pdf LICENSE AUTHORS README.md open62541-raspberrypi/*
  162. rm build -rf
  163. echo -en 'travis_fold:end:script.build.cross_raspi\\r'
  164. fi
  165. echo -e "\r\n== Compile release build for 64-bit linux ==" && echo -en 'travis_fold:start:script.build.linux_64\\r'
  166. mkdir -p build && cd build
  167. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/open62541-linux64 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_ENABLE_AMALGAMATION=OFF -DUA_BUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON ..
  168. make -j
  169. if [ $? -ne 0 ] ; then exit 1 ; fi
  170. make install
  171. if [ $? -ne 0 ] ; then exit 1 ; fi
  172. cd ..
  173. tar -pczf open62541-linux64.tar.gz ../doc_latex/open62541.pdf LICENSE AUTHORS README.md open62541-linux64/*
  174. rm build -rf
  175. echo -en 'travis_fold:end:script.build.linux_64\\r'
  176. echo -e "\r\n== Building the C++ example ==" && echo -en 'travis_fold:start:script.build.example\\r'
  177. mkdir -p build && cd build
  178. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/open62541-linux64 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=OFF -DBUILD_SHARED_LIBS=ON ..
  179. make -j
  180. cp open62541.h ../.. # copy single file-release
  181. cp open62541.c ../.. # copy single file-release
  182. gcc -std=c99 -c open62541.c
  183. g++ ../examples/server.cpp -I./ open62541.o -lrt -o cpp-server
  184. if [ $? -ne 0 ] ; then exit 1 ; fi
  185. cd .. && rm build -rf
  186. echo -en 'travis_fold:end:script.build.example\\r'
  187. echo "Compile as shared lib version" && echo -en 'travis_fold:start:script.build.shared_libs\\r'
  188. mkdir -p build && cd build
  189. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DBUILD_SHARED_LIBS=ON -DUA_ENABLE_AMALGAMATION=OFF -DUA_BUILD_EXAMPLES=ON ..
  190. make -j
  191. if [ $? -ne 0 ] ; then exit 1 ; fi
  192. cd .. && rm build -rf
  193. echo -en 'travis_fold:end:script.build.shared_libs\\r'
  194. echo "Compile as shared lib version with amalgamation" && echo -en 'travis_fold:start:script.build.shared_libs_amalgamate\\r'
  195. mkdir -p build && cd build
  196. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DBUILD_SHARED_LIBS=ON -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=OFF ..
  197. make -j
  198. if [ $? -ne 0 ] ; then exit 1 ; fi
  199. cd .. && rm build -rf
  200. echo -en 'travis_fold:end:script.build.shared_libs_amalgamate\\r'
  201. if [ "$CC" != "tcc" ]; then
  202. echo -e "\r\n==Compile multithreaded version==" && echo -en 'travis_fold:start:script.build.multithread\\r'
  203. mkdir -p build && cd build
  204. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLES=ON ..
  205. make -j
  206. if [ $? -ne 0 ] ; then exit 1 ; fi
  207. cd .. && rm build -rf
  208. echo -en 'travis_fold:end:script.build.multithread\\r'
  209. fi
  210. echo -e "\r\n== Compile with encryption ==" && echo -en 'travis_fold:start:script.build.encryption\\r'
  211. mkdir -p build && cd build
  212. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_ENCRYPTION=ON -DUA_BUILD_EXAMPLES=ON ..
  213. make -j
  214. if [ $? -ne 0 ] ; then exit 1 ; fi
  215. cd .. && rm build -rf
  216. echo -en 'travis_fold:end:script.build.encryption\\r'
  217. echo -e "\r\n== Compile without discovery version ==" && echo -en 'travis_fold:start:script.build.discovery\\r'
  218. mkdir -p build && cd build
  219. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=OFF -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  220. make -j
  221. if [ $? -ne 0 ] ; then exit 1 ; fi
  222. cd .. && rm build -rf
  223. echo -en 'travis_fold:end:script.build.discovery\\r'
  224. echo -e "\r\n== Compile discovery without multicast version ==" && echo -en 'travis_fold:start:script.build.multicast\\r'
  225. mkdir -p build && cd build
  226. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  227. make -j
  228. if [ $? -ne 0 ] ; then exit 1 ; fi
  229. cd .. && rm build -rf
  230. echo -en 'travis_fold:end:script.build.multicast\\r'
  231. if [ "$CC" != "tcc" ]; then
  232. echo -e "\r\n== Compile multithreaded version with discovery ==" && echo -en 'travis_fold:start:script.build.multithread_discovery\\r'
  233. mkdir -p build && cd build
  234. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_EXAMPLES=ON ..
  235. make -j
  236. if [ $? -ne 0 ] ; then exit 1 ; fi
  237. cd .. && rm build -rf
  238. echo -en 'travis_fold:end:script.build.multithread_discovery\\r'
  239. fi
  240. echo -e "\r\n== Unit tests (full NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_full\\r'
  241. mkdir -p build && cd build
  242. # Valgrind cannot handle the full NS0 because the generated file is too big. Thus run NS0 full without valgrind
  243. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_NAMESPACE_ZERO=FULL \
  244. -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_PUBSUB=ON -DUA_ENABLE_PUBSUB_DELTAFRAMES=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL=ON -DUA_ENABLE_ENCRYPTION=ON -DUA_ENABLE_DISCOVERY=ON \
  245. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=OFF \
  246. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=OFF -DUA_ENABLE_SUBSCRIPTIONS=ON -DUA_ENABLE_SUBSCRIPTIONS_EVENTS=ON ..
  247. make -j && make test ARGS="-V"
  248. if [ $? -ne 0 ] ; then exit 1 ; fi
  249. cd .. && rm build -rf
  250. echo -en 'travis_fold:end:script.build.unit_test_ns0_full\\r'
  251. if [ "$CC" != "tcc" ]; then
  252. echo -e "\r\n== Unit tests (minimal NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_minimal\\r'
  253. mkdir -p build && cd build
  254. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON \
  255. -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_PUBSUB=ON -DUA_ENABLE_PUBSUB_DELTAFRAMES=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL=ON -DUA_ENABLE_ENCRYPTION=ON -DUA_ENABLE_DISCOVERY=ON \
  256. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON \
  257. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON ..
  258. make -j && make test ARGS="-V"
  259. if [ $? -ne 0 ] ; then exit 1 ; fi
  260. echo -en 'travis_fold:end:script.build.unit_test_ns0_minimal\\r'
  261. # only run coveralls on main repo and when MINGW=true
  262. # We only want to build coveralls once, so we just take the travis run where MINGW=true which is only enabled once
  263. echo -e "\r\n== -> Current repo: ${TRAVIS_REPO_SLUG} =="
  264. if [ $MINGW = "true" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
  265. echo -en "\r\n== Building coveralls for ${TRAVIS_REPO_SLUG} ==" && echo -en 'travis_fold:start:script.build.coveralls\\r'
  266. coveralls -E '.*/build/CMakeFiles/.*' -E '.*/examples/.*' -E '.*/tests/.*' -E '.*\.h' -E '.*CMakeCXXCompilerId\.cpp' -E '.*CMakeCCompilerId\.c' -r ../ || true # ignore result since coveralls is unreachable from time to time
  267. echo -en 'travis_fold:end:script.build.coveralls\\r'
  268. fi
  269. cd .. && rm build -rf
  270. fi
  271. fi