1#!/bin/bash 2# Copyright 2017 gRPC authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# Creates test cases for a language by running run_interop_test in manual mode 17# and save the generated output under ./testcases/<lang>__<release>. 18# 19# Params: 20# LANG - The language. 21# SKIP_TEST - If set, skip running the test cases for sanity. 22# RELEASE - Create testcase for specific release, defautl to 'master'. 23# KEEP_IMAGE - Do not clean local docker image created for the test cases. 24 25set -e 26 27cd $(dirname $0)/../.. 28GRPC_ROOT=$(pwd) 29CMDS_SH="${GRPC_ROOT}/interop_client_cmds.sh" 30TESTCASES_DIR=${GRPC_ROOT}/tools/interop_matrix/testcases 31 32echo "Create '$LANG' test cases for gRPC release '${RELEASE:=master}'" 33 34# Clean up 35function cleanup { 36 [ -z "$testcase" ] && testcase=$CMDS_SH 37 echo "testcase: $testcase" 38 if [ -e $testcase ]; then 39 # The script should generate a line with "${docker_image:=...}". 40 eval docker_image=$(grep -oe '${docker_image:=.*}' $testcase) 41 if [ -z "$KEEP_IMAGE" ]; then 42 echo "Clean up docker_image $docker_image" 43 docker rmi -f $docker_image 44 else 45 echo "Kept docker_image $docker_image" 46 fi 47 fi 48 [ -e "$CMDS_SH" ] && rm $CMDS_SH 49} 50 51function createtests { 52# Invoke run_interop_test in manual mode. 53# TODO(adelez): Add cloud_gateways when we figure out how to skip them if not 54# running in GCE. 55if [ $1 == "cxx" ]; then 56client_lang="c++" 57else 58client_lang=$1 59fi 60echo $client_lang 61 62${GRPC_ROOT}/tools/run_tests/run_interop_tests.py -l $client_lang --use_docker \ 63 --cloud_to_prod --prod_servers default gateway_v4 --manual_run 64 65trap cleanup EXIT 66# TODO(adelez): add test auth tests but do not run if not testing on GCE. 67# Running the testcases as sanity unless we are asked to skip. 68[ -z "$SKIP_TEST" ] && (echo "Running test cases: $CMDS_SH"; sh $CMDS_SH) 69 70mkdir -p $TESTCASES_DIR 71testcase=$TESTCASES_DIR/$1__$RELEASE 72if [ -e $testcase ]; then 73 echo "Updating: $testcase" 74 diff $testcase $CMDS_SH || true 75fi 76mv $CMDS_SH $testcase 77chmod a+x $testcase 78echo "Test cases created: $testcase" 79} 80 81if [ $LANG == "csharp" ]; then 82createtests "csharp" 83createtests "csharpcoreclr" 84else 85createtests $LANG 86fi 87