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