travis_linux_script.sh 11 KB

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