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