blob: e4dbe8dae654c3bb9aa9abc1430dac470772a106 [file] [log] [blame]
rw48dfc692014-12-16 00:32:11 -08001#!/bin/bash -eu
Wouter van Oortmerssena42a9902016-05-23 13:53:08 -07002#
rw48dfc692014-12-16 00:32:11 -08003# 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
17pushd "$(dirname $0)" >/dev/null
18test_dir="$(pwd)"
19gen_code_path=${test_dir}
20runtime_library_dir=${test_dir}/../python
21
22# Emit Python code for the example schema in the test dir:
Wouter van Oortmerssen22743ca2017-05-24 15:21:26 -070023${test_dir}/../flatc -p -o ${gen_code_path} -I include_test monster_test.fbs
rw48dfc692014-12-16 00:32:11 -080024
25# Syntax: run_tests <interpreter> <benchmark vtable dedupes>
26# <benchmark read count> <benchmark build count>
27interpreters_tested=()
28function run_tests() {
29 if $(which ${1} >/dev/null); then
30 echo "Testing with interpreter: ${1}"
31 PYTHONDONTWRITEBYTECODE=1 \
32 JYTHONDONTWRITEBYTECODE=1 \
33 PYTHONPATH=${runtime_library_dir}:${gen_code_path} \
34 JYTHONPATH=${runtime_library_dir}:${gen_code_path} \
35 COMPARE_GENERATED_TO_GO=0 \
36 COMPARE_GENERATED_TO_JAVA=0 \
37 $1 py_test.py $2 $3 $4
38 interpreters_tested+=(${1})
39 echo
40 fi
41}
42
43# Run test suite with these interpreters. The arguments are benchmark counts.
44run_tests python2.6 100 100 100
45run_tests python2.7 100 100 100
46run_tests python3 100 100 100
47run_tests pypy 100 100 100
48
49# NOTE: We'd like to support python2.5 in the future.
50
51# NOTE: Jython 2.7.0 fails due to a bug in the stdlib `struct` library:
52# http://bugs.jython.org/issue2188
53
54if [ ${#interpreters_tested[@]} -eq 0 ]; then
55 echo "No Python interpeters found on this system, could not run tests."
56 exit 1
57fi
58
59# Run test suite with default python intereter.
60# (If the Python program `coverage` is available, it will be run, too.
61# Install `coverage` with `pip install coverage`.)
62if $(which coverage >/dev/null); then
63 echo 'Found coverage utility, running coverage with default Python:'
64
65 PYTHONDONTWRITEBYTECODE=1 \
66 PYTHONPATH=${runtime_library_dir}:${gen_code_path} \
67 coverage run --source=flatbuffers,MyGame py_test.py 0 0 0 > /dev/null
68
69 echo
70 cov_result=`coverage report --omit="*flatbuffers/vendor*,*py_test*" \
71 | tail -n 1 | awk ' { print $4 } '`
72 echo "Code coverage: ${cov_result}"
73else
74 echo -n "Did not find coverage utility for default Python, skipping. "
75 echo "Install with 'pip install coverage'."
76fi
77
78echo
79echo "OK: all tests passed for ${#interpreters_tested[@]} interpreters: ${interpreters_tested[@]}."