tests.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. #!/bin/bash
  2. #
  3. # Build and runs tests for the protobuf project. We use this script to run
  4. # tests on kokoro (Ubuntu and MacOS). It can run locally as well but you
  5. # will need to make sure the required compilers/tools are available.
  6. # For when some other test needs the C++ main build, including protoc and
  7. # libprotobuf.
  8. internal_build_cpp() {
  9. if [ -f src/protoc ]; then
  10. # Already built.
  11. return
  12. fi
  13. # Initialize any submodules.
  14. git submodule update --init --recursive
  15. ./autogen.sh
  16. ./configure CXXFLAGS="-fPIC -std=c++11" # -fPIC is needed for python cpp test.
  17. # See python/setup.py for more details
  18. make -j$(nproc)
  19. }
  20. build_cpp() {
  21. internal_build_cpp
  22. make check -j$(nproc) || (cat src/test-suite.log; false)
  23. cd conformance && make test_cpp && cd ..
  24. # The benchmark code depends on cmake, so test if it is installed before
  25. # trying to do the build.
  26. if [[ $(type cmake 2>/dev/null) ]]; then
  27. # Verify benchmarking code can build successfully.
  28. cd benchmarks && make cpp-benchmark && cd ..
  29. else
  30. echo ""
  31. echo "WARNING: Skipping validation of the bench marking code, cmake isn't installed."
  32. echo ""
  33. fi
  34. }
  35. build_cpp_tcmalloc() {
  36. internal_build_cpp
  37. ./configure LIBS=-ltcmalloc && make clean && make \
  38. PTHREAD_CFLAGS='-pthread -DGOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN' \
  39. check
  40. cd src
  41. PPROF_PATH=/usr/bin/google-pprof HEAPCHECK=strict ./protobuf-test
  42. }
  43. build_cpp_distcheck() {
  44. grep -q -- "-Og" src/Makefile.am &&
  45. echo "The -Og flag is incompatible with Clang versions older than 4.0." &&
  46. exit 1
  47. # Initialize any submodules.
  48. git submodule update --init --recursive
  49. ./autogen.sh
  50. ./configure
  51. make dist
  52. # List all files that should be included in the distribution package.
  53. git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\|src/google/protobuf/.*\.proto\)" |\
  54. grep -v ".gitignore" | grep -v "java/compatibility_tests" |\
  55. grep -v "python/compatibility_tests" | grep -v "csharp/compatibility_tests" > dist.lst
  56. # Unzip the dist tar file.
  57. DIST=`ls *.tar.gz`
  58. tar -xf $DIST
  59. cd ${DIST//.tar.gz}
  60. # Check if every file exists in the dist tar file.
  61. FILES_MISSING=""
  62. for FILE in $(<../dist.lst); do
  63. [ -f "$FILE" ] || {
  64. echo "$FILE is not found!"
  65. FILES_MISSING="$FILE $FILES_MISSING"
  66. }
  67. done
  68. cd ..
  69. if [ ! -z "$FILES_MISSING" ]; then
  70. echo "Missing files in EXTRA_DIST: $FILES_MISSING"
  71. exit 1
  72. fi
  73. # Do the regular dist-check for C++.
  74. make distcheck -j$(nproc)
  75. }
  76. build_dist_install() {
  77. # Initialize any submodules.
  78. git submodule update --init --recursive
  79. ./autogen.sh
  80. ./configure
  81. make dist
  82. # Unzip the dist tar file and install it.
  83. DIST=`ls *.tar.gz`
  84. tar -xf $DIST
  85. pushd ${DIST//.tar.gz}
  86. ./configure && make check -j4 && make install
  87. export LD_LIBRARY_PATH=/usr/local/lib
  88. # Try to install Java
  89. pushd java
  90. use_java jdk7
  91. $MVN install
  92. popd
  93. # Try to install Python
  94. virtualenv --no-site-packages venv
  95. source venv/bin/activate
  96. pushd python
  97. python setup.py clean build sdist
  98. pip install dist/protobuf-*.tar.gz
  99. popd
  100. deactivate
  101. rm -rf python/venv
  102. }
  103. build_csharp() {
  104. # Required for conformance tests and to regenerate protos.
  105. internal_build_cpp
  106. NUGET=/usr/local/bin/nuget.exe
  107. # Disable some unwanted dotnet options
  108. export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
  109. export DOTNET_CLI_TELEMETRY_OPTOUT=true
  110. # TODO(jtattermusch): is this still needed with "first time experience"
  111. # disabled?
  112. # Perform "dotnet new" once to get the setup preprocessing out of the
  113. # way. That spews a lot of output (including backspaces) into logs
  114. # otherwise, and can cause problems. It doesn't matter if this step
  115. # is performed multiple times; it's cheap after the first time anyway.
  116. # (It also doesn't matter if it's unnecessary, which it will be on some
  117. # systems. It's necessary on Jenkins in order to avoid unprintable
  118. # characters appearing in the JUnit output.)
  119. mkdir dotnettmp
  120. (cd dotnettmp; dotnet new > /dev/null)
  121. rm -rf dotnettmp
  122. # Check that the protos haven't broken C# codegen.
  123. # TODO(jonskeet): Fail if regenerating creates any changes.
  124. csharp/generate_protos.sh
  125. csharp/buildall.sh
  126. cd conformance && make test_csharp && cd ..
  127. # Run csharp compatibility test between 3.0.0 and the current version.
  128. csharp/compatibility_tests/v3.0.0/test.sh 3.0.0
  129. }
  130. build_golang() {
  131. # Go build needs `protoc`.
  132. internal_build_cpp
  133. # Add protoc to the path so that the examples build finds it.
  134. export PATH="`pwd`/src:$PATH"
  135. export GOPATH="$HOME/gocode"
  136. mkdir -p "$GOPATH/src/github.com/protocolbuffers"
  137. rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf"
  138. ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf"
  139. export PATH="$GOPATH/bin:$PATH"
  140. go get github.com/golang/protobuf/protoc-gen-go
  141. cd examples && PROTO_PATH="-I../src -I." make gotest && cd ..
  142. }
  143. use_java() {
  144. version=$1
  145. case "$version" in
  146. jdk8)
  147. export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH
  148. export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
  149. ;;
  150. jdk7)
  151. export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
  152. export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
  153. ;;
  154. oracle7)
  155. export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
  156. export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
  157. ;;
  158. esac
  159. MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
  160. MVN="$MVN -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
  161. which java
  162. java -version
  163. $MVN -version
  164. }
  165. # --batch-mode supresses download progress output that spams the logs.
  166. MVN="mvn --batch-mode"
  167. build_java() {
  168. version=$1
  169. dir=java_$version
  170. # Java build needs `protoc`.
  171. internal_build_cpp
  172. cp -r java $dir
  173. cd $dir && $MVN clean && $MVN test
  174. cd ../..
  175. }
  176. # The conformance tests are hard-coded to work with the $ROOT/java directory.
  177. # So this can't run in parallel with two different sets of tests.
  178. build_java_with_conformance_tests() {
  179. # Java build needs `protoc`.
  180. internal_build_cpp
  181. cd java && $MVN test && $MVN install
  182. cd util && $MVN package assembly:single
  183. cd ../..
  184. cd conformance && make test_java && cd ..
  185. }
  186. build_java_jdk7() {
  187. use_java jdk7
  188. build_java_with_conformance_tests
  189. }
  190. build_java_oracle7() {
  191. use_java oracle7
  192. build_java oracle7
  193. }
  194. build_java_compatibility() {
  195. use_java jdk7
  196. internal_build_cpp
  197. # Use the unit-tests extraced from 2.5.0 to test the compatibilty between
  198. # 3.0.0-beta-4 and the current version.
  199. cd java/compatibility_tests/v2.5.0
  200. ./test.sh 3.0.0-beta-4
  201. }
  202. build_java_linkage_monitor() {
  203. # Linkage Monitor checks compatibility with other Google libraries
  204. # https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor
  205. use_java jdk8
  206. internal_build_cpp
  207. # Linkage Monitor uses $HOME/.m2 local repository
  208. MVN="mvn -e -B -Dhttps.protocols=TLSv1.2"
  209. cd java
  210. # Sets java artifact version with SNAPSHOT, as Linkage Monitor looks for SNAPSHOT versions.
  211. # Example: "3.9.0" (without 'rc')
  212. VERSION=`grep '<version>' pom.xml |head -1 |perl -nle 'print $1 if m/<version>(\d+\.\d+.\d+)/'`
  213. cd bom
  214. $MVN versions:set -DnewVersion=${VERSION}-SNAPSHOT
  215. cd ..
  216. $MVN versions:set -DnewVersion=${VERSION}-SNAPSHOT
  217. # Installs the snapshot version locally
  218. $MVN install -Dmaven.test.skip=true
  219. # Linkage Monitor uses the snapshot versions installed in $HOME/.m2 to verify compatibility
  220. JAR=linkage-monitor-latest-all-deps.jar
  221. curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/${JAR}"
  222. # Fails if there's new linkage errors compared with baseline
  223. java -jar $JAR com.google.cloud:libraries-bom
  224. }
  225. build_objectivec_ios() {
  226. # Reused the build script that takes care of configuring and ensuring things
  227. # are up to date. The OS X test runs the objc conformance test, so skip it
  228. # here.
  229. objectivec/DevTools/full_mac_build.sh \
  230. --core-only --skip-xcode-osx --skip-xcode-tvos --skip-objc-conformance "$@"
  231. }
  232. build_objectivec_ios_debug() {
  233. build_objectivec_ios --skip-xcode-release
  234. }
  235. build_objectivec_ios_release() {
  236. build_objectivec_ios --skip-xcode-debug
  237. }
  238. build_objectivec_osx() {
  239. # Reused the build script that takes care of configuring and ensuring things
  240. # are up to date.
  241. objectivec/DevTools/full_mac_build.sh \
  242. --core-only --skip-xcode-ios --skip-xcode-tvos
  243. }
  244. build_objectivec_tvos() {
  245. # Reused the build script that takes care of configuring and ensuring things
  246. # are up to date. The OS X test runs the objc conformance test, so skip it
  247. # here.
  248. objectivec/DevTools/full_mac_build.sh \
  249. --core-only --skip-xcode-ios --skip-xcode-osx --skip-objc-conformance "$@"
  250. }
  251. build_objectivec_tvos_debug() {
  252. build_objectivec_tvos --skip-xcode-release
  253. }
  254. build_objectivec_tvos_release() {
  255. build_objectivec_tvos --skip-xcode-debug
  256. }
  257. build_objectivec_cocoapods_integration() {
  258. # Update pod to the latest version.
  259. gem install cocoapods --no_document
  260. objectivec/Tests/CocoaPods/run_tests.sh
  261. }
  262. build_python() {
  263. internal_build_cpp
  264. cd python
  265. if [ $(uname -s) == "Linux" ]; then
  266. envlist=py\{27,33,34,35,36\}-python
  267. else
  268. envlist=py27-python
  269. fi
  270. tox -e $envlist
  271. cd ..
  272. }
  273. build_python_version() {
  274. internal_build_cpp
  275. cd python
  276. envlist=$1
  277. tox -e $envlist
  278. cd ..
  279. }
  280. build_python27() {
  281. build_python_version py27-python
  282. }
  283. build_python33() {
  284. build_python_version py33-python
  285. }
  286. build_python34() {
  287. build_python_version py34-python
  288. }
  289. build_python35() {
  290. build_python_version py35-python
  291. }
  292. build_python36() {
  293. build_python_version py36-python
  294. }
  295. build_python37() {
  296. build_python_version py37-python
  297. }
  298. build_python_cpp() {
  299. internal_build_cpp
  300. export LD_LIBRARY_PATH=../src/.libs # for Linux
  301. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  302. cd python
  303. if [ $(uname -s) == "Linux" ]; then
  304. envlist=py\{27,33,34,35,36\}-cpp
  305. else
  306. envlist=py27-cpp
  307. fi
  308. tox -e $envlist
  309. cd ..
  310. }
  311. build_python_cpp_version() {
  312. internal_build_cpp
  313. export LD_LIBRARY_PATH=../src/.libs # for Linux
  314. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  315. cd python
  316. envlist=$1
  317. tox -e $envlist
  318. cd ..
  319. }
  320. build_python27_cpp() {
  321. build_python_cpp_version py27-cpp
  322. }
  323. build_python33_cpp() {
  324. build_python_cpp_version py33-cpp
  325. }
  326. build_python34_cpp() {
  327. build_python_cpp_version py34-cpp
  328. }
  329. build_python35_cpp() {
  330. build_python_cpp_version py35-cpp
  331. }
  332. build_python36_cpp() {
  333. build_python_cpp_version py36-cpp
  334. }
  335. build_python37_cpp() {
  336. build_python_cpp_version py37-cpp
  337. }
  338. build_python_compatibility() {
  339. internal_build_cpp
  340. # Use the unit-tests extraced from 2.5.0 to test the compatibilty.
  341. cd python/compatibility_tests/v2.5.0
  342. # Test between 2.5.0 and the current version.
  343. ./test.sh 2.5.0
  344. # Test between 3.0.0-beta-1 and the current version.
  345. ./test.sh 3.0.0-beta-1
  346. }
  347. build_ruby23() {
  348. internal_build_cpp # For conformance tests.
  349. cd ruby && bash travis-test.sh ruby-2.3.8 && cd ..
  350. }
  351. build_ruby24() {
  352. internal_build_cpp # For conformance tests.
  353. cd ruby && bash travis-test.sh ruby-2.4 && cd ..
  354. }
  355. build_ruby25() {
  356. internal_build_cpp # For conformance tests.
  357. cd ruby && bash travis-test.sh ruby-2.5.1 && cd ..
  358. }
  359. build_ruby26() {
  360. internal_build_cpp # For conformance tests.
  361. cd ruby && bash travis-test.sh ruby-2.6.0 && cd ..
  362. }
  363. build_javascript() {
  364. internal_build_cpp
  365. cd js && npm install && npm test && cd ..
  366. cd conformance && make test_nodejs && cd ..
  367. }
  368. generate_php_test_proto() {
  369. internal_build_cpp
  370. pushd php/tests
  371. # Generate test file
  372. rm -rf generated
  373. mkdir generated
  374. ../../src/protoc --php_out=generated \
  375. -I../../src -I. \
  376. proto/empty/echo.proto \
  377. proto/test.proto \
  378. proto/test_include.proto \
  379. proto/test_no_namespace.proto \
  380. proto/test_prefix.proto \
  381. proto/test_php_namespace.proto \
  382. proto/test_empty_php_namespace.proto \
  383. proto/test_reserved_enum_lower.proto \
  384. proto/test_reserved_enum_upper.proto \
  385. proto/test_reserved_enum_value_lower.proto \
  386. proto/test_reserved_enum_value_upper.proto \
  387. proto/test_reserved_message_lower.proto \
  388. proto/test_reserved_message_upper.proto \
  389. proto/test_service.proto \
  390. proto/test_service_namespace.proto \
  391. proto/test_wrapper_type_setters.proto \
  392. proto/test_descriptors.proto
  393. pushd ../../src
  394. ./protoc --php_out=../php/tests/generated -I../php/tests -I. \
  395. ../php/tests/proto/test_import_descriptor_proto.proto
  396. popd
  397. popd
  398. }
  399. use_php() {
  400. VERSION=$1
  401. export PATH=/usr/local/php-${VERSION}/bin:$PATH
  402. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$CPLUS_INCLUDE_PATH
  403. export C_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$C_INCLUDE_PATH
  404. generate_php_test_proto
  405. }
  406. use_php_zts() {
  407. VERSION=$1
  408. export PATH=/usr/local/php-${VERSION}-zts/bin:$PATH
  409. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$CPLUS_INCLUDE_PATH
  410. export C_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$C_INCLUDE_PATH
  411. generate_php_test_proto
  412. }
  413. use_php_bc() {
  414. VERSION=$1
  415. export PATH=/usr/local/php-${VERSION}-bc/bin:$PATH
  416. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$CPLUS_INCLUDE_PATH
  417. export C_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$C_INCLUDE_PATH
  418. generate_php_test_proto
  419. }
  420. build_php5.5() {
  421. use_php 5.5
  422. pushd php
  423. rm -rf vendor
  424. composer update
  425. ./vendor/bin/phpunit
  426. popd
  427. pushd conformance
  428. make test_php
  429. popd
  430. }
  431. build_php5.5_c() {
  432. use_php 5.5
  433. pushd php/tests
  434. /bin/bash ./test.sh 5.5
  435. popd
  436. # TODO(teboring): Add it back
  437. # pushd conformance
  438. # make test_php_c
  439. # popd
  440. }
  441. build_php5.5_mixed() {
  442. use_php 5.5
  443. pushd php
  444. rm -rf vendor
  445. composer update
  446. /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
  447. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  448. popd
  449. }
  450. build_php5.5_zts_c() {
  451. use_php_zts 5.5
  452. cd php/tests && /bin/bash ./test.sh 5.5-zts && cd ../..
  453. # TODO(teboring): Add it back
  454. # pushd conformance
  455. # make test_php_zts_c
  456. # popd
  457. }
  458. build_php5.6() {
  459. use_php 5.6
  460. pushd php
  461. rm -rf vendor
  462. composer update
  463. ./vendor/bin/phpunit
  464. popd
  465. pushd conformance
  466. make test_php
  467. popd
  468. }
  469. build_php5.6_c() {
  470. use_php 5.6
  471. cd php/tests && /bin/bash ./test.sh 5.6 && cd ../..
  472. # TODO(teboring): Add it back
  473. # pushd conformance
  474. # make test_php_c
  475. # popd
  476. }
  477. build_php5.6_mixed() {
  478. use_php 5.6
  479. pushd php
  480. rm -rf vendor
  481. composer update
  482. /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
  483. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  484. popd
  485. }
  486. build_php5.6_zts_c() {
  487. use_php_zts 5.6
  488. cd php/tests && /bin/bash ./test.sh 5.6-zts && cd ../..
  489. # TODO(teboring): Add it back
  490. # pushd conformance
  491. # make test_php_zts_c
  492. # popd
  493. }
  494. build_php5.6_mac() {
  495. generate_php_test_proto
  496. # Install PHP
  497. curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6
  498. PHP_FOLDER=`find /usr/local -type d -name "php5-5.6*"` # The folder name may change upon time
  499. export PATH="$PHP_FOLDER/bin:$PATH"
  500. # Install phpunit
  501. curl https://phar.phpunit.de/phpunit-5.6.8.phar -L -o phpunit.phar
  502. chmod +x phpunit.phar
  503. sudo mv phpunit.phar /usr/local/bin/phpunit
  504. # Install valgrind
  505. echo "#! /bin/bash" > valgrind
  506. chmod ug+x valgrind
  507. sudo mv valgrind /usr/local/bin/valgrind
  508. # Test
  509. cd php/tests && /bin/bash ./test.sh && cd ../..
  510. # TODO(teboring): Add it back
  511. # pushd conformance
  512. # make test_php_c
  513. # popd
  514. }
  515. build_php7.0() {
  516. use_php 7.0
  517. pushd php
  518. rm -rf vendor
  519. composer update
  520. ./vendor/bin/phpunit
  521. popd
  522. pushd conformance
  523. make test_php
  524. popd
  525. }
  526. build_php7.0_c() {
  527. use_php 7.0
  528. cd php/tests && /bin/bash ./test.sh 7.0 && cd ../..
  529. # TODO(teboring): Add it back
  530. # pushd conformance
  531. # make test_php_c
  532. # popd
  533. }
  534. build_php7.0_mixed() {
  535. use_php 7.0
  536. pushd php
  537. rm -rf vendor
  538. composer update
  539. /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
  540. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  541. popd
  542. }
  543. build_php7.0_zts_c() {
  544. use_php_zts 7.0
  545. cd php/tests && /bin/bash ./test.sh 7.0-zts && cd ../..
  546. # TODO(teboring): Add it back.
  547. # pushd conformance
  548. # make test_php_zts_c
  549. # popd
  550. }
  551. build_php7.0_mac() {
  552. generate_php_test_proto
  553. # Install PHP
  554. curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0
  555. PHP_FOLDER=`find /usr/local -type d -name "php7-7.0*"` # The folder name may change upon time
  556. export PATH="$PHP_FOLDER/bin:$PATH"
  557. # Install phpunit
  558. curl https://phar.phpunit.de/phpunit-5.6.0.phar -L -o phpunit.phar
  559. chmod +x phpunit.phar
  560. sudo mv phpunit.phar /usr/local/bin/phpunit
  561. # Install valgrind
  562. echo "#! /bin/bash" > valgrind
  563. chmod ug+x valgrind
  564. sudo mv valgrind /usr/local/bin/valgrind
  565. # Test
  566. cd php/tests && /bin/bash ./test.sh && cd ../..
  567. # TODO(teboring): Add it back
  568. # pushd conformance
  569. # make test_php_c
  570. # popd
  571. }
  572. build_php_compatibility() {
  573. internal_build_cpp
  574. php/tests/compatibility_test.sh
  575. }
  576. build_php7.1() {
  577. use_php 7.1
  578. pushd php
  579. rm -rf vendor
  580. composer update
  581. ./vendor/bin/phpunit
  582. popd
  583. pushd conformance
  584. make test_php
  585. popd
  586. }
  587. build_php7.1_c() {
  588. ENABLE_CONFORMANCE_TEST=$1
  589. use_php 7.1
  590. cd php/tests && /bin/bash ./test.sh 7.1 && cd ../..
  591. if [ "$ENABLE_CONFORMANCE_TEST" = "true" ]
  592. then
  593. pushd conformance
  594. make test_php_c
  595. popd
  596. fi
  597. }
  598. build_php7.1_mixed() {
  599. use_php 7.1
  600. pushd php
  601. rm -rf vendor
  602. composer update
  603. /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
  604. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  605. popd
  606. }
  607. build_php7.1_zts_c() {
  608. use_php_zts 7.1
  609. cd php/tests && /bin/bash ./test.sh 7.1-zts && cd ../..
  610. pushd conformance
  611. # make test_php_c
  612. popd
  613. }
  614. build_php_all_32() {
  615. build_php5.5
  616. build_php5.6
  617. build_php7.0
  618. build_php7.1
  619. build_php5.5_c
  620. build_php5.6_c
  621. build_php7.0_c
  622. build_php7.1_c $1
  623. build_php5.5_mixed
  624. build_php5.6_mixed
  625. build_php7.0_mixed
  626. build_php7.1_mixed
  627. build_php5.5_zts_c
  628. build_php5.6_zts_c
  629. build_php7.0_zts_c
  630. build_php7.1_zts_c
  631. }
  632. build_php_all() {
  633. build_php_all_32 true
  634. build_php_compatibility
  635. }
  636. build_benchmark() {
  637. use_php 7.2
  638. cd kokoro/linux/benchmark && ./run.sh
  639. }
  640. # -------- main --------
  641. if [ "$#" -ne 1 ]; then
  642. echo "
  643. Usage: $0 { cpp |
  644. cpp_distcheck |
  645. csharp |
  646. java_jdk7 |
  647. java_oracle7 |
  648. java_compatibility |
  649. java_linkage_monitor |
  650. objectivec_ios |
  651. objectivec_ios_debug |
  652. objectivec_ios_release |
  653. objectivec_osx |
  654. objectivec_tvos |
  655. objectivec_tvos_debug |
  656. objectivec_tvos_release |
  657. objectivec_cocoapods_integration |
  658. python |
  659. python_cpp |
  660. python_compatibility |
  661. ruby23 |
  662. ruby24 |
  663. ruby25 |
  664. ruby26 |
  665. jruby |
  666. ruby_all |
  667. php5.5 |
  668. php5.5_c |
  669. php5.6 |
  670. php5.6_c |
  671. php7.0 |
  672. php7.0_c |
  673. php_compatibility |
  674. php7.1 |
  675. php7.1_c |
  676. php_all |
  677. dist_install |
  678. benchmark)
  679. "
  680. exit 1
  681. fi
  682. set -e # exit immediately on error
  683. set -x # display all commands
  684. cd $(dirname $0)
  685. eval "build_$1"