travis_linux_script.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #!/bin/bash
  2. set -e
  3. # Docker build test
  4. if ! [ -z ${DOCKER+x} ]; then
  5. docker build -t open62541 .
  6. docker run -d -p 127.0.0.1:80:80 --name open62541 open62541 /bin/sh
  7. docker ps | grep -q open62541
  8. # disabled since it randomly fails
  9. # docker ps | grep -q open62541
  10. exit 0
  11. fi
  12. # Fuzzer build test
  13. if ! [ -z ${FUZZER+x} ]; then
  14. mkdir -p build && cd build
  15. export CC=clang-3.9
  16. export CXX=clang++-3.9
  17. cmake -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_FUZZING=ON ..
  18. make && make run_fuzzer
  19. if [ $? -ne 0 ] ; then exit 1 ; fi
  20. cd .. && rm build -rf
  21. exit 0
  22. fi
  23. if [ $ANALYZE = "true" ]; then
  24. echo "=== Running static code analysis ===" && echo -en 'travis_fold:start:script.analyze\\r'
  25. if [ "$CC" = "clang" ]; then
  26. mkdir -p build
  27. cd build
  28. scan-build-3.9 cmake -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON ..
  29. scan-build-3.9 -enable-checker security.FloatLoopCounter \
  30. -enable-checker security.insecureAPI.UncheckedReturn \
  31. --status-bugs -v \
  32. make -j
  33. cd .. && rm build -rf
  34. mkdir -p build
  35. cd build
  36. scan-build-3.9 cmake -DUA_ENABLE_AMALGAMATION=ON ..
  37. scan-build-3.9 -enable-checker security.FloatLoopCounter \
  38. -enable-checker security.insecureAPI.UncheckedReturn \
  39. --status-bugs -v \
  40. make -j
  41. cd .. && rm build -rf
  42. mkdir -p build
  43. cd build
  44. cmake -DUA_BUILD_EXAMPLES=ON ..
  45. make -j
  46. make lint
  47. cd .. && rm build -rf
  48. else
  49. cppcheck --template "{file}({line}): {severity} ({id}): {message}" \
  50. --enable=style --force --std=c++11 -j 8 \
  51. --suppress=duplicateBranch \
  52. --suppress=incorrectStringBooleanError \
  53. --suppress=invalidscanf --inline-suppr \
  54. -I include src plugins 2> cppcheck.txt
  55. if [ -s cppcheck.txt ]; then
  56. echo "====== CPPCHECK Static Analysis Errors ======"
  57. cat cppcheck.txt
  58. # flush output
  59. sleep 5
  60. exit 1
  61. fi
  62. fi
  63. echo -en 'travis_fold:end:script.analyze\\r'
  64. else
  65. echo -en "\r\n=== Building ===\r\n"
  66. echo -e "\r\n== Documentation and certificate build ==" && echo -en 'travis_fold:start:script.build.doc\\r'
  67. mkdir -p build
  68. cd build
  69. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_SELFSIGNED_CERTIFICATE=ON ..
  70. make doc
  71. make doc_pdf
  72. make selfsigned
  73. cp -r doc ../../
  74. cp -r doc_latex ../../
  75. cp ./examples/server_cert.der ../../
  76. cd .. && rm build -rf
  77. echo -en 'travis_fold:end:script.build.doc\\r'
  78. echo -e "\r\n== Full Namespace 0 Generation ==" && echo -en 'travis_fold:start:script.build.ns0\\r'
  79. mkdir -p build
  80. cd build
  81. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Debug -DUA_ENABLE_FULL_NS0=ON -DUA_BUILD_EXAMPLES=ON ..
  82. make -j
  83. if [ $? -ne 0 ] ; then exit 1 ; fi
  84. cd .. && rm build -rf
  85. echo -en 'travis_fold:end:script.build.ns0\\r'
  86. # cross compilation only with gcc
  87. if [ "$CC" = "gcc" ]; then
  88. echo -e "\r\n== Cross compile release build for MinGW 32 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw32\\r'
  89. mkdir -p build && cd build
  90. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  91. make -j
  92. if [ $? -ne 0 ] ; then exit 1 ; fi
  93. zip -r open62541-win32.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server.exe ./bin/examples/client.exe ./bin/libopen62541.dll.a open62541.h open62541.c
  94. cp open62541-win32.zip ..
  95. cd .. && rm build -rf
  96. echo -en 'travis_fold:end:script.build.cross_mingw32\\r'
  97. echo -e "\r\n== Cross compile release build for MinGW 64 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw64\\r'
  98. mkdir -p build && cd build
  99. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  100. make -j
  101. if [ $? -ne 0 ] ; then exit 1 ; fi
  102. zip -r open62541-win64.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server.exe ./bin/examples/client.exe ./bin/libopen62541.dll.a open62541.h open62541.c
  103. cp open62541-win64.zip ..
  104. cd .. && rm build -rf
  105. echo -en 'travis_fold:end:script.build.cross_mingw64\\r'
  106. echo -e "\r\n== Cross compile release build for 32-bit linux ==" && echo -en 'travis_fold:start:script.build.cross_linux\\r'
  107. mkdir -p build && cd build
  108. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-gcc-m32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  109. make -j
  110. if [ $? -ne 0 ] ; then exit 1 ; fi
  111. tar -pczf open62541-linux32.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server ./bin/examples/client ./bin/libopen62541.a open62541.h open62541.c
  112. cp open62541-linux32.tar.gz ..
  113. cd .. && rm build -rf
  114. echo -en 'travis_fold:end:script.build.cross_linux\\r'
  115. echo -e "\r\n== Cross compile release build for RaspberryPi ==" && echo -en 'travis_fold:start:script.build.cross_raspi\\r'
  116. mkdir -p build && cd build
  117. git clone https://github.com/raspberrypi/tools
  118. export PATH=$PATH:./tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
  119. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  120. make -j
  121. if [ $? -ne 0 ] ; then exit 1 ; fi
  122. tar -pczf open62541-raspberrypi.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server ./bin/examples/client ./bin/libopen62541.a open62541.h open62541.c
  123. cp open62541-raspberrypi.tar.gz ..
  124. cd .. && rm build -rf
  125. echo -en 'travis_fold:end:script.build.cross_raspi\\r'
  126. fi
  127. echo -e "\r\n== Compile release build for 64-bit linux ==" && echo -en 'travis_fold:start:script.build.linux_64\\r'
  128. mkdir -p build && cd build
  129. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Release -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  130. make -j
  131. if [ $? -ne 0 ] ; then exit 1 ; fi
  132. tar -pczf open62541-linux64.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md ./bin/examples/server ./bin/examples/client ./bin/libopen62541.a open62541.h open62541.c
  133. cp open62541-linux64.tar.gz ..
  134. cp open62541.h ../.. # copy single file-release
  135. cp open62541.c ../.. # copy single file-release
  136. cd .. && rm build -rf
  137. echo -en 'travis_fold:end:script.build.linux_64\\r'
  138. echo -e "\r\n== Building the C++ example ==" && echo -en 'travis_fold:start:script.build.example\\r'
  139. mkdir -p build && cd build
  140. cp ../../open62541.* .
  141. gcc -std=c99 -c open62541.c
  142. g++ ../examples/server.cpp -I./ open62541.o -lrt -o cpp-server
  143. if [ $? -ne 0 ] ; then exit 1 ; fi
  144. cd .. && rm build -rf
  145. echo -en 'travis_fold:end:script.build.example\\r'
  146. echo "Compile as shared lib version" && echo -en 'travis_fold:start:script.build.shared_libs\\r'
  147. mkdir -p build && cd build
  148. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DBUILD_SHARED_LIBS=ON -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  149. make -j
  150. if [ $? -ne 0 ] ; then exit 1 ; fi
  151. cd .. && rm build -rf
  152. echo -en 'travis_fold:end:script.build.shared_libs\\r'echo -e "\r\n==Compile multithreaded version==" && echo -en 'travis_fold:start:script.build.multithread\\r'
  153. mkdir -p build && cd build
  154. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLES=ON ..
  155. make -j
  156. if [ $? -ne 0 ] ; then exit 1 ; fi
  157. cd .. && rm build -rf
  158. echo -en 'travis_fold:end:script.build.multithread\\r'
  159. echo -e "\r\n== Compile without discovery version ==" && echo -en 'travis_fold:start:script.build.unit_test_valgrind\\r'
  160. mkdir -p build && cd build
  161. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=OFF -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  162. make -j
  163. if [ $? -ne 0 ] ; then exit 1 ; fi
  164. cd .. && rm build -rf
  165. echo -e "\r\n== Compile discovery without multicast version =="
  166. mkdir -p build && cd build
  167. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  168. make -j
  169. if [ $? -ne 0 ] ; then exit 1 ; fi
  170. cd .. && rm build -rf
  171. echo -e "\r\n== Compile multithreaded version with discovery =="
  172. mkdir -p build && cd build
  173. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_EXAMPLES=ON ..
  174. make -j
  175. if [ $? -ne 0 ] ; then exit 1 ; fi
  176. cd .. && rm build -rf
  177. echo -en 'travis_fold:end:script.build.multithread\\r'
  178. echo -e "\r\n== Unit tests (full NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_full\\r'
  179. mkdir -p build && cd build
  180. # Valgrind cannot handle the full NS0 because the generated file is too big. Thus run NS0 full without valgrind
  181. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_FULL_NS0=ON \
  182. -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON \
  183. -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=OFF -DUA_ENABLE_UNIT_TESTS_MEMCHECK=OFF ..
  184. make -j && make test ARGS="-V"
  185. if [ $? -ne 0 ] ; then exit 1 ; fi
  186. cd .. && rm build -rf
  187. echo -en 'travis_fold:end:script.build.unit_test_ns0\\r'
  188. echo -e "\r\n== Unit tests (minimal NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_minimal\\r'
  189. mkdir -p build && cd build
  190. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON \
  191. -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON \
  192. -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON ..
  193. make -j && make test ARGS="-V"
  194. if [ $? -ne 0 ] ; then exit 1 ; fi
  195. echo -en 'travis_fold:end:script.build.unit_test_ns0_minimal\\r'
  196. # only run coveralls on main repo, otherwise it fails uploading the files
  197. echo -e "\r\n== -> Current repo: ${TRAVIS_REPO_SLUG} =="
  198. if [ "$CC" = "gcc" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
  199. echo -en "\r\n== Building coveralls for ${TRAVIS_REPO_SLUG} ==" && echo -en 'travis_fold:start:script.build.coveralls\\r'
  200. 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
  201. echo -en 'travis_fold:end:script.build.coveralls\\r'
  202. fi
  203. cd .. && rm build -rf
  204. fi