tests.sh 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. #!/bin/bash
  2. on_travis() {
  3. if [ "$TRAVIS" == "true" ]; then
  4. "$@"
  5. fi
  6. }
  7. # For when some other test needs the C++ main build, including protoc and
  8. # libprotobuf.
  9. internal_build_cpp() {
  10. if [ -f src/protoc ]; then
  11. # Already built.
  12. return
  13. fi
  14. if [[ $(uname -s) == "Linux" && "$TRAVIS" == "true" ]]; then
  15. # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
  16. # decent C++ 11 support in order to compile conformance tests.
  17. sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
  18. sudo apt-get update -qq
  19. sudo apt-get install -qq g++-4.8
  20. export CXX="g++-4.8" CC="gcc-4.8"
  21. fi
  22. ./autogen.sh
  23. ./configure
  24. make $PARALLELISM
  25. }
  26. build_cpp() {
  27. internal_build_cpp
  28. make check $PARALLELISM
  29. cd conformance && make test_cpp && cd ..
  30. }
  31. build_cpp_distcheck() {
  32. ./autogen.sh
  33. ./configure
  34. make distcheck $PARALLELISM
  35. }
  36. build_csharp() {
  37. # Just for the conformance tests. We don't currently
  38. # need to really build protoc, but it's simplest to keep with the
  39. # conventions of the other builds.
  40. internal_build_cpp
  41. NUGET=/usr/local/bin/nuget.exe
  42. if [ "$TRAVIS" == "true" ]; then
  43. # Install latest version of Mono
  44. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
  45. echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
  46. echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
  47. sudo apt-get update -qq
  48. sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
  49. wget www.nuget.org/NuGet.exe -O nuget.exe
  50. NUGET=../../nuget.exe
  51. fi
  52. (cd csharp/src; mono $NUGET restore)
  53. csharp/buildall.sh
  54. cd conformance && make test_csharp && cd ..
  55. }
  56. build_golang() {
  57. # Go build needs `protoc`.
  58. internal_build_cpp
  59. # Add protoc to the path so that the examples build finds it.
  60. export PATH="`pwd`/src:$PATH"
  61. # Install Go and the Go protobuf compiler plugin.
  62. sudo apt-get update -qq
  63. sudo apt-get install -qq golang
  64. export GOPATH="$HOME/gocode"
  65. mkdir -p "$GOPATH/src/github.com/google"
  66. ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
  67. export PATH="$GOPATH/bin:$PATH"
  68. go get github.com/golang/protobuf/protoc-gen-go
  69. cd examples && make gotest && cd ..
  70. }
  71. use_java() {
  72. version=$1
  73. case "$version" in
  74. jdk6)
  75. on_travis sudo apt-get install openjdk-6-jdk
  76. export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
  77. ;;
  78. jdk7)
  79. on_travis sudo apt-get install openjdk-7-jdk
  80. export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
  81. ;;
  82. oracle7)
  83. if [ "$TRAVIS" == "true" ]; then
  84. sudo apt-get install python-software-properties # for apt-add-repository
  85. echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
  86. sudo debconf-set-selections
  87. yes | sudo apt-add-repository ppa:webupd8team/java
  88. yes | sudo apt-get install oracle-java7-installer
  89. fi;
  90. export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
  91. ;;
  92. esac
  93. which java
  94. java -version
  95. }
  96. # --batch-mode supresses download progress output that spams the logs.
  97. MVN="mvn --batch-mode"
  98. build_java() {
  99. # Java build needs `protoc`.
  100. internal_build_cpp
  101. cd java && $MVN test && $MVN install
  102. cd util && $MVN test
  103. cd ../..
  104. }
  105. build_java_with_conformance_tests() {
  106. # Java build needs `protoc`.
  107. internal_build_cpp
  108. cd java && $MVN test && $MVN install
  109. cd util && $MVN test && $MVN assembly:single
  110. cd ../..
  111. cd conformance && make test_java && cd ..
  112. }
  113. build_javanano() {
  114. # Java build needs `protoc`.
  115. internal_build_cpp
  116. cd javanano && $MVN test && cd ..
  117. }
  118. build_java_jdk6() {
  119. use_java jdk6
  120. build_java
  121. }
  122. build_java_jdk7() {
  123. use_java jdk7
  124. build_java_with_conformance_tests
  125. }
  126. build_java_oracle7() {
  127. use_java oracle7
  128. build_java
  129. }
  130. build_javanano_jdk6() {
  131. use_java jdk6
  132. build_javanano
  133. }
  134. build_javanano_jdk7() {
  135. use_java jdk7
  136. build_javanano
  137. }
  138. build_javanano_oracle7() {
  139. use_java oracle7
  140. build_javanano
  141. }
  142. internal_install_python_deps() {
  143. if [ "$TRAVIS" != "true" ]; then
  144. return;
  145. fi
  146. # Install tox (OS X doesn't have pip).
  147. if [ $(uname -s) == "Darwin" ]; then
  148. sudo easy_install tox
  149. else
  150. sudo pip install tox
  151. fi
  152. # Only install Python2.6/3.x on Linux.
  153. if [ $(uname -s) == "Linux" ]; then
  154. sudo apt-get install -y python-software-properties # for apt-add-repository
  155. sudo apt-add-repository -y ppa:fkrull/deadsnakes
  156. sudo apt-get update -qq
  157. sudo apt-get install -y python2.6 python2.6-dev
  158. sudo apt-get install -y python3.3 python3.3-dev
  159. sudo apt-get install -y python3.4 python3.4-dev
  160. fi
  161. }
  162. internal_objectivec_common () {
  163. # Make sure xctool is up to date. Adapted from
  164. # http://docs.travis-ci.com/user/osx-ci-environment/
  165. # We don't use a before_install because we test multiple OSes.
  166. brew update
  167. # xctool 0.2.8 seems to have a bug where it randomly kills tests saying
  168. # they failed. Disabling the updates, but letting it report about being
  169. # updates as a hint that this needs to eventually get re-enabled.
  170. # https://github.com/facebook/xctool/issues/619
  171. # https://github.com/google/protobuf/issues/1232
  172. brew outdated xctool || true
  173. #brew outdated xctool || brew upgrade xctool
  174. # Reused the build script that takes care of configuring and ensuring things
  175. # are up to date. Xcode and conformance tests will be directly invoked.
  176. objectivec/DevTools/full_mac_build.sh \
  177. --core-only --skip-xcode --skip-objc-conformance
  178. }
  179. internal_xctool_debug_and_release() {
  180. # Always use -reporter plain to avoid escape codes in output (makes travis
  181. # logs easier to read).
  182. xctool -reporter plain -configuration Debug "$@"
  183. xctool -reporter plain -configuration Release "$@"
  184. }
  185. build_objectivec_ios() {
  186. internal_objectivec_common
  187. # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
  188. # doesn't support >1 destination, so we have to build first and then run the
  189. # tests one destination at a time.
  190. internal_xctool_debug_and_release \
  191. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  192. -scheme ProtocolBuffers \
  193. -sdk iphonesimulator \
  194. build-tests
  195. IOS_DESTINATIONS=(
  196. "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  197. "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
  198. "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
  199. "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
  200. )
  201. for i in "${IOS_DESTINATIONS[@]}" ; do
  202. internal_xctool_debug_and_release \
  203. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  204. -scheme ProtocolBuffers \
  205. -sdk iphonesimulator \
  206. -destination "${i}" \
  207. run-tests
  208. done
  209. }
  210. build_objectivec_osx() {
  211. internal_objectivec_common
  212. internal_xctool_debug_and_release \
  213. -project objectivec/ProtocolBuffers_OSX.xcodeproj \
  214. -scheme ProtocolBuffers \
  215. -destination "platform=OS X,arch=x86_64" \
  216. test
  217. cd conformance && make test_objc && cd ..
  218. }
  219. build_python() {
  220. internal_build_cpp
  221. internal_install_python_deps
  222. cd python
  223. # Only test Python 2.6/3.x on Linux
  224. if [ $(uname -s) == "Linux" ]; then
  225. envlist=py\{26,27,33,34\}-python
  226. else
  227. envlist=py27-python
  228. fi
  229. tox -e $envlist
  230. cd ..
  231. }
  232. build_python_cpp() {
  233. internal_build_cpp
  234. internal_install_python_deps
  235. export LD_LIBRARY_PATH=../src/.libs # for Linux
  236. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  237. cd python
  238. # Only test Python 2.6/3.x on Linux
  239. if [ $(uname -s) == "Linux" ]; then
  240. # py26 is currently disabled due to json_format
  241. envlist=py\{27,33,34\}-cpp
  242. else
  243. envlist=py27-cpp
  244. fi
  245. tox -e $envlist
  246. cd ..
  247. }
  248. build_ruby19() {
  249. internal_build_cpp # For conformance tests.
  250. cd ruby && bash travis-test.sh ruby-1.9 && cd ..
  251. }
  252. build_ruby20() {
  253. internal_build_cpp # For conformance tests.
  254. cd ruby && bash travis-test.sh ruby-2.0 && cd ..
  255. }
  256. build_ruby21() {
  257. internal_build_cpp # For conformance tests.
  258. cd ruby && bash travis-test.sh ruby-2.1 && cd ..
  259. }
  260. build_ruby22() {
  261. internal_build_cpp # For conformance tests.
  262. cd ruby && bash travis-test.sh ruby-2.2 && cd ..
  263. }
  264. build_jruby() {
  265. internal_build_cpp # For conformance tests.
  266. cd ruby && bash travis-test.sh jruby && cd ..
  267. }
  268. build_javascript() {
  269. internal_build_cpp
  270. cd js && npm install && npm test && cd ..
  271. }
  272. [ -n "${PARALLELISM}" ] && PARALLELISM=-j8
  273. # Note: travis currently does not support testing more than one language so the
  274. # .travis.yml cheats and claims to only be cpp. If they add multiple language
  275. # support, this should probably get updated to install steps and/or
  276. # rvm/gemfile/jdk/etc. entries rather than manually doing the work.
  277. # .travis.yml uses matrix.exclude to block the cases where app-get can't be
  278. # use to install things.
  279. # -------- main --------
  280. # Set value used in tests.sh.
  281. PARALLELISM=-j2
  282. if [ "$#" -ne 1 ]; then
  283. echo "
  284. Usage: $0 { cpp |
  285. csharp |
  286. java_jdk6 |
  287. java_jdk7 |
  288. java_oracle7 |
  289. javanano_jdk6 |
  290. javanano_jdk7 |
  291. javanano_oracle7 |
  292. objectivec_ios |
  293. objectivec_osx |
  294. python |
  295. python_cpp |
  296. ruby19 |
  297. ruby20 |
  298. ruby21 |
  299. ruby22 |
  300. jruby }
  301. "
  302. exit 1
  303. fi
  304. set -e # exit immediately on error
  305. set -x # display all commands
  306. eval "build_$1"