travis_linux_script.sh 11 KB

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