travis_linux_script.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 -DBUILD_SHARED_LIBS=ON ..
  121. make -j
  122. if [ $? -ne 0 ] ; then exit 1 ; fi
  123. cp ../LICENSE ../AUTHORS ../README.md .
  124. zip -r open62541-win32.zip ../../doc_latex/open62541.pdf LICENSE AUTHORS README.md ./bin/examples/server_ctt.exe ./bin/examples/client.exe ./bin/libopen62541.* open62541.h open62541.c
  125. cp open62541-win32.zip ..
  126. cd .. && rm build -rf
  127. echo -en 'travis_fold:end:script.build.cross_mingw32\\r'
  128. echo -e "\r\n== Cross compile release build for MinGW 64 bit ==" && echo -en 'travis_fold:start:script.build.cross_mingw64\\r'
  129. mkdir -p build && cd build
  130. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON ..
  131. make -j
  132. if [ $? -ne 0 ] ; then exit 1 ; fi
  133. cp ../LICENSE ../AUTHORS ../README.md .
  134. zip -r open62541-win64.zip ../../doc_latex/open62541.pdf LICENSE AUTHORS README.md ./bin/examples/server_ctt.exe ./bin/examples/client.exe ./bin/libopen62541.* open62541.h open62541.c
  135. cp open62541-win64.zip ..
  136. cd .. && rm build -rf
  137. echo -en 'travis_fold:end:script.build.cross_mingw64\\r'
  138. echo -e "\r\n== Cross compile release build for 32-bit linux ==" && echo -en 'travis_fold:start:script.build.cross_linux\\r'
  139. mkdir -p build && cd build
  140. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-gcc-m32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON ..
  141. make -j
  142. if [ $? -ne 0 ] ; then exit 1 ; fi
  143. tar -pczf open62541-linux32.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md bin/examples/server_ctt bin/examples/client bin/libopen62541.* open62541.h open62541.c
  144. cp open62541-linux32.tar.gz ..
  145. cd .. && rm build -rf
  146. echo -en 'travis_fold:end:script.build.cross_linux\\r'
  147. echo -e "\r\n== Cross compile release build for RaspberryPi ==" && echo -en 'travis_fold:start:script.build.cross_raspi\\r'
  148. mkdir -p build && cd build
  149. git clone https://github.com/raspberrypi/tools
  150. export PATH=$PATH:./tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
  151. cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON ..
  152. make -j
  153. if [ $? -ne 0 ] ; then exit 1 ; fi
  154. tar -pczf open62541-raspberrypi.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md bin/examples/server_ctt bin/examples/client bin/libopen62541.* open62541.h open62541.c
  155. cp open62541-raspberrypi.tar.gz ..
  156. cd .. && rm build -rf
  157. echo -en 'travis_fold:end:script.build.cross_raspi\\r'
  158. fi
  159. echo -e "\r\n== Compile release build for 64-bit linux ==" && echo -en 'travis_fold:start:script.build.linux_64\\r'
  160. mkdir -p build && cd build
  161. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DCMAKE_BUILD_TYPE=Release -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON ..
  162. make -j
  163. if [ $? -ne 0 ] ; then exit 1 ; fi
  164. tar -pczf open62541-linux64.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md bin/examples/server_ctt bin/examples/client bin/libopen62541.* open62541.h open62541.c
  165. cp open62541-linux64.tar.gz ..
  166. cp open62541.h ../.. # copy single file-release
  167. cp open62541.c ../.. # copy single file-release
  168. cd .. && rm build -rf
  169. echo -en 'travis_fold:end:script.build.linux_64\\r'
  170. echo -e "\r\n== Building the C++ example ==" && echo -en 'travis_fold:start:script.build.example\\r'
  171. mkdir -p build && cd build
  172. cp ../../open62541.* .
  173. gcc -std=c99 -c open62541.c
  174. g++ ../examples/server.cpp -I./ open62541.o -lrt -o cpp-server
  175. if [ $? -ne 0 ] ; then exit 1 ; fi
  176. cd .. && rm build -rf
  177. echo -en 'travis_fold:end:script.build.example\\r'
  178. echo "Compile as shared lib version" && echo -en 'travis_fold:start:script.build.shared_libs\\r'
  179. mkdir -p build && cd build
  180. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DBUILD_SHARED_LIBS=ON -DUA_ENABLE_AMALGAMATION=ON -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.shared_libs\\r'
  185. if [ "$CC" != "tcc" ]; then
  186. echo -e "\r\n==Compile multithreaded version==" && echo -en 'travis_fold:start:script.build.multithread\\r'
  187. mkdir -p build && cd build
  188. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=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\\r'
  193. fi
  194. echo -e "\r\n== Compile with encryption ==" && echo -en 'travis_fold:start:script.build.encryption\\r'
  195. mkdir -p build && cd build
  196. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_ENCRYPTION=ON -DUA_BUILD_EXAMPLES=ON ..
  197. make -j
  198. if [ $? -ne 0 ] ; then exit 1 ; fi
  199. cd .. && rm build -rf
  200. echo -en 'travis_fold:end:script.build.encryption\\r'
  201. echo -e "\r\n== Compile without discovery version ==" && echo -en 'travis_fold:start:script.build.discovery\\r'
  202. mkdir -p build && cd build
  203. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=OFF -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  204. make -j
  205. if [ $? -ne 0 ] ; then exit 1 ; fi
  206. cd .. && rm build -rf
  207. echo -en 'travis_fold:end:script.build.discovery\\r'
  208. echo -e "\r\n== Compile discovery without multicast version ==" && echo -en 'travis_fold:start:script.build.multicast\\r'
  209. mkdir -p build && cd build
  210. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=OFF -DUA_BUILD_EXAMPLES=ON ..
  211. make -j
  212. if [ $? -ne 0 ] ; then exit 1 ; fi
  213. cd .. && rm build -rf
  214. echo -en 'travis_fold:end:script.build.multicast\\r'
  215. if [ "$CC" != "tcc" ]; then
  216. echo -e "\r\n== Compile multithreaded version with discovery ==" && echo -en 'travis_fold:start:script.build.multithread_discovery\\r'
  217. mkdir -p build && cd build
  218. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_ENABLE_MULTITHREADING=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_EXAMPLES=ON ..
  219. make -j
  220. if [ $? -ne 0 ] ; then exit 1 ; fi
  221. cd .. && rm build -rf
  222. echo -en 'travis_fold:end:script.build.multithread_discovery\\r'
  223. fi
  224. echo -e "\r\n== Unit tests (full NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_full\\r'
  225. mkdir -p build && cd build
  226. # Valgrind cannot handle the full NS0 because the generated file is too big. Thus run NS0 full without valgrind
  227. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON -DUA_NAMESPACE_ZERO=FULL \
  228. -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 \
  229. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=OFF \
  230. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=OFF -DUA_ENABLE_SUBSCRIPTIONS=ON -DUA_ENABLE_SUBSCRIPTIONS_EVENTS=ON ..
  231. make -j && make test ARGS="-V"
  232. if [ $? -ne 0 ] ; then exit 1 ; fi
  233. cd .. && rm build -rf
  234. echo -en 'travis_fold:end:script.build.unit_test_ns0_full\\r'
  235. if [ "$CC" != "tcc" ]; then
  236. echo -e "\r\n== Unit tests (minimal NS0) ==" && echo -en 'travis_fold:start:script.build.unit_test_ns0_minimal\\r'
  237. mkdir -p build && cd build
  238. cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/$PYTHON \
  239. -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 \
  240. -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON \
  241. -DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON ..
  242. make -j && make test ARGS="-V"
  243. if [ $? -ne 0 ] ; then exit 1 ; fi
  244. echo -en 'travis_fold:end:script.build.unit_test_ns0_minimal\\r'
  245. # only run coveralls on main repo and when MINGW=true
  246. # We only want to build coveralls once, so we just take the travis run where MINGW=true which is only enabled once
  247. echo -e "\r\n== -> Current repo: ${TRAVIS_REPO_SLUG} =="
  248. if [ $MINGW = "true" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
  249. echo -en "\r\n== Building coveralls for ${TRAVIS_REPO_SLUG} ==" && echo -en 'travis_fold:start:script.build.coveralls\\r'
  250. 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
  251. echo -en 'travis_fold:end:script.build.coveralls\\r'
  252. fi
  253. cd .. && rm build -rf
  254. fi
  255. fi