travis_linux_script.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 [ "$CC" = "clang" ]; then
  53. mkdir -p build
  54. cd build
  55. scan-build cmake -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON ..
  56. scan-build -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 cmake -DUA_ENABLE_AMALGAMATION=ON ..
  64. scan-build -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. make -j
  104. if [ $? -ne 0 ] ; then exit 1 ; fi
  105. cd .. && rm build -rf
  106. echo -en 'travis_fold:end:script.build.ns0\\r'
  107. # cross compilation only with gcc
  108. if [ "$CC" = "gcc" ]; then
  109. echo -e "\r\n== Cross compile release build for MinGW 32 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw32\\r'
  110. mkdir -p build && cd build
  111. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  112. make -j
  113. if [ $? -ne 0 ] ; then exit 1 ; fi
  114. 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
  115. cp open62541-win32.zip ..
  116. cd .. && rm build -rf
  117. echo -en 'travis_fold:end:script.build.cross_mingw32\\r'
  118. echo -e "\r\n== Cross compile release build for MinGW 64 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw64\\r'
  119. mkdir -p build && cd build
  120. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  121. make -j
  122. if [ $? -ne 0 ] ; then exit 1 ; fi
  123. 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
  124. cp open62541-win64.zip ..
  125. cd .. && rm build -rf
  126. echo -en 'travis_fold:end:script.build.cross_mingw64\\r'
  127. echo -e "\r\n== Cross compile release build for 32-bit linux ==" && echo -en 'travis_fold:start:script.build.cross_linux\\r'
  128. mkdir -p build && cd build
  129. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-gcc-m32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  130. make -j
  131. if [ $? -ne 0 ] ; then exit 1 ; fi
  132. 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
  133. cp open62541-linux32.tar.gz ..
  134. cd .. && rm build -rf
  135. echo -en 'travis_fold:end:script.build.cross_linux\\r'
  136. echo -e "\r\n== Cross compile release build for RaspberryPi ==" && echo -en 'travis_fold:start:script.build.cross_raspi\\r'
  137. mkdir -p build && cd build
  138. git clone https://github.com/raspberrypi/tools
  139. export PATH=$PATH:./tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
  140. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
  141. make -j
  142. if [ $? -ne 0 ] ; then exit 1 ; fi
  143. 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
  144. cp open62541-raspberrypi.tar.gz ..
  145. cd .. && rm build -rf
  146. echo -en 'travis_fold:end:script.build.cross_raspi\\r'
  147. fi
  148. echo -e "\r\n== Compile release build for 64-bit linux ==" && echo -en 'travis_fold:start:script.build.linux_64\\r'
  149. mkdir -p build && cd build
  150. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Release -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  151. make -j
  152. if [ $? -ne 0 ] ; then exit 1 ; fi
  153. 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
  154. cp open62541-linux64.tar.gz ..
  155. cp open62541.h ../.. # copy single file-release
  156. cp open62541.c ../.. # copy single file-release
  157. cd .. && rm build -rf
  158. echo -en 'travis_fold:end:script.build.linux_64\\r'
  159. echo -e "\r\n== Building the C++ example ==" && echo -en 'travis_fold:start:script.build.example\\r'
  160. mkdir -p build && cd build
  161. cp ../../open62541.* .
  162. gcc -std=c99 -DUA_ARCHITECTURE_POSIX -c open62541.c
  163. g++ ../examples/server.cpp -DUA_ARCHITECTURE_POSIX -I./ open62541.o -lrt -o cpp-server
  164. if [ $? -ne 0 ] ; then exit 1 ; fi
  165. cd .. && rm build -rf
  166. echo -en 'travis_fold:end:script.build.example\\r'
  167. echo "Compile as shared lib version" && echo -en 'travis_fold:start:script.build.shared_libs\\r'
  168. mkdir -p build && cd build
  169. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DBUILD_SHARED_LIBS=ON -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
  170. make -j
  171. if [ $? -ne 0 ] ; then exit 1 ; fi
  172. cd .. && rm build -rf
  173. echo -en 'travis_fold:end:script.build.shared_libs\\r'
  174. if [ "$CC" != "tcc" ]; then
  175. echo -e "\r\n==Compile multithreaded version==" && echo -en 'travis_fold:start:script.build.multithread\\r'
  176. mkdir -p build && cd build
  177. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLES=ON ..
  178. make -j
  179. if [ $? -ne 0 ] ; then exit 1 ; fi
  180. cd .. && rm build -rf
  181. echo -en 'travis_fold:end:script.build.multithread\\r'
  182. fi
  183. echo -e "\r\n== Compile with encryption ==" && echo -en 'travis_fold:start:script.build.encryption\\r'
  184. mkdir -p build && cd build
  185. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_ENCRYPTION=ON -DUA_BUILD_EXAMPLES=ON ..
  186. make -j
  187. if [ $? -ne 0 ] ; then exit 1 ; fi
  188. cd .. && rm build -rf
  189. echo -en 'travis_fold:end:script.build.encryption\\r'
  190. echo -e "\r\n== Compile without discovery version ==" && echo -en 'travis_fold:start:script.build.discovery\\r'
  191. mkdir -p build && cd build
  192. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=OFF -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  193. make -j
  194. if [ $? -ne 0 ] ; then exit 1 ; fi
  195. cd .. && rm build -rf
  196. echo -en 'travis_fold:end:script.build.discovery\\r'
  197. echo -e "\r\n== Compile discovery without multicast version ==" && echo -en 'travis_fold:start:script.build.multicast\\r'
  198. mkdir -p build && cd build
  199. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  200. make -j
  201. if [ $? -ne 0 ] ; then exit 1 ; fi
  202. cd .. && rm build -rf
  203. echo -en 'travis_fold:end:script.build.multicast\\r'
  204. if [ "$CC" != "tcc" ]; then
  205. echo -e "\r\n== Compile multithreaded version with discovery ==" && echo -en 'travis_fold:start:script.build.multithread_discovery\\r'
  206. mkdir -p build && cd build
  207. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_EXAMPLES=ON ..
  208. make -j
  209. if [ $? -ne 0 ] ; then exit 1 ; fi
  210. cd .. && rm build -rf
  211. echo -en 'travis_fold:end:script.build.multithread_discovery\\r'
  212. fi
  213. echo -e "\r\n== Unit tests (full NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_full\\r'
  214. mkdir -p build && cd build
  215. # Valgrind cannot handle the full NS0 because the generated file is too big. Thus run NS0 full without valgrind
  216. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_FULL_NS0=ON \
  217. -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_PUBSUB=ON -DUA_ENABLE_ENCRYPTION=ON -DUA_ENABLE_DISCOVERY=ON \
  218. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=OFF \
  219. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=OFF ..
  220. make -j && make test ARGS="-V"
  221. if [ $? -ne 0 ] ; then exit 1 ; fi
  222. cd .. && rm build -rf
  223. echo -en 'travis_fold:end:script.build.unit_test_ns0_full\\r'
  224. if [ "$CC" != "tcc" ]; then
  225. echo -e "\r\n== Unit tests (minimal NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_minimal\\r'
  226. mkdir -p build && cd build
  227. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON \
  228. -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_PUBSUB=ON -DUA_ENABLE_ENCRYPTION=ON -DUA_ENABLE_DISCOVERY=ON \
  229. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON \
  230. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON ..
  231. make -j && make test ARGS="-V"
  232. if [ $? -ne 0 ] ; then exit 1 ; fi
  233. echo -en 'travis_fold:end:script.build.unit_test_ns0_minimal\\r'
  234. # only run coveralls on main repo, otherwise it fails uploading the files
  235. echo -e "\r\n== -> Current repo: ${TRAVIS_REPO_SLUG} =="
  236. if [ "$CC" = "gcc" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
  237. echo -en "\r\n== Building coveralls for ${TRAVIS_REPO_SLUG} ==" && echo -en 'travis_fold:start:script.build.coveralls\\r'
  238. 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
  239. echo -en 'travis_fold:end:script.build.coveralls\\r'
  240. fi
  241. cd .. && rm build -rf
  242. fi
  243. fi