test.sh 4.4 KB

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