compatibility_test.sh 3.4 KB

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