tests.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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. LAST_RELEASED=3.9.0
  130. # Run csharp compatibility test between last released and the current version.
  131. csharp/compatibility_tests/v3.0.0/test.sh $LAST_RELEASED
  132. }
  133. build_golang() {
  134. # Go build needs `protoc`.
  135. internal_build_cpp
  136. # Add protoc to the path so that the examples build finds it.
  137. export PATH="`pwd`/src:$PATH"
  138. export GOPATH="$HOME/gocode"
  139. mkdir -p "$GOPATH/src/github.com/protocolbuffers"
  140. rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf"
  141. ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf"
  142. export PATH="$GOPATH/bin:$PATH"
  143. go get github.com/golang/protobuf/protoc-gen-go
  144. cd examples && PROTO_PATH="-I../src -I." make gotest && cd ..
  145. }
  146. use_java() {
  147. version=$1
  148. case "$version" in
  149. jdk8)
  150. export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH
  151. export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
  152. ;;
  153. jdk7)
  154. export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
  155. export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
  156. ;;
  157. oracle7)
  158. export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
  159. export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
  160. ;;
  161. esac
  162. MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
  163. MVN="$MVN -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
  164. which java
  165. java -version
  166. $MVN -version
  167. }
  168. # --batch-mode supresses download progress output that spams the logs.
  169. MVN="mvn --batch-mode"
  170. build_java() {
  171. version=$1
  172. dir=java_$version
  173. # Java build needs `protoc`.
  174. internal_build_cpp
  175. cp -r java $dir
  176. cd $dir && $MVN clean && $MVN test
  177. cd ../..
  178. }
  179. # The conformance tests are hard-coded to work with the $ROOT/java directory.
  180. # So this can't run in parallel with two different sets of tests.
  181. build_java_with_conformance_tests() {
  182. # Java build needs `protoc`.
  183. internal_build_cpp
  184. cd java && $MVN test && $MVN install
  185. cd util && $MVN package assembly:single
  186. cd ../..
  187. cd conformance && make test_java && cd ..
  188. }
  189. build_java_jdk7() {
  190. use_java jdk7
  191. build_java_with_conformance_tests
  192. }
  193. build_java_oracle7() {
  194. use_java oracle7
  195. build_java oracle7
  196. }
  197. build_java_compatibility() {
  198. use_java jdk7
  199. internal_build_cpp
  200. # Use the unit-tests extraced from 2.5.0 to test the compatibilty between
  201. # 3.0.0-beta-4 and the current version.
  202. cd java/compatibility_tests/v2.5.0
  203. ./test.sh 3.0.0-beta-4
  204. }
  205. build_java_linkage_monitor() {
  206. # Linkage Monitor checks compatibility with other Google libraries
  207. # https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor
  208. use_java jdk8
  209. internal_build_cpp
  210. # Linkage Monitor uses $HOME/.m2 local repository
  211. MVN="mvn -e -B -Dhttps.protocols=TLSv1.2"
  212. cd java
  213. # Sets java artifact version with SNAPSHOT, as Linkage Monitor looks for SNAPSHOT versions.
  214. # Example: "3.9.0" (without 'rc')
  215. VERSION=`grep '<version>' pom.xml |head -1 |perl -nle 'print $1 if m/<version>(\d+\.\d+.\d+)/'`
  216. cd bom
  217. $MVN versions:set -DnewVersion=${VERSION}-SNAPSHOT
  218. cd ..
  219. $MVN versions:set -DnewVersion=${VERSION}-SNAPSHOT
  220. # Installs the snapshot version locally
  221. $MVN install -Dmaven.test.skip=true
  222. # Linkage Monitor uses the snapshot versions installed in $HOME/.m2 to verify compatibility
  223. JAR=linkage-monitor-latest-all-deps.jar
  224. curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/${JAR}"
  225. # Fails if there's new linkage errors compared with baseline
  226. java -jar $JAR com.google.cloud:libraries-bom
  227. }
  228. build_objectivec_ios() {
  229. # Reused the build script that takes care of configuring and ensuring things
  230. # are up to date. The OS X test runs the objc conformance test, so skip it
  231. # here.
  232. objectivec/DevTools/full_mac_build.sh \
  233. --core-only --skip-xcode-osx --skip-xcode-tvos --skip-objc-conformance "$@"
  234. }
  235. build_objectivec_ios_debug() {
  236. build_objectivec_ios --skip-xcode-release
  237. }
  238. build_objectivec_ios_release() {
  239. build_objectivec_ios --skip-xcode-debug
  240. }
  241. build_objectivec_osx() {
  242. # Reused the build script that takes care of configuring and ensuring things
  243. # are up to date.
  244. objectivec/DevTools/full_mac_build.sh \
  245. --core-only --skip-xcode-ios --skip-xcode-tvos
  246. }
  247. build_objectivec_tvos() {
  248. # Reused the build script that takes care of configuring and ensuring things
  249. # are up to date. The OS X test runs the objc conformance test, so skip it
  250. # here.
  251. objectivec/DevTools/full_mac_build.sh \
  252. --core-only --skip-xcode-ios --skip-xcode-osx --skip-objc-conformance "$@"
  253. }
  254. build_objectivec_tvos_debug() {
  255. build_objectivec_tvos --skip-xcode-release
  256. }
  257. build_objectivec_tvos_release() {
  258. build_objectivec_tvos --skip-xcode-debug
  259. }
  260. build_objectivec_cocoapods_integration() {
  261. # Update pod to the latest version.
  262. gem install cocoapods --no_document
  263. objectivec/Tests/CocoaPods/run_tests.sh
  264. }
  265. build_python() {
  266. internal_build_cpp
  267. cd python
  268. if [ $(uname -s) == "Linux" ]; then
  269. envlist=py\{27,33,34,35,36\}-python
  270. else
  271. envlist=py27-python
  272. fi
  273. tox -e $envlist
  274. cd ..
  275. }
  276. build_python_version() {
  277. internal_build_cpp
  278. cd python
  279. envlist=$1
  280. tox -e $envlist
  281. cd ..
  282. }
  283. build_python27() {
  284. build_python_version py27-python
  285. }
  286. build_python33() {
  287. build_python_version py33-python
  288. }
  289. build_python34() {
  290. build_python_version py34-python
  291. }
  292. build_python35() {
  293. build_python_version py35-python
  294. }
  295. build_python36() {
  296. build_python_version py36-python
  297. }
  298. build_python37() {
  299. build_python_version py37-python
  300. }
  301. build_python_cpp() {
  302. internal_build_cpp
  303. export LD_LIBRARY_PATH=../src/.libs # for Linux
  304. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  305. cd python
  306. if [ $(uname -s) == "Linux" ]; then
  307. envlist=py\{27,33,34,35,36\}-cpp
  308. else
  309. envlist=py27-cpp
  310. fi
  311. tox -e $envlist
  312. cd ..
  313. }
  314. build_python_cpp_version() {
  315. internal_build_cpp
  316. export LD_LIBRARY_PATH=../src/.libs # for Linux
  317. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  318. cd python
  319. envlist=$1
  320. tox -e $envlist
  321. cd ..
  322. }
  323. build_python27_cpp() {
  324. build_python_cpp_version py27-cpp
  325. }
  326. build_python33_cpp() {
  327. build_python_cpp_version py33-cpp
  328. }
  329. build_python34_cpp() {
  330. build_python_cpp_version py34-cpp
  331. }
  332. build_python35_cpp() {
  333. build_python_cpp_version py35-cpp
  334. }
  335. build_python36_cpp() {
  336. build_python_cpp_version py36-cpp
  337. }
  338. build_python37_cpp() {
  339. build_python_cpp_version py37-cpp
  340. }
  341. build_python_compatibility() {
  342. internal_build_cpp
  343. # Use the unit-tests extraced from 2.5.0 to test the compatibilty.
  344. cd python/compatibility_tests/v2.5.0
  345. # Test between 2.5.0 and the current version.
  346. ./test.sh 2.5.0
  347. # Test between 3.0.0-beta-1 and the current version.
  348. ./test.sh 3.0.0-beta-1
  349. }
  350. build_ruby23() {
  351. internal_build_cpp # For conformance tests.
  352. cd ruby && bash travis-test.sh ruby-2.3.8 && cd ..
  353. }
  354. build_ruby24() {
  355. internal_build_cpp # For conformance tests.
  356. cd ruby && bash travis-test.sh ruby-2.4 && cd ..
  357. }
  358. build_ruby25() {
  359. internal_build_cpp # For conformance tests.
  360. cd ruby && bash travis-test.sh ruby-2.5.1 && cd ..
  361. }
  362. build_ruby26() {
  363. internal_build_cpp # For conformance tests.
  364. cd ruby && bash travis-test.sh ruby-2.6.0 && cd ..
  365. }
  366. build_javascript() {
  367. internal_build_cpp
  368. cd js && npm install && npm test && cd ..
  369. cd conformance && make test_nodejs && cd ..
  370. }
  371. generate_php_test_proto() {
  372. internal_build_cpp
  373. pushd php/tests
  374. # Generate test file
  375. rm -rf generated
  376. mkdir generated
  377. ../../src/protoc --php_out=generated \
  378. -I../../src -I. \
  379. proto/empty/echo.proto \
  380. proto/test.proto \
  381. proto/test_include.proto \
  382. proto/test_no_namespace.proto \
  383. proto/test_prefix.proto \
  384. proto/test_php_namespace.proto \
  385. proto/test_empty_php_namespace.proto \
  386. proto/test_reserved_enum_lower.proto \
  387. proto/test_reserved_enum_upper.proto \
  388. proto/test_reserved_enum_value_lower.proto \
  389. proto/test_reserved_enum_value_upper.proto \
  390. proto/test_reserved_message_lower.proto \
  391. proto/test_reserved_message_upper.proto \
  392. proto/test_service.proto \
  393. proto/test_service_namespace.proto \
  394. proto/test_wrapper_type_setters.proto \
  395. proto/test_descriptors.proto
  396. pushd ../../src
  397. ./protoc --php_out=../php/tests/generated -I../php/tests -I. \
  398. ../php/tests/proto/test_import_descriptor_proto.proto
  399. popd
  400. popd
  401. }
  402. use_php() {
  403. VERSION=$1
  404. export PATH=/usr/local/php-${VERSION}/bin:$PATH
  405. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$CPLUS_INCLUDE_PATH
  406. export C_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$C_INCLUDE_PATH
  407. generate_php_test_proto
  408. }
  409. use_php_zts() {
  410. VERSION=$1
  411. export PATH=/usr/local/php-${VERSION}-zts/bin:$PATH
  412. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$CPLUS_INCLUDE_PATH
  413. export C_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$C_INCLUDE_PATH
  414. generate_php_test_proto
  415. }
  416. use_php_bc() {
  417. VERSION=$1
  418. export PATH=/usr/local/php-${VERSION}-bc/bin:$PATH
  419. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$CPLUS_INCLUDE_PATH
  420. export C_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$C_INCLUDE_PATH
  421. generate_php_test_proto
  422. }
  423. build_php5.5() {
  424. use_php 5.5
  425. pushd php
  426. rm -rf vendor
  427. composer update
  428. ./vendor/bin/phpunit
  429. popd
  430. pushd conformance
  431. make test_php
  432. popd
  433. }
  434. build_php5.5_c() {
  435. use_php 5.5
  436. pushd php/tests
  437. /bin/bash ./test.sh 5.5
  438. popd
  439. # TODO(teboring): Add it back
  440. # pushd conformance
  441. # make test_php_c
  442. # popd
  443. }
  444. build_php5.5_mixed() {
  445. use_php 5.5
  446. pushd php
  447. rm -rf vendor
  448. composer update
  449. /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
  450. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  451. popd
  452. }
  453. build_php5.5_zts_c() {
  454. use_php_zts 5.5
  455. cd php/tests && /bin/bash ./test.sh 5.5-zts && cd ../..
  456. # TODO(teboring): Add it back
  457. # pushd conformance
  458. # make test_php_zts_c
  459. # popd
  460. }
  461. build_php5.6() {
  462. use_php 5.6
  463. pushd php
  464. rm -rf vendor
  465. composer update
  466. ./vendor/bin/phpunit
  467. popd
  468. pushd conformance
  469. make test_php
  470. popd
  471. }
  472. build_php5.6_c() {
  473. use_php 5.6
  474. cd php/tests && /bin/bash ./test.sh 5.6 && cd ../..
  475. # TODO(teboring): Add it back
  476. # pushd conformance
  477. # make test_php_c
  478. # popd
  479. }
  480. build_php5.6_mixed() {
  481. use_php 5.6
  482. pushd php
  483. rm -rf vendor
  484. composer update
  485. /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
  486. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  487. popd
  488. }
  489. build_php5.6_zts_c() {
  490. use_php_zts 5.6
  491. cd php/tests && /bin/bash ./test.sh 5.6-zts && cd ../..
  492. # TODO(teboring): Add it back
  493. # pushd conformance
  494. # make test_php_zts_c
  495. # popd
  496. }
  497. build_php5.6_mac() {
  498. generate_php_test_proto
  499. # Install PHP
  500. curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6
  501. PHP_FOLDER=`find /usr/local -type d -name "php5-5.6*"` # The folder name may change upon time
  502. export PATH="$PHP_FOLDER/bin:$PATH"
  503. # Install phpunit
  504. curl https://phar.phpunit.de/phpunit-5.6.8.phar -L -o phpunit.phar
  505. chmod +x phpunit.phar
  506. sudo mv phpunit.phar /usr/local/bin/phpunit
  507. # Install valgrind
  508. echo "#! /bin/bash" > valgrind
  509. chmod ug+x valgrind
  510. sudo mv valgrind /usr/local/bin/valgrind
  511. # Test
  512. cd php/tests && /bin/bash ./test.sh && cd ../..
  513. # TODO(teboring): Add it back
  514. # pushd conformance
  515. # make test_php_c
  516. # popd
  517. }
  518. build_php7.0() {
  519. use_php 7.0
  520. pushd php
  521. rm -rf vendor
  522. composer update
  523. ./vendor/bin/phpunit
  524. popd
  525. pushd conformance
  526. make test_php
  527. popd
  528. }
  529. build_php7.0_c() {
  530. use_php 7.0
  531. cd php/tests && /bin/bash ./test.sh 7.0 && cd ../..
  532. # TODO(teboring): Add it back
  533. # pushd conformance
  534. # make test_php_c
  535. # popd
  536. }
  537. build_php7.0_mixed() {
  538. use_php 7.0
  539. pushd php
  540. rm -rf vendor
  541. composer update
  542. /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
  543. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  544. popd
  545. }
  546. build_php7.0_zts_c() {
  547. use_php_zts 7.0
  548. cd php/tests && /bin/bash ./test.sh 7.0-zts && cd ../..
  549. # TODO(teboring): Add it back.
  550. # pushd conformance
  551. # make test_php_zts_c
  552. # popd
  553. }
  554. build_php7.0_mac() {
  555. generate_php_test_proto
  556. # Install PHP
  557. curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0
  558. PHP_FOLDER=`find /usr/local -type d -name "php7-7.0*"` # The folder name may change upon time
  559. export PATH="$PHP_FOLDER/bin:$PATH"
  560. # Install phpunit
  561. curl https://phar.phpunit.de/phpunit-5.6.0.phar -L -o phpunit.phar
  562. chmod +x phpunit.phar
  563. sudo mv phpunit.phar /usr/local/bin/phpunit
  564. # Install valgrind
  565. echo "#! /bin/bash" > valgrind
  566. chmod ug+x valgrind
  567. sudo mv valgrind /usr/local/bin/valgrind
  568. # Test
  569. cd php/tests && /bin/bash ./test.sh && cd ../..
  570. # TODO(teboring): Add it back
  571. # pushd conformance
  572. # make test_php_c
  573. # popd
  574. }
  575. build_php_compatibility() {
  576. internal_build_cpp
  577. php/tests/compatibility_test.sh
  578. }
  579. build_php7.1() {
  580. use_php 7.1
  581. pushd php
  582. rm -rf vendor
  583. composer update
  584. ./vendor/bin/phpunit
  585. popd
  586. pushd conformance
  587. make test_php
  588. popd
  589. }
  590. build_php7.1_c() {
  591. ENABLE_CONFORMANCE_TEST=$1
  592. use_php 7.1
  593. cd php/tests && /bin/bash ./test.sh 7.1 && cd ../..
  594. if [ "$ENABLE_CONFORMANCE_TEST" = "true" ]
  595. then
  596. pushd conformance
  597. make test_php_c
  598. popd
  599. fi
  600. }
  601. build_php7.1_mixed() {
  602. use_php 7.1
  603. pushd php
  604. rm -rf vendor
  605. composer update
  606. /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
  607. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  608. popd
  609. }
  610. build_php7.1_zts_c() {
  611. use_php_zts 7.1
  612. cd php/tests && /bin/bash ./test.sh 7.1-zts && cd ../..
  613. pushd conformance
  614. # make test_php_c
  615. popd
  616. }
  617. build_php_all_32() {
  618. build_php5.5
  619. build_php5.6
  620. build_php7.0
  621. build_php7.1
  622. build_php5.5_c
  623. build_php5.6_c
  624. build_php7.0_c
  625. build_php7.1_c $1
  626. build_php5.5_mixed
  627. build_php5.6_mixed
  628. build_php7.0_mixed
  629. build_php7.1_mixed
  630. build_php5.5_zts_c
  631. build_php5.6_zts_c
  632. build_php7.0_zts_c
  633. build_php7.1_zts_c
  634. }
  635. build_php_all() {
  636. build_php_all_32 true
  637. build_php_compatibility
  638. }
  639. build_benchmark() {
  640. use_php 7.2
  641. cd kokoro/linux/benchmark && ./run.sh
  642. }
  643. # -------- main --------
  644. if [ "$#" -ne 1 ]; then
  645. echo "
  646. Usage: $0 { cpp |
  647. cpp_distcheck |
  648. csharp |
  649. java_jdk7 |
  650. java_oracle7 |
  651. java_compatibility |
  652. java_linkage_monitor |
  653. objectivec_ios |
  654. objectivec_ios_debug |
  655. objectivec_ios_release |
  656. objectivec_osx |
  657. objectivec_tvos |
  658. objectivec_tvos_debug |
  659. objectivec_tvos_release |
  660. objectivec_cocoapods_integration |
  661. python |
  662. python_cpp |
  663. python_compatibility |
  664. ruby23 |
  665. ruby24 |
  666. ruby25 |
  667. ruby26 |
  668. jruby |
  669. ruby_all |
  670. php5.5 |
  671. php5.5_c |
  672. php5.6 |
  673. php5.6_c |
  674. php7.0 |
  675. php7.0_c |
  676. php_compatibility |
  677. php7.1 |
  678. php7.1_c |
  679. php_all |
  680. dist_install |
  681. benchmark)
  682. "
  683. exit 1
  684. fi
  685. set -e # exit immediately on error
  686. set -x # display all commands
  687. cd $(dirname $0)
  688. eval "build_$1"