Craig Tiller | 83399c9 | 2015-12-14 13:34:44 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | # Copyright 2015 gRPC authors. |
Craig Tiller | 83399c9 | 2015-12-14 13:34:44 -0800 | [diff] [blame] | 4 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | # 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 Tiller | 83399c9 | 2015-12-14 13:34:44 -0800 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
Craig Tiller | 83399c9 | 2015-12-14 13:34:44 -0800 | [diff] [blame] | 10 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | # 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 Tiller | 83399c9 | 2015-12-14 13:34:44 -0800 | [diff] [blame] | 16 | |
| 17 | def 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 | |
| 34 | done = set() |
| 35 | |
| 36 | for 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) |