Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 1 | #!/bin/bash -eu |
| 2 | # |
| 3 | # Copyright 2014 Google Inc. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | pushd "$(dirname $0)" >/dev/null |
| 18 | test_dir="$(pwd)" |
| 19 | gen_code_path=${test_dir} |
| 20 | runtime_library_dir=${test_dir}/../python |
| 21 | |
| 22 | # Emit Python code for the example schema in the test dir: |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 23 | ${test_dir}/../flatc -p -o ${gen_code_path} -I include_test monster_test.fbs --gen-object-api |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 24 | ${test_dir}/../flatc -p -o ${gen_code_path} -I include_test monster_test.fbs --gen-object-api --gen-onefile |
| 25 | ${test_dir}/../flatc -p -o ${gen_code_path} -I include_test monster_extra.fbs --gen-object-api |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 26 | |
| 27 | # Syntax: run_tests <interpreter> <benchmark vtable dedupes> |
| 28 | # <benchmark read count> <benchmark build count> |
| 29 | interpreters_tested=() |
| 30 | function run_tests() { |
| 31 | if $(which ${1} >/dev/null); then |
| 32 | echo "Testing with interpreter: ${1}" |
| 33 | PYTHONDONTWRITEBYTECODE=1 \ |
| 34 | JYTHONDONTWRITEBYTECODE=1 \ |
| 35 | PYTHONPATH=${runtime_library_dir}:${gen_code_path} \ |
| 36 | JYTHONPATH=${runtime_library_dir}:${gen_code_path} \ |
| 37 | COMPARE_GENERATED_TO_GO=0 \ |
| 38 | COMPARE_GENERATED_TO_JAVA=0 \ |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 39 | $1 py_test.py $2 $3 $4 $5 |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 40 | if [ $1 = python3 ]; then |
| 41 | PYTHONDONTWRITEBYTECODE=1 \ |
| 42 | PYTHONPATH=${runtime_library_dir}:${gen_code_path} \ |
| 43 | $1 py_flexbuffers_test.py |
| 44 | fi |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 45 | interpreters_tested+=(${1}) |
| 46 | echo |
| 47 | fi |
| 48 | } |
| 49 | |
| 50 | # Run test suite with these interpreters. The arguments are benchmark counts. |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 51 | run_tests python2.6 100 100 100 false |
| 52 | run_tests python2.7 100 100 100 false |
| 53 | run_tests python2.7 100 100 100 true |
| 54 | run_tests python3 100 100 100 false |
| 55 | run_tests python3 100 100 100 true |
| 56 | run_tests pypy 100 100 100 false |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 57 | |
| 58 | # NOTE: We'd like to support python2.5 in the future. |
| 59 | |
| 60 | # NOTE: Jython 2.7.0 fails due to a bug in the stdlib `struct` library: |
| 61 | # http://bugs.jython.org/issue2188 |
| 62 | |
| 63 | if [ ${#interpreters_tested[@]} -eq 0 ]; then |
| 64 | echo "No Python interpeters found on this system, could not run tests." |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
| 68 | # Run test suite with default python intereter. |
| 69 | # (If the Python program `coverage` is available, it will be run, too. |
| 70 | # Install `coverage` with `pip install coverage`.) |
| 71 | if $(which coverage >/dev/null); then |
| 72 | echo 'Found coverage utility, running coverage with default Python:' |
| 73 | |
| 74 | PYTHONDONTWRITEBYTECODE=1 \ |
| 75 | PYTHONPATH=${runtime_library_dir}:${gen_code_path} \ |
| 76 | coverage run --source=flatbuffers,MyGame py_test.py 0 0 0 > /dev/null |
| 77 | |
| 78 | echo |
| 79 | cov_result=`coverage report --omit="*flatbuffers/vendor*,*py_test*" \ |
| 80 | | tail -n 1 | awk ' { print $4 } '` |
| 81 | echo "Code coverage: ${cov_result}" |
| 82 | else |
| 83 | echo -n "Did not find coverage utility for default Python, skipping. " |
| 84 | echo "Install with 'pip install coverage'." |
| 85 | fi |
| 86 | |
| 87 | echo |
| 88 | echo "OK: all tests passed for ${#interpreters_tested[@]} interpreters: ${interpreters_tested[@]}." |