1# Copyright 2018 gRPC authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""The Python implementation of the GRPC interoperability test client.""" 15 16import argparse 17import logging 18import sys 19 20from tests.fork import methods 21 22 23def _args(): 24 def parse_bool(value): 25 if value == "true": 26 return True 27 if value == "false": 28 return False 29 raise argparse.ArgumentTypeError("Only true/false allowed") 30 31 parser = argparse.ArgumentParser() 32 parser.add_argument( 33 "--server_host", 34 default="localhost", 35 type=str, 36 help="the host to which to connect", 37 ) 38 parser.add_argument( 39 "--server_port", 40 type=int, 41 required=True, 42 help="the port to which to connect", 43 ) 44 parser.add_argument( 45 "--test_case", 46 default="large_unary", 47 type=str, 48 help="the test case to execute", 49 ) 50 parser.add_argument( 51 "--use_tls", 52 default=False, 53 type=parse_bool, 54 help="require a secure connection", 55 ) 56 return parser.parse_args() 57 58 59def _test_case_from_arg(test_case_arg): 60 for test_case in methods.TestCase: 61 if test_case_arg == test_case.value: 62 return test_case 63 else: 64 raise ValueError('No test case "%s"!' % test_case_arg) 65 66 67def test_fork(): 68 logging.basicConfig(level=logging.INFO) 69 args = vars(_args()) 70 if args["test_case"] == "all": 71 for test_case in methods.TestCase: 72 test_case.run_test(args) 73 else: 74 test_case = _test_case_from_arg(args["test_case"]) 75 test_case.run_test(args) 76 77 78if __name__ == "__main__": 79 test_fork() 80