tests.sh 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. #!/bin/bash
  2. #
  3. # Build and runs tests for the protobuf project. The tests as written here are
  4. # used by both Jenkins and Travis, though some specialized logic is required to
  5. # handle the differences between them.
  6. on_travis() {
  7. if [ "$TRAVIS" == "true" ]; then
  8. "$@"
  9. fi
  10. }
  11. # For when some other test needs the C++ main build, including protoc and
  12. # libprotobuf.
  13. internal_build_cpp() {
  14. if [ -f src/protoc ]; then
  15. # Already built.
  16. return
  17. fi
  18. if [[ $(uname -s) == "Linux" && "$TRAVIS" == "true" ]]; then
  19. # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
  20. # decent C++ 11 support in order to compile conformance tests.
  21. sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
  22. sudo apt-get update -qq
  23. sudo apt-get install -qq g++-4.8
  24. export CXX="g++-4.8" CC="gcc-4.8"
  25. fi
  26. ./autogen.sh
  27. ./configure
  28. make -j2
  29. }
  30. build_cpp() {
  31. internal_build_cpp
  32. make check -j2
  33. cd conformance && make test_cpp && cd ..
  34. # Verify benchmarking code can build successfully.
  35. cd benchmarks && make && ./generate-datasets && cd ..
  36. }
  37. build_cpp_distcheck() {
  38. ./autogen.sh
  39. ./configure
  40. make distcheck -j2
  41. }
  42. build_csharp() {
  43. # Just for the conformance tests. We don't currently
  44. # need to really build protoc, but it's simplest to keep with the
  45. # conventions of the other builds.
  46. internal_build_cpp
  47. NUGET=/usr/local/bin/nuget.exe
  48. if [ "$TRAVIS" == "true" ]; then
  49. # Install latest version of Mono
  50. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
  51. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1397BC53640DB551
  52. echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
  53. sudo apt-get update -qq
  54. sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
  55. # Then install the dotnet SDK as per Ubuntu 14.04 instructions on dot.net.
  56. sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
  57. sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
  58. sudo apt-get update -qq
  59. sudo apt-get install -qq dotnet-dev-1.0.0-preview2-003121
  60. fi
  61. # Perform "dotnet new" once to get the setup preprocessing out of the
  62. # way. That spews a lot of output (including backspaces) into logs
  63. # otherwise, and can cause problems. It doesn't matter if this step
  64. # is performed multiple times; it's cheap after the first time anyway.
  65. mkdir dotnettmp
  66. (cd dotnettmp; dotnet new > /dev/null)
  67. rm -rf dotnettmp
  68. (cd csharp/src; dotnet restore)
  69. csharp/buildall.sh
  70. cd conformance && make test_csharp && cd ..
  71. }
  72. build_golang() {
  73. # Go build needs `protoc`.
  74. internal_build_cpp
  75. # Add protoc to the path so that the examples build finds it.
  76. export PATH="`pwd`/src:$PATH"
  77. # Install Go and the Go protobuf compiler plugin.
  78. sudo apt-get update -qq
  79. sudo apt-get install -qq golang
  80. export GOPATH="$HOME/gocode"
  81. mkdir -p "$GOPATH/src/github.com/google"
  82. ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
  83. export PATH="$GOPATH/bin:$PATH"
  84. go get github.com/golang/protobuf/protoc-gen-go
  85. cd examples && make gotest && cd ..
  86. }
  87. use_java() {
  88. version=$1
  89. case "$version" in
  90. jdk6)
  91. on_travis sudo apt-get install openjdk-6-jdk
  92. export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
  93. ;;
  94. jdk7)
  95. on_travis sudo apt-get install openjdk-7-jdk
  96. export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
  97. ;;
  98. oracle7)
  99. if [ "$TRAVIS" == "true" ]; then
  100. sudo apt-get install python-software-properties # for apt-add-repository
  101. echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
  102. sudo debconf-set-selections
  103. yes | sudo apt-add-repository ppa:webupd8team/java
  104. yes | sudo apt-get install oracle-java7-installer
  105. fi;
  106. export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
  107. ;;
  108. esac
  109. if [ "$TRAVIS" != "true" ]; then
  110. MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
  111. MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
  112. fi;
  113. which java
  114. java -version
  115. }
  116. # --batch-mode supresses download progress output that spams the logs.
  117. MVN="mvn --batch-mode"
  118. build_java() {
  119. version=$1
  120. dir=java_$version
  121. # Java build needs `protoc`.
  122. internal_build_cpp
  123. cp -r java $dir
  124. cd $dir && $MVN clean && $MVN test
  125. cd ../..
  126. }
  127. # The conformance tests are hard-coded to work with the $ROOT/java directory.
  128. # So this can't run in parallel with two different sets of tests.
  129. build_java_with_conformance_tests() {
  130. # Java build needs `protoc`.
  131. internal_build_cpp
  132. cd java && $MVN test && $MVN install
  133. cd util && $MVN package assembly:single
  134. cd ../..
  135. cd conformance && make test_java && cd ..
  136. }
  137. build_javanano() {
  138. # Java build needs `protoc`.
  139. internal_build_cpp
  140. cd javanano && $MVN test && cd ..
  141. }
  142. build_java_jdk6() {
  143. use_java jdk6
  144. build_java jdk6
  145. }
  146. build_java_jdk7() {
  147. use_java jdk7
  148. build_java_with_conformance_tests
  149. }
  150. build_java_oracle7() {
  151. use_java oracle7
  152. build_java oracle7
  153. }
  154. build_javanano_jdk6() {
  155. use_java jdk6
  156. build_javanano
  157. }
  158. build_javanano_jdk7() {
  159. use_java jdk7
  160. build_javanano
  161. }
  162. build_javanano_oracle7() {
  163. use_java oracle7
  164. build_javanano
  165. }
  166. internal_install_python_deps() {
  167. if [ "$TRAVIS" != "true" ]; then
  168. return;
  169. fi
  170. # Install tox (OS X doesn't have pip).
  171. if [ $(uname -s) == "Darwin" ]; then
  172. sudo easy_install tox
  173. else
  174. sudo pip install tox
  175. fi
  176. # Only install Python2.6/3.x on Linux.
  177. if [ $(uname -s) == "Linux" ]; then
  178. sudo apt-get install -y python-software-properties # for apt-add-repository
  179. sudo apt-add-repository -y ppa:fkrull/deadsnakes
  180. sudo apt-get update -qq
  181. sudo apt-get install -y python2.6 python2.6-dev
  182. sudo apt-get install -y python3.3 python3.3-dev
  183. sudo apt-get install -y python3.4 python3.4-dev
  184. fi
  185. }
  186. build_objectivec_ios() {
  187. # Reused the build script that takes care of configuring and ensuring things
  188. # are up to date. The OS X test runs the objc conformance test, so skip it
  189. # here.
  190. # Note: travis has xctool installed, and we've looked at using it in the past
  191. # but it has ended up proving unreliable (bugs), an they are removing build
  192. # support in favor of xcbuild (or just xcodebuild).
  193. objectivec/DevTools/full_mac_build.sh \
  194. --core-only --skip-xcode-osx --skip-objc-conformance "$@"
  195. }
  196. build_objectivec_ios_debug() {
  197. build_objectivec_ios --skip-xcode-release
  198. }
  199. build_objectivec_ios_release() {
  200. build_objectivec_ios --skip-xcode-debug
  201. }
  202. build_objectivec_osx() {
  203. # Reused the build script that takes care of configuring and ensuring things
  204. # are up to date.
  205. objectivec/DevTools/full_mac_build.sh \
  206. --core-only --skip-xcode-ios
  207. }
  208. build_objectivec_cocoapods_integration() {
  209. # First, load the RVM environment in bash, needed to update ruby.
  210. source ~/.rvm/scripts/rvm
  211. # Update ruby to 2.2.3 as the default one crashes with segmentation faults
  212. # when using pod.
  213. rvm use 2.2.3 --install --binary --fuzzy
  214. # Update pod to the latest version.
  215. gem install cocoapods --no-ri --no-rdoc
  216. objectivec/Tests/CocoaPods/run_tests.sh
  217. }
  218. build_python() {
  219. internal_build_cpp
  220. internal_install_python_deps
  221. cd python
  222. # Only test Python 2.6/3.x on Linux
  223. if [ $(uname -s) == "Linux" ]; then
  224. envlist=py\{26,27,33,34\}-python
  225. else
  226. envlist=py27-python
  227. fi
  228. tox -e $envlist
  229. cd ..
  230. }
  231. build_python_cpp() {
  232. internal_build_cpp
  233. internal_install_python_deps
  234. export LD_LIBRARY_PATH=../src/.libs # for Linux
  235. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  236. cd python
  237. # Only test Python 2.6/3.x on Linux
  238. if [ $(uname -s) == "Linux" ]; then
  239. # py26 is currently disabled due to json_format
  240. envlist=py\{27,33,34\}-cpp
  241. else
  242. envlist=py27-cpp
  243. fi
  244. tox -e $envlist
  245. cd ..
  246. }
  247. build_ruby19() {
  248. internal_build_cpp # For conformance tests.
  249. cd ruby && bash travis-test.sh ruby-1.9 && cd ..
  250. }
  251. build_ruby20() {
  252. internal_build_cpp # For conformance tests.
  253. cd ruby && bash travis-test.sh ruby-2.0 && cd ..
  254. }
  255. build_ruby21() {
  256. internal_build_cpp # For conformance tests.
  257. cd ruby && bash travis-test.sh ruby-2.1 && cd ..
  258. }
  259. build_ruby22() {
  260. internal_build_cpp # For conformance tests.
  261. cd ruby && bash travis-test.sh ruby-2.2 && cd ..
  262. }
  263. build_jruby() {
  264. internal_build_cpp # For conformance tests.
  265. cd ruby && bash travis-test.sh jruby && cd ..
  266. }
  267. build_javascript() {
  268. internal_build_cpp
  269. cd js && npm install && npm test && cd ..
  270. }
  271. # Note: travis currently does not support testing more than one language so the
  272. # .travis.yml cheats and claims to only be cpp. If they add multiple language
  273. # support, this should probably get updated to install steps and/or
  274. # rvm/gemfile/jdk/etc. entries rather than manually doing the work.
  275. # .travis.yml uses matrix.exclude to block the cases where app-get can't be
  276. # use to install things.
  277. # -------- main --------
  278. if [ "$#" -ne 1 ]; then
  279. echo "
  280. Usage: $0 { cpp |
  281. csharp |
  282. java_jdk6 |
  283. java_jdk7 |
  284. java_oracle7 |
  285. javanano_jdk6 |
  286. javanano_jdk7 |
  287. javanano_oracle7 |
  288. objectivec_ios |
  289. objectivec_ios_debug |
  290. objectivec_ios_release |
  291. objectivec_osx |
  292. objectivec_cocoapods_integration |
  293. python |
  294. python_cpp |
  295. ruby19 |
  296. ruby20 |
  297. ruby21 |
  298. ruby22 |
  299. jruby }
  300. "
  301. exit 1
  302. fi
  303. set -e # exit immediately on error
  304. set -x # display all commands
  305. eval "build_$1"