compatibility_test.sh 3.4 KB

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