travis_linux_script.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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_AMALGAMATION=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. else
  70. cppcheck --template "{file}({line}): {severity} ({id}): {message}" \
  71. --enable=style --force --std=c++11 -j 8 \
  72. --suppress=duplicateBranch \
  73. --suppress=incorrectStringBooleanError \
  74. --suppress=invalidscanf --inline-suppr \
  75. -I include src plugins examples 2> cppcheck.txt
  76. if [ -s cppcheck.txt ]; then
  77. echo "====== CPPCHECK Static Analysis Errors ======"
  78. cat cppcheck.txt
  79. # flush output
  80. sleep 5
  81. exit 1
  82. fi
  83. fi
  84. echo -en 'travis_fold:end:script.analyze\\r'
  85. else
  86. echo -en "\r\n=== Building ===\r\n"
  87. echo -e "\r\n== Documentation and certificate build ==" && echo -en 'travis_fold:start:script.build.doc\\r'
  88. mkdir -p build
  89. cd build
  90. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_SELFSIGNED_CERTIFICATE=ON ..
  91. make doc
  92. make doc_pdf
  93. make selfsigned
  94. cp -r doc ../../
  95. cp -r doc_latex ../../
  96. cp ./examples/server_cert.der ../../
  97. cd .. && rm build -rf
  98. echo -en 'travis_fold:end:script.build.doc\\r'
  99. echo -e "\r\n== Full Namespace 0 Generation ==" && echo -en 'travis_fold:start:script.build.ns0\\r'
  100. mkdir -p build
  101. cd build
  102. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Debug -DUA_ENABLE_FULL_NS0=ON -DUA_BUILD_EXAMPLES=ON \
  103. -DUA_ENABLE_SUBSCRIPTIONS_EVENTS=ON ..
  104. make -j
  105. if [ $? -ne 0 ] ; then exit 1 ; fi
  106. cd .. && rm build -rf
  107. echo -en 'travis_fold:end:script.build.ns0\\r'
  108. # cross compilation only with gcc
  109. if ! [ -z ${MINGW+x} ]; then
  110. echo -e "\r\n== Cross compile release build for MinGW 32 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw32\\r'
  111. mkdir -p build && cd build
  112. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  113. make -j
  114. if [ $? -ne 0 ] ; then exit 1 ; fi
  115. zip -r open62541-win32.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server_ctt.exe ./bin/examples/client.exe ./bin/libopen62541.dll.a open62541.h open62541.c
  116. cp open62541-win32.zip ..
  117. cd .. && rm build -rf
  118. echo -en 'travis_fold:end:script.build.cross_mingw32\\r'
  119. echo -e "\r\n== Cross compile release build for MinGW 64 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw64\\r'
  120. mkdir -p build && cd build
  121. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  122. make -j
  123. if [ $? -ne 0 ] ; then exit 1 ; fi
  124. zip -r open62541-win64.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server_ctt.exe ./bin/examples/client.exe ./bin/libopen62541.dll.a open62541.h open62541.c
  125. cp open62541-win64.zip ..
  126. cd .. && rm build -rf
  127. echo -en 'travis_fold:end:script.build.cross_mingw64\\r'
  128. echo -e "\r\n== Cross compile release build for 32-bit linux ==" && echo -en 'travis_fold:start:script.build.cross_linux\\r'
  129. mkdir -p build && cd build
  130. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-gcc-m32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  131. make -j
  132. if [ $? -ne 0 ] ; then exit 1 ; fi
  133. tar -pczf open62541-linux32.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server_ctt ./bin/examples/client ./bin/libopen62541.a open62541.h open62541.c
  134. cp open62541-linux32.tar.gz ..
  135. cd .. && rm build -rf
  136. echo -en 'travis_fold:end:script.build.cross_linux\\r'
  137. echo -e "\r\n== Cross compile release build for RaspberryPi ==" && echo -en 'travis_fold:start:script.build.cross_raspi\\r'
  138. mkdir -p build && cd build
  139. git clone https://github.com/raspberrypi/tools
  140. export PATH=$PATH:./tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
  141. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  142. make -j
  143. if [ $? -ne 0 ] ; then exit 1 ; fi
  144. tar -pczf open62541-raspberrypi.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server_ctt ./bin/examples/client ./bin/libopen62541.a open62541.h open62541.c
  145. cp open62541-raspberrypi.tar.gz ..
  146. cd .. && rm build -rf
  147. echo -en 'travis_fold:end:script.build.cross_raspi\\r'
  148. fi
  149. echo -e "\r\n== Compile release build for 64-bit linux ==" && echo -en 'travis_fold:start:script.build.linux_64\\r'
  150. mkdir -p build && cd build
  151. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Release -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  152. make -j
  153. if [ $? -ne 0 ] ; then exit 1 ; fi
  154. tar -pczf open62541-linux64.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server_ctt ./bin/examples/client ./bin/libopen62541.a open62541.h open62541.c
  155. cp open62541-linux64.tar.gz ..
  156. cp open62541.h ../.. # copy single file-release
  157. cp open62541.c ../.. # copy single file-release
  158. cd .. && rm build -rf
  159. echo -en 'travis_fold:end:script.build.linux_64\\r'
  160. echo -e "\r\n== Building the C++ example ==" && echo -en 'travis_fold:start:script.build.example\\r'
  161. mkdir -p build && cd build
  162. cp ../../open62541.* .
  163. gcc -std=c99 -c open62541.c
  164. g++ ../examples/server.cpp -I./ open62541.o -lrt -o cpp-server
  165. if [ $? -ne 0 ] ; then exit 1 ; fi
  166. cd .. && rm build -rf
  167. echo -en 'travis_fold:end:script.build.example\\r'
  168. echo "Compile as shared lib version" && echo -en 'travis_fold:start:script.build.shared_libs\\r'
  169. mkdir -p build && cd build
  170. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DBUILD_SHARED_LIBS=ON -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  171. make -j
  172. if [ $? -ne 0 ] ; then exit 1 ; fi
  173. cd .. && rm build -rf
  174. echo -en 'travis_fold:end:script.build.shared_libs\\r'
  175. if [ "$CC" != "tcc" ]; then
  176. echo -e "\r\n==Compile multithreaded version==" && echo -en 'travis_fold:start:script.build.multithread\\r'
  177. mkdir -p build && cd build
  178. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLES=ON ..
  179. make -j
  180. if [ $? -ne 0 ] ; then exit 1 ; fi
  181. cd .. && rm build -rf
  182. echo -en 'travis_fold:end:script.build.multithread\\r'
  183. fi
  184. echo -e "\r\n== Compile with encryption ==" && echo -en 'travis_fold:start:script.build.encryption\\r'
  185. mkdir -p build && cd build
  186. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_ENCRYPTION=ON -DUA_BUILD_EXAMPLES=ON ..
  187. make -j
  188. if [ $? -ne 0 ] ; then exit 1 ; fi
  189. cd .. && rm build -rf
  190. echo -en 'travis_fold:end:script.build.encryption\\r'
  191. echo -e "\r\n== Compile without discovery version ==" && echo -en 'travis_fold:start:script.build.discovery\\r'
  192. mkdir -p build && cd build
  193. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=OFF -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  194. make -j
  195. if [ $? -ne 0 ] ; then exit 1 ; fi
  196. cd .. && rm build -rf
  197. echo -en 'travis_fold:end:script.build.discovery\\r'
  198. echo -e "\r\n== Compile discovery without multicast version ==" && echo -en 'travis_fold:start:script.build.multicast\\r'
  199. mkdir -p build && cd build
  200. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  201. make -j
  202. if [ $? -ne 0 ] ; then exit 1 ; fi
  203. cd .. && rm build -rf
  204. echo -en 'travis_fold:end:script.build.multicast\\r'
  205. if [ "$CC" != "tcc" ]; then
  206. echo -e "\r\n== Compile multithreaded version with discovery ==" && echo -en 'travis_fold:start:script.build.multithread_discovery\\r'
  207. mkdir -p build && cd build
  208. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_EXAMPLES=ON ..
  209. make -j
  210. if [ $? -ne 0 ] ; then exit 1 ; fi
  211. cd .. && rm build -rf
  212. echo -en 'travis_fold:end:script.build.multithread_discovery\\r'
  213. fi
  214. echo -e "\r\n== Unit tests (full NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_full\\r'
  215. mkdir -p build && cd build
  216. # Valgrind cannot handle the full NS0 because the generated file is too big. Thus run NS0 full without valgrind
  217. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_FULL_NS0=ON \
  218. -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_PUBSUB=ON -DUA_ENABLE_ENCRYPTION=ON -DUA_ENABLE_DISCOVERY=ON \
  219. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=OFF \
  220. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=OFF -DUA_ENABLE_SUBSCRIPTIONS_EVENTS=ON ..
  221. make -j && make test ARGS="-V"
  222. if [ $? -ne 0 ] ; then exit 1 ; fi
  223. cd .. && rm build -rf
  224. echo -en 'travis_fold:end:script.build.unit_test_ns0_full\\r'
  225. if [ "$CC" != "tcc" ]; then
  226. echo -e "\r\n== Unit tests (minimal NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_minimal\\r'
  227. mkdir -p build && cd build
  228. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON \
  229. -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_PUBSUB=ON -DUA_ENABLE_ENCRYPTION=ON -DUA_ENABLE_DISCOVERY=ON \
  230. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON \
  231. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON ..
  232. make -j && make test ARGS="-V"
  233. if [ $? -ne 0 ] ; then exit 1 ; fi
  234. echo -en 'travis_fold:end:script.build.unit_test_ns0_minimal\\r'
  235. # only run coveralls on main repo, otherwise it fails uploading the files
  236. echo -e "\r\n== -> Current repo: ${TRAVIS_REPO_SLUG} =="
  237. if [ "$CC" = "gcc" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
  238. echo -en "\r\n== Building coveralls for ${TRAVIS_REPO_SLUG} ==" && echo -en 'travis_fold:start:script.build.coveralls\\r'
  239. 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
  240. echo -en 'travis_fold:end:script.build.coveralls\\r'
  241. fi
  242. cd .. && rm build -rf
  243. fi
  244. fi