Home | History | Annotate | Download | only in interop_matrix
      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 
     25 set -e
     26 
     27 cd $(dirname $0)/../..
     28 GRPC_ROOT=$(pwd)
     29 CMDS_SH="${GRPC_ROOT}/interop_client_cmds.sh"
     30 TESTCASES_DIR=${GRPC_ROOT}/tools/interop_matrix/testcases
     31 
     32 echo "Create '$LANG' test cases for gRPC release '${RELEASE:=master}'"
     33 
     34 # Clean up
     35 function 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 
     51 function 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.
     55 if [ $1 == "cxx" ]; then
     56 client_lang="c++"
     57 else
     58 client_lang=$1
     59 fi
     60 echo $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 
     65 trap 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 
     70 mkdir -p $TESTCASES_DIR
     71 testcase=$TESTCASES_DIR/$1__$RELEASE
     72 if [ -e $testcase ]; then
     73   echo "Updating: $testcase"
     74   diff $testcase $CMDS_SH || true
     75 fi
     76 mv $CMDS_SH $testcase
     77 chmod a+x $testcase
     78 echo "Test cases created: $testcase"
     79 }
     80 
     81 if [ $LANG == "csharp" ]; then
     82 createtests "csharp"
     83 createtests "csharpcoreclr"
     84 else
     85 createtests $LANG
     86 fi 
     87