test.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. set -ex
  3. cd $(dirname $0)
  4. ./generate_protos.sh
  5. ./compile_extension.sh
  6. PHP_VERSION=$(php -r "echo PHP_VERSION;")
  7. TEST_NEW_EXTENSION=true
  8. # Each version of PHPUnit supports a fairly narrow range of PHP versions.
  9. case "$PHP_VERSION" in
  10. 5.*.*)
  11. PHPUNIT=phpunit-5.6.8.phar
  12. TEST_NEW_EXTENSION=false
  13. ;;
  14. 7.0.*|7.1.*|7.2.*)
  15. # Oddly older than for 5.6. Not sure the reason.
  16. PHPUNIT=phpunit-5.6.0.phar
  17. ;;
  18. 7.3.*|7.4.*)
  19. PHPUNIT=phpunit-8.phar
  20. ;;
  21. *)
  22. echo "ERROR: Unknown PHP version $PHP_VERSION"
  23. exit 1
  24. ;;
  25. esac
  26. [ -f $PHPUNIT ] || wget https://phar.phpunit.de/$PHPUNIT
  27. tests=( array_test.php encode_decode_test.php generated_class_test.php map_field_test.php well_known_test.php descriptors_test.php wrapper_type_setters_test.php)
  28. for t in "${tests[@]}"
  29. do
  30. echo "****************************"
  31. echo "* $t"
  32. echo "****************************"
  33. php -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
  34. if [ "$TEST_NEW_EXTENSION" = "true" ]; then
  35. php -dextension=../ext/google/protobuf2/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
  36. fi
  37. echo ""
  38. done
  39. for t in "${tests[@]}"
  40. do
  41. echo "****************************"
  42. echo "* $t persistent"
  43. echo "****************************"
  44. php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
  45. if [ "$TEST_NEW_EXTENSION" = "true" ]; then
  46. php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf2/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
  47. fi
  48. echo ""
  49. done
  50. # # Make sure to run the memory test in debug mode.
  51. # php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
  52. export ZEND_DONT_UNLOAD_MODULES=1
  53. export USE_ZEND_ALLOC=0
  54. valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
  55. valgrind --leak-check=yes php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
  56. if [ "$TEST_NEW_EXTENSION" = "true" ]; then
  57. valgrind --leak-check=yes php -dextension=../ext/google/protobuf2/modules/protobuf.so memory_leak_test.php
  58. valgrind --leak-check=yes php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf2/modules/protobuf.so memory_leak_test.php
  59. fi
  60. # TODO(teboring): Only for debug (phpunit has memory leak which blocks this beging used by
  61. # regresssion test.)
  62. # for t in "${tests[@]}"
  63. # do
  64. # echo "****************************"
  65. # echo "* $t (memory leak)"
  66. # echo "****************************"
  67. # valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
  68. # echo ""
  69. # done