test.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_64.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_64.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_64.exe
  29. ;;
  30. 3.0.0-beta-3)
  31. OLD_VERSION=3.0.0-beta-3
  32. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-3/protoc-3.0.0-beta-3-linux-x86_64.exe
  33. ;;
  34. 3.0.0-beta-4)
  35. OLD_VERSION=3.0.0-beta-4
  36. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-4/protoc-3.0.0-beta-4-linux-x86_64.exe
  37. ;;
  38. *)
  39. echo "[ERROR]: Unknown version number: $1"
  40. exit 1
  41. ;;
  42. esac
  43. # Extract the latest protobuf version number.
  44. VERSION_NUMBER=`grep "^ <version>.*</version>" ../../pom.xml | sed "s| <version>\(.*\)</version>|\1|"`
  45. echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION"
  46. # Check protoc
  47. [ -f ../../../src/protoc ] || {
  48. echo "[ERROR]: Please build protoc first."
  49. exit 1
  50. }
  51. # Build and install protobuf-java-$VERSION_NUMBER.jar
  52. [ -f ../../core/target/protobuf-java-$VERSION_NUMBER.jar ] || {
  53. pushd ../..
  54. mvn install -Dmaven.test.skip=true
  55. popd
  56. }
  57. # Download old version source for the compatibility test
  58. [ -d protobuf ] || {
  59. git clone https://github.com/google/protobuf.git
  60. cd protobuf
  61. git reset --hard v$TEST_VERSION
  62. cd ..
  63. }
  64. # Download old version protoc compiler (for linux)
  65. wget $OLD_VERSION_PROTOC -O protoc
  66. chmod +x protoc
  67. # Test source compatibility. In these tests we recompile everything against
  68. # the new runtime (including old version generated code).
  69. # Test A.1:
  70. # protos: use new version
  71. # more_protos: use old version
  72. mvn clean test \
  73. -Dprotobuf.test.source.path=$(pwd)/protobuf \
  74. -Dprotoc.path=$(pwd)/protoc \
  75. -Dprotos.protoc.path=$(pwd)/../../../src/protoc \
  76. -Dprotobuf.version=$VERSION_NUMBER
  77. # Test A.2:
  78. # protos: use old version
  79. # more_protos: use new version
  80. mvn clean test \
  81. -Dprotobuf.test.source.path=$(pwd)/protobuf \
  82. -Dprotoc.path=$(pwd)/protoc \
  83. -Dmore_protos.protoc.path=$(pwd)/../../../src/protoc \
  84. -Dprotobuf.version=$VERSION_NUMBER
  85. # Test binary compatibility. In these tests we run the old version compiled
  86. # jar against the new runtime directly without recompile.
  87. # Collect all test dependencies in a single jar file (except for protobuf) to
  88. # make it easier to run binary compatibility test (where we will need to run
  89. # the jar files directly).
  90. cd deps
  91. mvn assembly:single
  92. cd ..
  93. cp -f deps/target/compatibility-test-deps-${TEST_VERSION}-jar-with-dependencies.jar deps.jar
  94. # Build the old version of all 3 artifacts.
  95. mvn clean install -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/protoc -Dprotobuf.version=$OLD_VERSION
  96. cp -f protos/target/compatibility-protos-${TEST_VERSION}.jar protos.jar
  97. cp -f more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar more_protos.jar
  98. cp -f tests/target/compatibility-tests-${TEST_VERSION}.jar tests.jar
  99. # Collect the list of tests we need to run.
  100. TESTS=`find tests -name "*Test.java" | sed "s|/|.|g;s/.java$//g;s/tests.src.main.java.//g"`
  101. # Test B.1: run all the old artifacts against the new runtime. Note that we
  102. # must run the test in the protobuf source tree because some of the tests need
  103. # to read golden test data files.
  104. cd protobuf
  105. java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos.jar:../more_protos.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
  106. cd ..
  107. # Test B.2: update protos.jar only.
  108. cd protos
  109. mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
  110. cd ..
  111. cd protobuf
  112. 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
  113. cd ..
  114. # Test B.3: update more_protos.jar only.
  115. cd more_protos
  116. mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
  117. cd ..
  118. cd protobuf
  119. 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
  120. cd ..