travis_linux_script.sh 13 KB

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