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