17 from __future__
import print_function
25 run_tests_root = os.path.abspath(
26 os.path.join(os.path.dirname(sys.argv[0]),
'../../../tools/run_tests'))
27 sys.path.append(run_tests_root)
31 _COPYRIGHT =
"""# Copyright 2021 The gRPC Authors
33 # Licensed under the Apache License, Version 2.0 (the "License");
34 # you may not use this file except in compliance with the License.
35 # You may obtain a copy of the License at
37 # http://www.apache.org/licenses/LICENSE-2.0
39 # Unless required by applicable law or agreed to in writing, software
40 # distributed under the License is distributed on an "AS IS" BASIS,
41 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42 # See the License for the specific language governing permissions and
43 # limitations under the License.
48 """Modifies vanilla benchmark scenario config to make it more suitable for running as a unit test."""
50 scenario_json = dict(scenario_json)
51 scenario_json[
'warmup_seconds'] = 0
52 scenario_json[
'benchmark_seconds'] = 1
53 outstanding_rpcs_divisor = 1
54 if scenario_json[
'client_config'][
55 'client_type'] ==
'SYNC_CLIENT' or scenario_json[
'server_config'][
56 'server_type'] ==
'SYNC_SERVER':
58 outstanding_rpcs_divisor = 10
59 scenario_json[
'client_config'][
'outstanding_rpcs_per_channel'] =
max(
60 1, scenario_json[
'client_config'][
'outstanding_rpcs_per_channel'] //
61 outstanding_rpcs_divisor)
65 max_client_channels = 16
66 if scenario_json[
'client_config'][
'rpc_type'] ==
'STREAMING_FROM_SERVER':
69 max_client_channels = 4
71 scenario_json[
'client_config'][
'client_channels'] =
min(
72 max_client_channels, scenario_json[
'client_config'][
'client_channels'])
74 return scenario_config.remove_nonproto_fields(scenario_json)
80 for scenario_json
in scenario_config.CXXLanguage().
scenarios()
81 if 'scalable' in scenario_json.get(
'CATEGORIES', [])
88 for scenario_json
in scenario_config.CXXLanguage().
scenarios()
89 if 'inproc' in scenario_json.get(
'CATEGORIES', [])
94 """Generate .bzl file that defines a variable with JSON scenario configs."""
96 for scenario
in json_scenarios:
97 scenario_name = scenario[
'name']
100 scenarios_json_arg_str =
'\\\'%s\\\'' % json.dumps(
101 {
'scenarios': [scenario]})
102 all_scenarios.append((scenario_name, scenarios_json_arg_str))
104 with open(bzl_filename,
'w')
as f:
107 '"""AUTOGENERATED: configuration of benchmark scenarios to be run as bazel test"""\n\n'
109 f.write(
'%s = {\n' % bzl_variablename)
110 for scenario
in all_scenarios:
111 f.write(
" \"%s\": '%s',\n" % (scenario[0], scenario[1]))