Craig Tiller | 83399c9 | 2015-12-14 13:34:44 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | |
| 3 | # Copyright 2015, Google Inc. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are |
| 8 | # met: |
| 9 | # |
| 10 | # * Redistributions of source code must retain the above copyright |
| 11 | # notice, this list of conditions and the following disclaimer. |
| 12 | # * Redistributions in binary form must reproduce the above |
| 13 | # copyright notice, this list of conditions and the following disclaimer |
| 14 | # in the documentation and/or other materials provided with the |
| 15 | # distribution. |
| 16 | # * Neither the name of Google Inc. nor the names of its |
| 17 | # contributors may be used to endorse or promote products derived from |
| 18 | # this software without specific prior written permission. |
| 19 | # |
| 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | def esc_c(line): |
| 33 | out = "\"" |
| 34 | last_was_hex = False |
| 35 | for c in line: |
| 36 | if 32 <= c < 127: |
| 37 | if c in hex_bytes and last_was_hex: |
| 38 | out += "\"\"" |
| 39 | if c != ord('"'): |
| 40 | out += chr(c) |
| 41 | else: |
| 42 | out += "\\\"" |
| 43 | last_was_hex = False |
| 44 | else: |
| 45 | out += "\\x%02x" % c |
| 46 | last_was_hex = True |
| 47 | return out + "\"" |
| 48 | |
| 49 | done = set() |
| 50 | |
| 51 | for message_length in range(0, 3): |
| 52 | for send_message_length in range(0, message_length + 1): |
| 53 | payload = [ |
| 54 | 0, |
| 55 | (message_length >> 24) & 0xff, |
| 56 | (message_length >> 16) & 0xff, |
| 57 | (message_length >> 8) & 0xff, |
| 58 | (message_length) & 0xff |
| 59 | ] + send_message_length * [0] |
| 60 | for frame_length in range(0, len(payload) + 1): |
| 61 | is_end = frame_length == len(payload) and send_message_length == message_length |
| 62 | frame = [ |
| 63 | (frame_length >> 16) & 0xff, |
| 64 | (frame_length >> 8) & 0xff, |
| 65 | (frame_length) & 0xff, |
| 66 | 0, |
| 67 | 1 if is_end else 0, |
| 68 | 0, 0, 0, 1 |
| 69 | ] + payload[0:frame_length] |
| 70 | text = esc_c(frame) |
| 71 | if text not in done: |
| 72 | print 'GRPC_RUN_BAD_CLIENT_TEST(verifier_%s, PFX_STR %s, %s);' % ( |
| 73 | 'succeeds' if is_end else 'fails', |
| 74 | text, |
| 75 | '0' if is_end else 'GRPC_BAD_CLIENT_DISCONNECT') |
| 76 | done.add(text) |