blob: 8b5b618e8ea33bca6c98ec4507e69556ce6c3bc1 [file] [log] [blame]
Craig Tiller83399c92015-12-14 13:34:44 -08001#!/usr/bin/env python2.7
2
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003# Copyright 2015 gRPC authors.
Craig Tiller83399c92015-12-14 13:34:44 -08004#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
Craig Tiller83399c92015-12-14 13:34:44 -08008#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009# http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller83399c92015-12-14 13:34:44 -080010#
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Craig Tiller83399c92015-12-14 13:34:44 -080016
17def esc_c(line):
18 out = "\""
19 last_was_hex = False
20 for c in line:
21 if 32 <= c < 127:
22 if c in hex_bytes and last_was_hex:
23 out += "\"\""
24 if c != ord('"'):
25 out += chr(c)
26 else:
27 out += "\\\""
28 last_was_hex = False
29 else:
30 out += "\\x%02x" % c
31 last_was_hex = True
32 return out + "\""
33
34done = set()
35
36for message_length in range(0, 3):
37 for send_message_length in range(0, message_length + 1):
38 payload = [
39 0,
40 (message_length >> 24) & 0xff,
41 (message_length >> 16) & 0xff,
42 (message_length >> 8) & 0xff,
43 (message_length) & 0xff
44 ] + send_message_length * [0]
45 for frame_length in range(0, len(payload) + 1):
46 is_end = frame_length == len(payload) and send_message_length == message_length
47 frame = [
48 (frame_length >> 16) & 0xff,
49 (frame_length >> 8) & 0xff,
50 (frame_length) & 0xff,
51 0,
52 1 if is_end else 0,
53 0, 0, 0, 1
54 ] + payload[0:frame_length]
55 text = esc_c(frame)
56 if text not in done:
57 print 'GRPC_RUN_BAD_CLIENT_TEST(verifier_%s, PFX_STR %s, %s);' % (
58 'succeeds' if is_end else 'fails',
59 text,
60 '0' if is_end else 'GRPC_BAD_CLIENT_DISCONNECT')
61 done.add(text)