tests.sh 22 KB

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