compatibility_test.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/bin/bash
  2. function use_php() {
  3. VERSION=$1
  4. OLD_PATH=$PATH
  5. OLD_CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH
  6. OLD_C_INCLUDE_PATH=$C_INCLUDE_PATH
  7. export PATH=/usr/local/php-${VERSION}/bin:$OLD_PATH
  8. export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$OLD_CPLUS_INCLUDE_PATH
  9. export C_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$OLD_C_INCLUDE_PATH
  10. }
  11. function generate_proto() {
  12. PROTOC1=$1
  13. PROTOC2=$2
  14. rm -rf generated
  15. mkdir generated
  16. $PROTOC1 --php_out=generated proto/test_include.proto
  17. $PROTOC2 --php_out=generated \
  18. -I../../src -I. \
  19. proto/empty/echo.proto \
  20. proto/test.proto \
  21. proto/test_no_namespace.proto \
  22. proto/test_prefix.proto \
  23. proto/test_php_namespace.proto \
  24. proto/test_empty_php_namespace.proto \
  25. proto/test_reserved_enum_lower.proto \
  26. proto/test_reserved_enum_upper.proto \
  27. proto/test_reserved_enum_value_lower.proto \
  28. proto/test_reserved_enum_value_upper.proto \
  29. proto/test_reserved_message_lower.proto \
  30. proto/test_reserved_message_upper.proto \
  31. proto/test_service.proto \
  32. proto/test_service_namespace.proto \
  33. proto/test_wrapper_type_setters.proto \
  34. proto/test_descriptors.proto
  35. pushd ../../src
  36. $PROTOC2 --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto
  37. popd
  38. }
  39. # Remove tests to expect error. These were added to API tests by mistake.
  40. function remove_error_test() {
  41. local TEMPFILE=`tempfile`
  42. cat $1 | \
  43. awk -v file=`basename $1` -v dir=`basename $(dirname $1)` '
  44. BEGIN {
  45. show = 1
  46. }
  47. /@expectedException PHPUnit_Framework_Error/ { show = 0; next; }
  48. / *\*\// { print; next; }
  49. / *}/ {
  50. if (!show) {
  51. show = 1;
  52. next;
  53. }
  54. }
  55. show { print }
  56. ' > $TEMPFILE
  57. cp $TEMPFILE $1
  58. }
  59. set -ex
  60. # Change to the script's directory.
  61. cd $(dirname $0)
  62. OLD_VERSION=$1
  63. OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/$OLD_VERSION/protoc-$OLD_VERSION-linux-x86_64.exe
  64. # Extract the latest protobuf version number.
  65. VERSION_NUMBER=`grep "PHP_PROTOBUF_VERSION" ../ext/google/protobuf/protobuf.h | sed "s|#define PHP_PROTOBUF_VERSION \"\(.*\)\"|\1|"`
  66. echo "Running compatibility tests between current $VERSION_NUMBER and released $OLD_VERSION"
  67. # Check protoc
  68. [ -f ../../src/protoc ] || {
  69. echo "[ERROR]: Please build protoc first."
  70. exit 1
  71. }
  72. # Download old test.
  73. rm -rf protobuf
  74. git clone https://github.com/protocolbuffers/protobuf.git
  75. pushd protobuf
  76. git checkout v$OLD_VERSION
  77. popd
  78. # Build and copy the new runtime
  79. use_php 7.1
  80. pushd ../ext/google/protobuf
  81. make clean || true
  82. phpize && ./configure && make
  83. popd
  84. rm -rf protobuf/php/ext
  85. rm -rf protobuf/php/src
  86. cp -r ../ext protobuf/php/ext/
  87. cp -r ../src protobuf/php/src/
  88. # Download old version protoc compiler (for linux)
  89. wget $OLD_VERSION_PROTOC -O old_protoc
  90. chmod +x old_protoc
  91. NEW_PROTOC=`pwd`/../../src/protoc
  92. OLD_PROTOC=`pwd`/old_protoc
  93. cd protobuf/php
  94. composer install
  95. # Remove implementation detail tests.
  96. tests=( array_test.php encode_decode_test.php generated_class_test.php map_field_test.php well_known_test.php )
  97. sed -i.bak '/php_implementation_test.php/d' phpunit.xml
  98. sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml
  99. sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh
  100. sed -i.bak 's/generated_service_test.php//g' tests/test.sh
  101. sed -i.bak '/memory_leak_test.php/d' tests/test.sh
  102. sed -i.bak '/^ public function testTimestamp()$/,/^ }$/d' tests/well_known_test.php
  103. sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/array_test.php
  104. sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/map_field_test.php
  105. sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/test_base.php
  106. for t in "${tests[@]}"
  107. do
  108. remove_error_test tests/$t
  109. done
  110. cd tests
  111. # Test A.1:
  112. # proto set 1: use old version
  113. # proto set 2 which may import protos in set 1: use old version
  114. generate_proto $OLD_PROTOC $OLD_PROTOC
  115. ./test.sh
  116. pushd ..
  117. ./vendor/bin/phpunit
  118. popd
  119. # Test A.2:
  120. # proto set 1: use new version
  121. # proto set 2 which may import protos in set 1: use old version
  122. generate_proto $NEW_PROTOC $OLD_PROTOC
  123. ./test.sh
  124. pushd ..
  125. ./vendor/bin/phpunit
  126. popd
  127. # Test A.3:
  128. # proto set 1: use old version
  129. # proto set 2 which may import protos in set 1: use new version
  130. generate_proto $OLD_PROTOC $NEW_PROTOC
  131. ./test.sh
  132. pushd ..
  133. ./vendor/bin/phpunit
  134. popd