Jie Luo | ea51149 | 2017-01-23 15:11:00 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -ex |
| 4 | |
| 5 | # Change to the script's directory. |
| 6 | cd $(dirname $0) |
| 7 | |
| 8 | # Version of the tests (i.e., the version of protobuf from where we extracted |
| 9 | # these tests). |
| 10 | TEST_VERSION=2.5.0 |
| 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. |
| 17 | case "$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_64.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_64.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_64.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_64.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_64.exe |
| 41 | ;; |
| 42 | *) |
| 43 | echo "[ERROR]: Unknown version number: $1" |
| 44 | exit 1 |
| 45 | ;; |
| 46 | esac |
| 47 | |
| 48 | # Extract the latest protobuf version number. |
| 49 | VERSION_NUMBER=`grep "^__version__ = '.*'" ../../google/protobuf/__init__.py | sed "s|__version__ = '\(.*\)'|\1|"` |
| 50 | |
| 51 | echo "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 | # Test source compatibility. In these tests we recompile everything against |
| 60 | # the new runtime (including old version generated code). |
| 61 | rm google -f -r |
| 62 | mkdir -p google/protobuf/internal |
| 63 | # Build and copy the new runtime |
| 64 | cd ../../ |
| 65 | python setup.py build |
| 66 | cp google/protobuf/*.py compatibility_tests/v2.5.0/google/protobuf/ |
| 67 | cp google/protobuf/internal/*.py compatibility_tests/v2.5.0/google/protobuf/internal/ |
| 68 | cd compatibility_tests/v2.5.0 |
| 69 | cp tests/google/protobuf/internal/test_util.py google/protobuf/internal/ |
| 70 | cp google/protobuf/__init__.py google/ |
| 71 | |
| 72 | # Download old version protoc compiler (for linux) |
| 73 | wget $OLD_VERSION_PROTOC -O old_protoc |
| 74 | chmod +x old_protoc |
| 75 | |
| 76 | # Test A.1: |
| 77 | # proto set 1: use old version |
| 78 | # proto set 2 which may import protos in set 1: use old version |
| 79 | cp old_protoc protoc_1 |
| 80 | cp old_protoc protoc_2 |
| 81 | python setup.py build |
| 82 | python setup.py test |
| 83 | |
| 84 | # Test A.2: |
| 85 | # proto set 1: use new version |
| 86 | # proto set 2 which may import protos in set 1: use old version |
| 87 | cp ../../../src/protoc protoc_1 |
| 88 | cp old_protoc protoc_2 |
| 89 | python setup.py build |
| 90 | python setup.py test |
| 91 | |
| 92 | # Test A.3: |
| 93 | # proto set 1: use old version |
| 94 | # proto set 2 which may import protos in set 1: use new version |
Jie Luo | 42e1e2a | 2017-01-30 15:23:35 -0800 | [diff] [blame] | 95 | cp old_protoc protoc_1 |
| 96 | cp ../../../src/protoc protoc_2 |
| 97 | python setup.py build |
| 98 | python setup.py test |
Jie Luo | ea51149 | 2017-01-23 15:11:00 -0800 | [diff] [blame] | 99 | |
| 100 | rm google -r -f |
| 101 | rm build -r -f |
| 102 | rm protoc_1 |
| 103 | rm protoc_2 |
| 104 | rm old_protoc |