1#!/usr/bin/env python2.7
2# Copyright 2015 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
17"""Generates the appropriate build.json data for all the naming tests."""
18
19
20import yaml
21import collections
22import hashlib
23import json
24
25_LOCAL_DNS_SERVER_ADDRESS = '127.0.0.1:15353'
26
27def _append_zone_name(name, zone_name):
28  return '%s.%s' % (name, zone_name)
29
30def _build_expected_addrs_cmd_arg(expected_addrs):
31  out = []
32  for addr in expected_addrs:
33    out.append('%s,%s' % (addr['address'], str(addr['is_balancer'])))
34  return ';'.join(out)
35
36def _resolver_test_cases(resolver_component_data):
37  out = []
38  for test_case in resolver_component_data['resolver_component_tests']:
39    target_name = _append_zone_name(
40        test_case['record_to_resolve'],
41        resolver_component_data['resolver_tests_common_zone_name'])
42    out.append({
43        'test_title': target_name,
44        'arg_names_and_values': [
45            ('target_name', target_name),
46            ('expected_addrs',
47             _build_expected_addrs_cmd_arg(test_case['expected_addrs'])),
48            ('expected_chosen_service_config',
49             (test_case['expected_chosen_service_config'] or '')),
50            ('expected_lb_policy', (test_case['expected_lb_policy'] or '')),
51        ],
52    })
53  return out
54
55def main():
56  resolver_component_data = ''
57  with open('test/cpp/naming/resolver_test_record_groups.yaml') as f:
58    resolver_component_data = yaml.load(f)
59
60  json = {
61      'resolver_tests_common_zone_name': resolver_component_data['resolver_tests_common_zone_name'],
62      'resolver_component_test_cases': _resolver_test_cases(resolver_component_data),
63      'targets': [
64          {
65              'name': 'resolver_component_test' + unsecure_build_config_suffix,
66              'build': 'test',
67              'language': 'c++',
68              'gtest': False,
69              'run': False,
70              'src': ['test/cpp/naming/resolver_component_test.cc'],
71              'platforms': ['linux', 'posix', 'mac', 'windows'],
72              'deps': [
73                  'grpc++_test_util' + unsecure_build_config_suffix,
74                  'grpc_test_util' + unsecure_build_config_suffix,
75                  'gpr_test_util',
76                  'grpc++' + unsecure_build_config_suffix,
77                  'grpc' + unsecure_build_config_suffix,
78                  'gpr',
79                  'grpc++_test_config',
80              ],
81          } for unsecure_build_config_suffix in ['_unsecure', '']
82      ] + [
83          {
84              'name': 'resolver_component_tests_runner_invoker' + unsecure_build_config_suffix,
85              'build': 'test',
86              'language': 'c++',
87              'gtest': False,
88              'run': True,
89              'src': ['test/cpp/naming/resolver_component_tests_runner_invoker.cc'],
90              'platforms': ['linux', 'posix', 'mac'],
91              'deps': [
92                  'grpc++_test_util',
93                  'grpc_test_util',
94                  'gpr_test_util',
95                  'grpc++',
96                  'grpc',
97                  'gpr',
98                  'grpc++_test_config',
99              ],
100              'args': [
101                  '--test_bin_name=resolver_component_test%s' % unsecure_build_config_suffix,
102                  '--running_under_bazel=false',
103              ],
104          } for unsecure_build_config_suffix in ['_unsecure', '']
105      ] + [
106          {
107              'name': 'address_sorting_test' + unsecure_build_config_suffix,
108              'build': 'test',
109              'language': 'c++',
110              'gtest': True,
111              'run': True,
112              'src': ['test/cpp/naming/address_sorting_test.cc'],
113              'platforms': ['linux', 'posix', 'mac', 'windows'],
114              'deps': [
115                  'grpc++_test_util' + unsecure_build_config_suffix,
116                  'grpc_test_util' + unsecure_build_config_suffix,
117                  'gpr_test_util',
118                  'grpc++' + unsecure_build_config_suffix,
119                  'grpc' + unsecure_build_config_suffix,
120                  'gpr',
121                  'grpc++_test_config',
122              ],
123          } for unsecure_build_config_suffix in ['_unsecure', '']
124      ] + [
125          {
126          'name': 'cancel_ares_query_test',
127          'build': 'test',
128          'language': 'c++',
129          'gtest': True,
130          'run': True,
131          'src': ['test/cpp/naming/cancel_ares_query_test.cc'],
132          'platforms': ['linux', 'posix', 'mac', 'windows'],
133          'deps': [
134              'grpc++_test_util',
135              'grpc_test_util',
136              'gpr_test_util',
137              'grpc++',
138              'grpc',
139              'gpr',
140              'grpc++_test_config',
141          ],
142          },
143      ]
144  }
145
146  print(yaml.dump(json))
147
148if __name__ == '__main__':
149  main()
150