tests.sh 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
  52. echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /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. wget www.nuget.org/NuGet.exe -O nuget.exe
  56. NUGET=../../nuget.exe
  57. fi
  58. (cd csharp/src; mono $NUGET restore)
  59. csharp/buildall.sh
  60. cd conformance && make test_csharp && cd ..
  61. }
  62. build_golang() {
  63. # Go build needs `protoc`.
  64. internal_build_cpp
  65. # Add protoc to the path so that the examples build finds it.
  66. export PATH="`pwd`/src:$PATH"
  67. # Install Go and the Go protobuf compiler plugin.
  68. sudo apt-get update -qq
  69. sudo apt-get install -qq golang
  70. export GOPATH="$HOME/gocode"
  71. mkdir -p "$GOPATH/src/github.com/google"
  72. ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
  73. export PATH="$GOPATH/bin:$PATH"
  74. go get github.com/golang/protobuf/protoc-gen-go
  75. cd examples && make gotest && cd ..
  76. }
  77. use_java() {
  78. version=$1
  79. case "$version" in
  80. jdk6)
  81. on_travis sudo apt-get install openjdk-6-jdk
  82. export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
  83. ;;
  84. jdk7)
  85. on_travis sudo apt-get install openjdk-7-jdk
  86. export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
  87. ;;
  88. oracle7)
  89. if [ "$TRAVIS" == "true" ]; then
  90. sudo apt-get install python-software-properties # for apt-add-repository
  91. echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
  92. sudo debconf-set-selections
  93. yes | sudo apt-add-repository ppa:webupd8team/java
  94. yes | sudo apt-get install oracle-java7-installer
  95. fi;
  96. export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
  97. ;;
  98. esac
  99. if [ "$TRAVIS" != "true" ]; then
  100. MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
  101. MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
  102. fi;
  103. which java
  104. java -version
  105. }
  106. # --batch-mode supresses download progress output that spams the logs.
  107. MVN="mvn --batch-mode"
  108. build_java() {
  109. version=$1
  110. dir=java_$version
  111. # Java build needs `protoc`.
  112. internal_build_cpp
  113. cp -r java $dir
  114. cd $dir && $MVN clean && $MVN test
  115. cd ../..
  116. }
  117. # The conformance tests are hard-coded to work with the $ROOT/java directory.
  118. # So this can't run in parallel with two different sets of tests.
  119. build_java_with_conformance_tests() {
  120. # Java build needs `protoc`.
  121. internal_build_cpp
  122. cd java && $MVN test && $MVN install
  123. cd util && $MVN package assembly:single
  124. cd ../..
  125. cd conformance && make test_java && cd ..
  126. }
  127. build_javanano() {
  128. # Java build needs `protoc`.
  129. internal_build_cpp
  130. cd javanano && $MVN test && cd ..
  131. }
  132. build_java_jdk6() {
  133. use_java jdk6
  134. build_java jdk6
  135. }
  136. build_java_jdk7() {
  137. use_java jdk7
  138. build_java_with_conformance_tests
  139. }
  140. build_java_oracle7() {
  141. use_java oracle7
  142. build_java oracle7
  143. }
  144. build_javanano_jdk6() {
  145. use_java jdk6
  146. build_javanano
  147. }
  148. build_javanano_jdk7() {
  149. use_java jdk7
  150. build_javanano
  151. }
  152. build_javanano_oracle7() {
  153. use_java oracle7
  154. build_javanano
  155. }
  156. internal_install_python_deps() {
  157. if [ "$TRAVIS" != "true" ]; then
  158. return;
  159. fi
  160. # Install tox (OS X doesn't have pip).
  161. if [ $(uname -s) == "Darwin" ]; then
  162. sudo easy_install tox
  163. else
  164. sudo pip install tox
  165. fi
  166. # Only install Python2.6/3.x on Linux.
  167. if [ $(uname -s) == "Linux" ]; then
  168. sudo apt-get install -y python-software-properties # for apt-add-repository
  169. sudo apt-add-repository -y ppa:fkrull/deadsnakes
  170. sudo apt-get update -qq
  171. sudo apt-get install -y python2.6 python2.6-dev
  172. sudo apt-get install -y python3.3 python3.3-dev
  173. sudo apt-get install -y python3.4 python3.4-dev
  174. fi
  175. }
  176. build_objectivec_ios() {
  177. # Reused the build script that takes care of configuring and ensuring things
  178. # are up to date. The OS X test runs the objc conformance test, so skip it
  179. # here.
  180. # Note: travis has xctool installed, and we've looked at using it in the past
  181. # but it has ended up proving unreliable (bugs), an they are removing build
  182. # support in favor of xcbuild (or just xcodebuild).
  183. objectivec/DevTools/full_mac_build.sh \
  184. --core-only --skip-xcode-osx --skip-objc-conformance "$@"
  185. }
  186. build_objectivec_ios_debug() {
  187. build_objectivec_ios --skip-xcode-release
  188. }
  189. build_objectivec_ios_release() {
  190. build_objectivec_ios --skip-xcode-debug
  191. }
  192. build_objectivec_osx() {
  193. # Reused the build script that takes care of configuring and ensuring things
  194. # are up to date.
  195. objectivec/DevTools/full_mac_build.sh \
  196. --core-only --skip-xcode-ios
  197. }
  198. build_python() {
  199. internal_build_cpp
  200. internal_install_python_deps
  201. cd python
  202. # Only test Python 2.6/3.x on Linux
  203. if [ $(uname -s) == "Linux" ]; then
  204. envlist=py\{26,27,33,34\}-python
  205. else
  206. envlist=py27-python
  207. fi
  208. tox -e $envlist
  209. cd ..
  210. }
  211. build_python_cpp() {
  212. internal_build_cpp
  213. internal_install_python_deps
  214. export LD_LIBRARY_PATH=../src/.libs # for Linux
  215. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  216. cd python
  217. # Only test Python 2.6/3.x on Linux
  218. if [ $(uname -s) == "Linux" ]; then
  219. # py26 is currently disabled due to json_format
  220. envlist=py\{27,33,34\}-cpp
  221. else
  222. envlist=py27-cpp
  223. fi
  224. tox -e $envlist
  225. cd ..
  226. }
  227. build_ruby19() {
  228. internal_build_cpp # For conformance tests.
  229. cd ruby && bash travis-test.sh ruby-1.9 && cd ..
  230. }
  231. build_ruby20() {
  232. internal_build_cpp # For conformance tests.
  233. cd ruby && bash travis-test.sh ruby-2.0 && cd ..
  234. }
  235. build_ruby21() {
  236. internal_build_cpp # For conformance tests.
  237. cd ruby && bash travis-test.sh ruby-2.1 && cd ..
  238. }
  239. build_ruby22() {
  240. internal_build_cpp # For conformance tests.
  241. cd ruby && bash travis-test.sh ruby-2.2 && cd ..
  242. }
  243. build_jruby() {
  244. internal_build_cpp # For conformance tests.
  245. cd ruby && bash travis-test.sh jruby && cd ..
  246. }
  247. build_javascript() {
  248. internal_build_cpp
  249. cd js && npm install && npm test && cd ..
  250. }
  251. # Note: travis currently does not support testing more than one language so the
  252. # .travis.yml cheats and claims to only be cpp. If they add multiple language
  253. # support, this should probably get updated to install steps and/or
  254. # rvm/gemfile/jdk/etc. entries rather than manually doing the work.
  255. # .travis.yml uses matrix.exclude to block the cases where app-get can't be
  256. # use to install things.
  257. # -------- main --------
  258. if [ "$#" -ne 1 ]; then
  259. echo "
  260. Usage: $0 { cpp |
  261. csharp |
  262. java_jdk6 |
  263. java_jdk7 |
  264. java_oracle7 |
  265. javanano_jdk6 |
  266. javanano_jdk7 |
  267. javanano_oracle7 |
  268. objectivec_ios |
  269. objectivec_ios_debug |
  270. objectivec_ios_release |
  271. objectivec_osx |
  272. python |
  273. python_cpp |
  274. ruby19 |
  275. ruby20 |
  276. ruby21 |
  277. ruby22 |
  278. jruby }
  279. "
  280. exit 1
  281. fi
  282. set -e # exit immediately on error
  283. set -x # display all commands
  284. eval "build_$1"