travis_linux_script.sh 12 KB

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