test.sh 5.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash

set -ex

# Change to the script's directory.
cd $(dirname $0)

# Version of the tests (i.e., the version of protobuf from where we extracted
# these tests).
TEST_VERSION=`grep "^  <version>.*</version>" pom.xml | sed "s|  <version>\(.*\)</version>|\1|"`

# The old version of protobuf that we are testing compatibility against. This
# 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 16 17 18 19 20 21 22 23
# is also possible to use this same test set to test the compatibiilty of the
# latest version against other versions.
case "$1" in
  ""|2.5.0)
    OLD_VERSION=2.5.0
    OLD_VERSION_PROTOC=https://github.com/xfxyjwf/protobuf-compiler-release/raw/master/v2.5.0/linux/protoc
    ;;
  2.6.1)
    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_64.exe
25 26 27
    ;;
  3.0.0-beta-1)
    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_64.exe
29 30 31
    ;;
  3.0.0-beta-2)
    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_64.exe
33
    ;;
34 35
  3.0.0-beta-3)
    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_64.exe
37 38 39
    ;;
  3.0.0-beta-4)
    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_64.exe
41
    ;;
42 43 44 45 46 47 48 49 50
  *)
    echo "[ERROR]: Unknown version number: $1"
    exit 1
    ;;
esac

# Extract the latest protobuf version number.
VERSION_NUMBER=`grep "^  <version>.*</version>" ../../pom.xml | sed "s|  <version>\(.*\)</version>|\1|"`

51
echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION"
52 53 54 55 56 57 58 59 60 61 62 63 64 65

# Check protoc
[ -f ../../../src/protoc ] || {
  echo "[ERROR]: Please build protoc first."
  exit 1
}

# Build and install protobuf-java-$VERSION_NUMBER.jar
[ -f ../../core/target/protobuf-java-$VERSION_NUMBER.jar ] || {
  pushd ../..
  mvn install -Dmaven.test.skip=true
  popd
}

66
# Download old version source for the compatibility test
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
[ -d protobuf ] || {
  git clone https://github.com/google/protobuf.git
  cd protobuf
  git reset --hard v$TEST_VERSION
  cd ..
}

# Download old version protoc compiler (for linux)
wget $OLD_VERSION_PROTOC -O protoc
chmod +x protoc

# Test source compatibility. In these tests we recompile everything against
# the new runtime (including old version generated code).

# Test A.1:
#   protos: use new version
#   more_protos: use old version
mvn clean test \
  -Dprotobuf.test.source.path=$(pwd)/protobuf \
  -Dprotoc.path=$(pwd)/protoc \
  -Dprotos.protoc.path=$(pwd)/../../../src/protoc \
  -Dprotobuf.version=$VERSION_NUMBER

# Test A.2:
#   protos: use old version
#   more_protos: use new version
mvn clean test \
  -Dprotobuf.test.source.path=$(pwd)/protobuf \
  -Dprotoc.path=$(pwd)/protoc \
  -Dmore_protos.protoc.path=$(pwd)/../../../src/protoc \
  -Dprotobuf.version=$VERSION_NUMBER

# Test binary compatibility. In these tests we run the old version compiled
# jar against the new runtime directly without recompile.

# 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
# the jar files directly).
cd deps
mvn assembly:single
cd ..
cp -f deps/target/compatibility-test-deps-${TEST_VERSION}-jar-with-dependencies.jar deps.jar

# Build the old version of all 3 artifacts.
mvn clean install -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/protoc -Dprotobuf.version=$OLD_VERSION
cp -f protos/target/compatibility-protos-${TEST_VERSION}.jar protos.jar
cp -f more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar more_protos.jar
cp -f tests/target/compatibility-tests-${TEST_VERSION}.jar tests.jar

# Collect the list of tests we need to run.
TESTS=`find tests -name "*Test.java" | sed "s|/|.|g;s/.java$//g;s/tests.src.main.java.//g"`

# Test B.1: run all the old artifacts against the new runtime. Note that we
# must run the test in the protobuf source tree because some of the tests need
# to read golden test data files.
cd protobuf
java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos.jar:../more_protos.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
cd ..

# Test B.2: update protos.jar only.
cd protos
mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
cd ..
cd protobuf
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
cd ..

# Test B.3: update more_protos.jar only.
cd more_protos
mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
cd ..
cd protobuf
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
cd ..