test.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. set -ex
  3. # Change to the script's directory.
  4. cd $(dirname $0)
  5. # Version of the tests (i.e., the version of protobuf from where we extracted
  6. # these tests).
  7. TEST_VERSION=`grep "^ <version>.*</version>" pom.xml | sed "s| <version>\(.*\)</version>|\1|"`
  8. # The old version of protobuf that we are testing compatibility against. This
  9. # is usually the same as TEST_VERSION (i.e., we use the tests extracted from
  10. # that version to test compatibility of the newest runtime against it), but it
  11. # is also possible to use this same test set to test the compatibiilty of the
  12. # latest version against other versions.
  13. case "$1" in
  14. ""|2.5.0)
  15. OLD_VERSION=2.5.0
  16. OLD_VERSION_PROTOC=https://github.com/xfxyjwf/protobuf-compiler-release/raw/master/v2.5.0/linux/protoc
  17. ;;
  18. 2.6.1)
  19. OLD_VERSION=2.6.1
  20. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/2.6.1-build2/protoc-2.6.1-build2-linux-x86_32.exe
  21. ;;
  22. 3.0.0-beta-1)
  23. OLD_VERSION=3.0.0-beta-1
  24. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-1/protoc-3.0.0-beta-1-linux-x86_32.exe
  25. ;;
  26. 3.0.0-beta-2)
  27. OLD_VERSION=3.0.0-beta-2
  28. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-2/protoc-3.0.0-beta-2-linux-x86_32.exe
  29. ;;
  30. *)
  31. echo "[ERROR]: Unknown version number: $1"
  32. exit 1
  33. ;;
  34. esac
  35. # Extract the latest protobuf version number.
  36. VERSION_NUMBER=`grep "^ <version>.*</version>" ../../pom.xml | sed "s| <version>\(.*\)</version>|\1|"`
  37. echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION"
  38. # Check protoc
  39. [ -f ../../../src/protoc ] || {
  40. echo "[ERROR]: Please build protoc first."
  41. exit 1
  42. }
  43. # Build and install protobuf-java-$VERSION_NUMBER.jar
  44. [ -f ../../core/target/protobuf-java-$VERSION_NUMBER.jar ] || {
  45. pushd ../..
  46. mvn install -Dmaven.test.skip=true
  47. popd
  48. }
  49. # Download old version source for the compatibility test
  50. [ -d protobuf ] || {
  51. git clone https://github.com/google/protobuf.git
  52. cd protobuf
  53. git reset --hard v$TEST_VERSION
  54. cd ..
  55. }
  56. # Download old version protoc compiler (for linux)
  57. wget $OLD_VERSION_PROTOC -O protoc
  58. chmod +x protoc
  59. # Test source compatibility. In these tests we recompile everything against
  60. # the new runtime (including old version generated code).
  61. # Test A.1:
  62. # protos: use new version
  63. # more_protos: use old version
  64. mvn clean test \
  65. -Dprotobuf.test.source.path=$(pwd)/protobuf \
  66. -Dprotoc.path=$(pwd)/protoc \
  67. -Dprotos.protoc.path=$(pwd)/../../../src/protoc \
  68. -Dprotobuf.version=$VERSION_NUMBER
  69. # Test A.2:
  70. # protos: use old version
  71. # more_protos: use new version
  72. mvn clean test \
  73. -Dprotobuf.test.source.path=$(pwd)/protobuf \
  74. -Dprotoc.path=$(pwd)/protoc \
  75. -Dmore_protos.protoc.path=$(pwd)/../../../src/protoc \
  76. -Dprotobuf.version=$VERSION_NUMBER
  77. # Test binary compatibility. In these tests we run the old version compiled
  78. # jar against the new runtime directly without recompile.
  79. # Collect all test dependencies in a single jar file (except for protobuf) to
  80. # make it easier to run binary compatibility test (where we will need to run
  81. # the jar files directly).
  82. cd deps
  83. mvn assembly:single
  84. cd ..
  85. cp -f deps/target/compatibility-test-deps-${TEST_VERSION}-jar-with-dependencies.jar deps.jar
  86. # Build the old version of all 3 artifacts.
  87. mvn clean install -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/protoc -Dprotobuf.version=$OLD_VERSION
  88. cp -f protos/target/compatibility-protos-${TEST_VERSION}.jar protos.jar
  89. cp -f more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar more_protos.jar
  90. cp -f tests/target/compatibility-tests-${TEST_VERSION}.jar tests.jar
  91. # Collect the list of tests we need to run.
  92. TESTS=`find tests -name "*Test.java" | sed "s|/|.|g;s/.java$//g;s/tests.src.main.java.//g"`
  93. # Test B.1: run all the old artifacts against the new runtime. Note that we
  94. # must run the test in the protobuf source tree because some of the tests need
  95. # to read golden test data files.
  96. cd protobuf
  97. java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos.jar:../more_protos.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
  98. cd ..
  99. # Test B.2: update protos.jar only.
  100. cd protos
  101. mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
  102. cd ..
  103. cd protobuf
  104. java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos/target/compatibility-protos-${TEST_VERSION}.jar:../more_protos.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
  105. cd ..
  106. # Test B.3: update more_protos.jar only.
  107. cd more_protos
  108. mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
  109. cd ..
  110. cd protobuf
  111. java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos.jar:../more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
  112. cd ..