compatibility_test.sh 4.3 KB

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