tests.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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. mkdir -p "$GOPATH/src/github.com/golang"
  142. rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf"
  143. rm -f "$GOPATH/src/github.com/golang/protobuf"
  144. ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf"
  145. export PATH="$GOPATH/bin:$PATH"
  146. (cd $GOPATH/src/github.com/golang && git clone https://github.com/golang/protobuf.git && cd protobuf && git checkout v1.3.5)
  147. go install github.com/golang/protobuf/protoc-gen-go
  148. cd examples && PROTO_PATH="-I../src -I." make gotest && cd ..
  149. }
  150. use_java() {
  151. version=$1
  152. case "$version" in
  153. jdk8)
  154. export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH
  155. export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
  156. ;;
  157. jdk7)
  158. export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
  159. export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
  160. ;;
  161. oracle7)
  162. export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
  163. export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
  164. ;;
  165. esac
  166. MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
  167. MVN="$MVN -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
  168. which java
  169. java -version
  170. $MVN -version
  171. }
  172. # --batch-mode suppresses download progress output that spams the logs.
  173. MVN="mvn --batch-mode"
  174. build_java() {
  175. version=$1
  176. dir=java_$version
  177. # Java build needs `protoc`.
  178. internal_build_cpp
  179. cp -r java $dir
  180. cd $dir && $MVN clean && $MVN test
  181. cd ../..
  182. }
  183. # The conformance tests are hard-coded to work with the $ROOT/java directory.
  184. # So this can't run in parallel with two different sets of tests.
  185. build_java_with_conformance_tests() {
  186. # Java build needs `protoc`.
  187. internal_build_cpp
  188. # This local installation avoids the problem caused by a new version not yet in Maven Central
  189. cd java/bom && $MVN install
  190. cd ../..
  191. cd java && $MVN test && $MVN install
  192. cd util && $MVN package assembly:single
  193. cd ../..
  194. cd conformance && make test_java && cd ..
  195. }
  196. build_java_jdk7() {
  197. use_java jdk7
  198. build_java_with_conformance_tests
  199. }
  200. build_java_oracle7() {
  201. use_java oracle7
  202. build_java oracle7
  203. }
  204. build_java_compatibility() {
  205. use_java jdk7
  206. internal_build_cpp
  207. # Use the unit-tests extracted from 2.5.0 to test the compatibility between
  208. # 3.0.0-beta-4 and the current version.
  209. cd java/compatibility_tests/v2.5.0
  210. ./test.sh 3.0.0-beta-4
  211. # Test the last released and current version.
  212. ./test.sh $LAST_RELEASED
  213. }
  214. build_java_linkage_monitor() {
  215. # Linkage Monitor checks compatibility with other Google libraries
  216. # https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor
  217. use_java jdk8
  218. internal_build_cpp
  219. # Linkage Monitor uses $HOME/.m2 local repository
  220. MVN="mvn -e -B -Dhttps.protocols=TLSv1.2"
  221. cd java
  222. # Installs the snapshot version locally
  223. $MVN install -Dmaven.test.skip=true
  224. # Linkage Monitor uses the snapshot versions installed in $HOME/.m2 to verify compatibility
  225. JAR=linkage-monitor-latest-all-deps.jar
  226. curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/${JAR}"
  227. # Fails if there's new linkage errors compared with baseline
  228. java -jar $JAR com.google.cloud:libraries-bom
  229. }
  230. build_objectivec_ios() {
  231. # Reused the build script that takes care of configuring and ensuring things
  232. # are up to date. The OS X test runs the objc conformance test, so skip it
  233. # here.
  234. objectivec/DevTools/full_mac_build.sh \
  235. --core-only --skip-xcode-osx --skip-xcode-tvos --skip-objc-conformance "$@"
  236. }
  237. build_objectivec_ios_debug() {
  238. build_objectivec_ios --skip-xcode-release
  239. }
  240. build_objectivec_ios_release() {
  241. build_objectivec_ios --skip-xcode-debug
  242. }
  243. build_objectivec_osx() {
  244. # Reused the build script that takes care of configuring and ensuring things
  245. # are up to date.
  246. objectivec/DevTools/full_mac_build.sh \
  247. --core-only --skip-xcode-ios --skip-xcode-tvos
  248. }
  249. build_objectivec_tvos() {
  250. # Reused the build script that takes care of configuring and ensuring things
  251. # are up to date. The OS X test runs the objc conformance test, so skip it
  252. # here.
  253. objectivec/DevTools/full_mac_build.sh \
  254. --core-only --skip-xcode-ios --skip-xcode-osx --skip-objc-conformance "$@"
  255. }
  256. build_objectivec_tvos_debug() {
  257. build_objectivec_tvos --skip-xcode-release
  258. }
  259. build_objectivec_tvos_release() {
  260. build_objectivec_tvos --skip-xcode-debug
  261. }
  262. build_objectivec_cocoapods_integration() {
  263. # Update pod to the latest version.
  264. gem install cocoapods --no_document
  265. objectivec/Tests/CocoaPods/run_tests.sh
  266. }
  267. build_python() {
  268. internal_build_cpp
  269. cd python
  270. if [ $(uname -s) == "Linux" ]; then
  271. envlist=py\{27,33,34,35,36\}-python
  272. else
  273. envlist=py27-python
  274. fi
  275. tox -e $envlist
  276. cd ..
  277. }
  278. build_python_version() {
  279. internal_build_cpp
  280. cd python
  281. envlist=$1
  282. tox -e $envlist
  283. cd ..
  284. }
  285. build_python27() {
  286. build_python_version py27-python
  287. }
  288. build_python33() {
  289. build_python_version py33-python
  290. }
  291. build_python34() {
  292. build_python_version py34-python
  293. }
  294. build_python35() {
  295. build_python_version py35-python
  296. }
  297. build_python36() {
  298. build_python_version py36-python
  299. }
  300. build_python37() {
  301. build_python_version py37-python
  302. }
  303. build_python38() {
  304. build_python_version py38-python
  305. }
  306. build_python_cpp() {
  307. internal_build_cpp
  308. export LD_LIBRARY_PATH=../src/.libs # for Linux
  309. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  310. cd python
  311. if [ $(uname -s) == "Linux" ]; then
  312. envlist=py\{27,33,34,35,36\}-cpp
  313. else
  314. envlist=py27-cpp
  315. fi
  316. tox -e $envlist
  317. cd ..
  318. }
  319. build_python_cpp_version() {
  320. internal_build_cpp
  321. export LD_LIBRARY_PATH=../src/.libs # for Linux
  322. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  323. cd python
  324. envlist=$1
  325. tox -e $envlist
  326. cd ..
  327. }
  328. build_python27_cpp() {
  329. build_python_cpp_version py27-cpp
  330. }
  331. build_python33_cpp() {
  332. build_python_cpp_version py33-cpp
  333. }
  334. build_python34_cpp() {
  335. build_python_cpp_version py34-cpp
  336. }
  337. build_python35_cpp() {
  338. build_python_cpp_version py35-cpp
  339. }
  340. build_python36_cpp() {
  341. build_python_cpp_version py36-cpp
  342. }
  343. build_python37_cpp() {
  344. build_python_cpp_version py37-cpp
  345. }
  346. build_python38_cpp() {
  347. build_python_cpp_version py38-cpp
  348. }
  349. build_python_compatibility() {
  350. internal_build_cpp
  351. # Use the unit-tests extracted from 2.5.0 to test the compatibility.
  352. cd python/compatibility_tests/v2.5.0
  353. # Test between 2.5.0 and the current version.
  354. ./test.sh 2.5.0
  355. # Test between 3.0.0-beta-1 and the current version.
  356. ./test.sh 3.0.0-beta-1
  357. # Test between last released and current version.
  358. ./test.sh $LAST_RELEASED
  359. }
  360. build_ruby23() {
  361. internal_build_cpp # For conformance tests.
  362. cd ruby && bash travis-test.sh ruby-2.3.8 && cd ..
  363. }
  364. build_ruby24() {
  365. internal_build_cpp # For conformance tests.
  366. cd ruby && bash travis-test.sh ruby-2.4 && cd ..
  367. }
  368. build_ruby25() {
  369. internal_build_cpp # For conformance tests.
  370. cd ruby && bash travis-test.sh ruby-2.5.1 && cd ..
  371. }
  372. build_ruby26() {
  373. internal_build_cpp # For conformance tests.
  374. cd ruby && bash travis-test.sh ruby-2.6.0 && cd ..
  375. }
  376. build_ruby27() {
  377. internal_build_cpp # For conformance tests.
  378. cd ruby && bash travis-test.sh ruby-2.7.0 && cd ..
  379. }
  380. build_javascript() {
  381. internal_build_cpp
  382. NODE_VERSION=node-v12.16.3-darwin-x64
  383. NODE_TGZ="$NODE_VERSION.tar.gz"
  384. pushd /tmp
  385. curl -OL https://nodejs.org/dist/v12.16.3/$NODE_TGZ
  386. tar zxvf $NODE_TGZ
  387. export PATH=$PATH:`pwd`/$NODE_VERSION/bin
  388. popd
  389. cd js && npm install && npm test && cd ..
  390. cd conformance && make test_nodejs && cd ..
  391. }
  392. generate_php_test_proto() {
  393. internal_build_cpp
  394. pushd php/tests
  395. # Generate test file
  396. rm -rf generated
  397. mkdir generated
  398. ../../src/protoc --php_out=generated \
  399. -I../../src -I. \
  400. proto/empty/echo.proto \
  401. proto/test.proto \
  402. proto/test_include.proto \
  403. proto/test_no_namespace.proto \
  404. proto/test_prefix.proto \
  405. proto/test_php_namespace.proto \
  406. proto/test_empty_php_namespace.proto \
  407. proto/test_reserved_enum_lower.proto \
  408. proto/test_reserved_enum_upper.proto \
  409. proto/test_reserved_enum_value_lower.proto \
  410. proto/test_reserved_enum_value_upper.proto \
  411. proto/test_reserved_message_lower.proto \
  412. proto/test_reserved_message_upper.proto \
  413. proto/test_service.proto \
  414. proto/test_service_namespace.proto \
  415. proto/test_wrapper_type_setters.proto \
  416. proto/test_descriptors.proto
  417. pushd ../../src
  418. ./protoc --php_out=../php/tests/generated -I../php/tests -I. \
  419. ../php/tests/proto/test_import_descriptor_proto.proto
  420. popd
  421. popd
  422. }
  423. use_php() {
  424. VERSION=$1
  425. export PATH=/usr/local/php-${VERSION}/bin:$PATH
  426. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$CPLUS_INCLUDE_PATH
  427. export C_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$C_INCLUDE_PATH
  428. generate_php_test_proto
  429. }
  430. use_php_zts() {
  431. VERSION=$1
  432. export PATH=/usr/local/php-${VERSION}-zts/bin:$PATH
  433. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$CPLUS_INCLUDE_PATH
  434. export C_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$C_INCLUDE_PATH
  435. generate_php_test_proto
  436. }
  437. use_php_bc() {
  438. VERSION=$1
  439. export PATH=/usr/local/php-${VERSION}-bc/bin:$PATH
  440. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$CPLUS_INCLUDE_PATH
  441. export C_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$C_INCLUDE_PATH
  442. generate_php_test_proto
  443. }
  444. build_php5.5() {
  445. use_php 5.5
  446. pushd php
  447. rm -rf vendor
  448. composer update
  449. ./vendor/bin/phpunit
  450. popd
  451. pushd conformance
  452. make test_php
  453. popd
  454. }
  455. build_php5.5_c() {
  456. IS_64BIT=$1
  457. use_php 5.5
  458. pushd php/tests
  459. /bin/bash ./test.sh 5.5
  460. popd
  461. pushd conformance
  462. if [ "$IS_64BIT" = "true" ]
  463. then
  464. make test_php_c
  465. else
  466. make test_php_c_32
  467. fi
  468. popd
  469. }
  470. build_php5.5_mixed() {
  471. use_php 5.5
  472. pushd php
  473. rm -rf vendor
  474. composer update
  475. pushd tests
  476. /bin/bash ./compile_extension.sh 5.5
  477. popd
  478. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  479. popd
  480. }
  481. build_php5.5_zts_c() {
  482. IS_64BIT=$1
  483. use_php_zts 5.5
  484. cd php/tests && /bin/bash ./test.sh 5.5-zts && cd ../..
  485. pushd conformance
  486. if [ "$IS_64BIT" = "true" ]
  487. then
  488. make test_php_c
  489. else
  490. make test_php_c_32
  491. fi
  492. popd
  493. }
  494. build_php5.6() {
  495. use_php 5.6
  496. pushd php
  497. rm -rf vendor
  498. composer update
  499. ./vendor/bin/phpunit
  500. popd
  501. pushd conformance
  502. make test_php
  503. popd
  504. }
  505. build_php5.6_c() {
  506. IS_64BIT=$1
  507. use_php 5.6
  508. cd php/tests && /bin/bash ./test.sh 5.6 && cd ../..
  509. pushd conformance
  510. if [ "$IS_64BIT" = "true" ]
  511. then
  512. make test_php_c
  513. else
  514. make test_php_c_32
  515. fi
  516. popd
  517. }
  518. build_php5.6_mixed() {
  519. use_php 5.6
  520. pushd php
  521. rm -rf vendor
  522. composer update
  523. pushd tests
  524. /bin/bash ./compile_extension.sh 5.6
  525. popd
  526. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  527. popd
  528. }
  529. build_php5.6_zts_c() {
  530. IS_64BIT=$1
  531. use_php_zts 5.6
  532. cd php/tests && /bin/bash ./test.sh 5.6-zts && cd ../..
  533. pushd conformance
  534. if [ "$IS_64BIT" = "true" ]
  535. then
  536. make test_php_c
  537. else
  538. make test_php_c_32
  539. fi
  540. popd
  541. }
  542. build_php5.6_mac() {
  543. generate_php_test_proto
  544. # Install PHP
  545. curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6
  546. PHP_FOLDER=`find /usr/local -type d -name "php5-5.6*"` # The folder name may change upon time
  547. test ! -z "$PHP_FOLDER"
  548. export PATH="$PHP_FOLDER/bin:$PATH"
  549. # Install phpunit
  550. curl https://phar.phpunit.de/phpunit-5.6.8.phar -L -o phpunit.phar
  551. chmod +x phpunit.phar
  552. sudo mv phpunit.phar /usr/local/bin/phpunit
  553. # Install valgrind
  554. echo "#! /bin/bash" > valgrind
  555. chmod ug+x valgrind
  556. sudo mv valgrind /usr/local/bin/valgrind
  557. # Test
  558. cd php/tests && /bin/bash ./test.sh && cd ../..
  559. pushd conformance
  560. make test_php_c
  561. popd
  562. }
  563. build_php7.0() {
  564. use_php 7.0
  565. pushd php
  566. rm -rf vendor
  567. composer update
  568. ./vendor/bin/phpunit
  569. popd
  570. pushd conformance
  571. make test_php
  572. popd
  573. }
  574. build_php7.0_c() {
  575. IS_64BIT=$1
  576. use_php 7.0
  577. cd php/tests && /bin/bash ./test.sh 7.0 && cd ../..
  578. pushd conformance
  579. if [ "$IS_64BIT" = "true" ]
  580. then
  581. make test_php_c
  582. else
  583. make test_php_c_32
  584. fi
  585. popd
  586. }
  587. build_php7.0_mixed() {
  588. use_php 7.0
  589. pushd php
  590. rm -rf vendor
  591. composer update
  592. pushd tests
  593. /bin/bash ./compile_extension.sh 7.0
  594. popd
  595. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  596. popd
  597. }
  598. build_php7.0_zts_c() {
  599. IS_64BIT=$1
  600. use_php_zts 7.0
  601. cd php/tests && /bin/bash ./test.sh 7.0-zts && cd ../..
  602. pushd conformance
  603. if [ "$IS_64BIT" = "true" ]
  604. then
  605. make test_php_c
  606. else
  607. make test_php_c_32
  608. fi
  609. popd
  610. }
  611. build_php7.0_mac() {
  612. generate_php_test_proto
  613. # Install PHP
  614. curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0
  615. PHP_FOLDER=`find /usr/local -type d -name "php5-7.0*"` # The folder name may change upon time
  616. test ! -z "$PHP_FOLDER"
  617. export PATH="$PHP_FOLDER/bin:$PATH"
  618. # Install phpunit
  619. curl https://phar.phpunit.de/phpunit-5.6.0.phar -L -o phpunit.phar
  620. chmod +x phpunit.phar
  621. sudo mv phpunit.phar /usr/local/bin/phpunit
  622. # Install valgrind
  623. echo "#! /bin/bash" > valgrind
  624. chmod ug+x valgrind
  625. sudo mv valgrind /usr/local/bin/valgrind
  626. # Test
  627. cd php/tests && /bin/bash ./test.sh && cd ../..
  628. pushd conformance
  629. make test_php_c
  630. popd
  631. }
  632. build_php7.3_mac() {
  633. generate_php_test_proto
  634. # Install PHP
  635. # We can't test PHP 7.4 with these binaries yet:
  636. # https://github.com/liip/php-osx/issues/276
  637. curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
  638. PHP_FOLDER=`find /usr/local -type d -name "php5-7.3*"` # The folder name may change upon time
  639. test ! -z "$PHP_FOLDER"
  640. export PATH="$PHP_FOLDER/bin:$PATH"
  641. # Install phpunit
  642. curl https://phar.phpunit.de/phpunit-8.phar -L -o phpunit.phar
  643. chmod +x phpunit.phar
  644. sudo mv phpunit.phar /usr/local/bin/phpunit
  645. # Install valgrind
  646. echo "#! /bin/bash" > valgrind
  647. chmod ug+x valgrind
  648. sudo mv valgrind /usr/local/bin/valgrind
  649. # Test
  650. cd php/tests && /bin/bash ./test.sh && cd ../..
  651. pushd conformance
  652. make test_php_c
  653. popd
  654. }
  655. build_php_compatibility() {
  656. internal_build_cpp
  657. php/tests/compatibility_test.sh $LAST_RELEASED
  658. }
  659. build_php_multirequest() {
  660. use_php 7.4
  661. pushd php/tests
  662. ./multirequest.sh
  663. popd
  664. }
  665. build_php7.1() {
  666. use_php 7.1
  667. pushd php
  668. rm -rf vendor
  669. composer update
  670. ./vendor/bin/phpunit
  671. popd
  672. pushd conformance
  673. make test_php
  674. popd
  675. }
  676. build_php7.1_c() {
  677. IS_64BIT=$1
  678. use_php 7.1
  679. cd php/tests && /bin/bash ./test.sh 7.1 && cd ../..
  680. pushd conformance
  681. if [ "$IS_64BIT" = "true" ]
  682. then
  683. make test_php_c
  684. else
  685. make test_php_c_32
  686. fi
  687. popd
  688. }
  689. build_php7.1_mixed() {
  690. use_php 7.1
  691. pushd php
  692. rm -rf vendor
  693. composer update
  694. pushd tests
  695. /bin/bash ./compile_extension.sh 7.1
  696. popd
  697. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  698. popd
  699. }
  700. build_php7.1_zts_c() {
  701. IS_64BIT=$1
  702. use_php_zts 7.1
  703. cd php/tests && /bin/bash ./test.sh 7.1-zts && cd ../..
  704. pushd conformance
  705. if [ "$IS_64BIT" = "true" ]
  706. then
  707. make test_php_c
  708. else
  709. make test_php_c_32
  710. fi
  711. popd
  712. }
  713. build_php7.4() {
  714. use_php 7.4
  715. pushd php
  716. rm -rf vendor
  717. composer update
  718. ./vendor/bin/phpunit
  719. popd
  720. pushd conformance
  721. make test_php
  722. popd
  723. }
  724. build_php7.4_c() {
  725. IS_64BIT=$1
  726. use_php 7.4
  727. cd php/tests && /bin/bash ./test.sh 7.4 && cd ../..
  728. pushd conformance
  729. if [ "$IS_64BIT" = "true" ]
  730. then
  731. make test_php_c
  732. else
  733. make test_php_c_32
  734. fi
  735. popd
  736. pushd php/ext/google/protobuf
  737. phpize --clean
  738. popd
  739. }
  740. build_php7.4_mixed() {
  741. use_php 7.4
  742. pushd php
  743. rm -rf vendor
  744. composer update
  745. pushd tests
  746. /bin/bash ./compile_extension.sh 7.4
  747. popd
  748. php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
  749. popd
  750. pushd php/ext/google/protobuf
  751. phpize --clean
  752. popd
  753. }
  754. build_php7.4_zts_c() {
  755. IS_64BIT=$1
  756. use_php_zts 7.4
  757. cd php/tests && /bin/bash ./test.sh 7.4-zts && cd ../..
  758. pushd conformance
  759. if [ "$IS_64BIT" = "true" ]
  760. then
  761. make test_php_c
  762. else
  763. make test_php_c_32
  764. fi
  765. popd
  766. pushd php/ext/google/protobuf
  767. phpize --clean
  768. popd
  769. }
  770. build_php_all_32() {
  771. build_php5.5
  772. build_php5.6
  773. build_php7.0
  774. build_php7.1
  775. build_php7.4
  776. build_php5.5_c $1
  777. build_php5.6_c $1
  778. build_php7.0_c $1
  779. build_php7.1_c $1
  780. build_php7.4_c $1
  781. build_php5.5_mixed
  782. build_php5.6_mixed
  783. build_php7.0_mixed
  784. build_php7.1_mixed
  785. build_php7.4_mixed
  786. build_php5.5_zts_c $1
  787. build_php5.6_zts_c $1
  788. build_php7.0_zts_c $1
  789. build_php7.1_zts_c $1
  790. build_php7.4_zts_c $1
  791. }
  792. build_php_all() {
  793. build_php_all_32 true
  794. build_php_multirequest
  795. build_php_compatibility
  796. }
  797. build_benchmark() {
  798. use_php 7.2
  799. cd kokoro/linux/benchmark && ./run.sh
  800. }
  801. # -------- main --------
  802. if [ "$#" -ne 1 ]; then
  803. echo "
  804. Usage: $0 { cpp |
  805. cpp_distcheck |
  806. csharp |
  807. java_jdk7 |
  808. java_oracle7 |
  809. java_compatibility |
  810. java_linkage_monitor |
  811. objectivec_ios |
  812. objectivec_ios_debug |
  813. objectivec_ios_release |
  814. objectivec_osx |
  815. objectivec_tvos |
  816. objectivec_tvos_debug |
  817. objectivec_tvos_release |
  818. objectivec_cocoapods_integration |
  819. python |
  820. python_cpp |
  821. python_compatibility |
  822. ruby23 |
  823. ruby24 |
  824. ruby25 |
  825. ruby26 |
  826. ruby27 |
  827. jruby |
  828. ruby_all |
  829. php5.5 |
  830. php5.5_c |
  831. php5.6 |
  832. php5.6_c |
  833. php7.0 |
  834. php7.0_c |
  835. php_compatibility |
  836. php7.1 |
  837. php7.1_c |
  838. php_all |
  839. dist_install |
  840. benchmark)
  841. "
  842. exit 1
  843. fi
  844. set -e # exit immediately on error
  845. set -x # display all commands
  846. cd $(dirname $0)
  847. eval "build_$1"