test.sh 5.4 KB

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