aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/codegen/core/gen_static_metadata.py
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2016-04-20 16:38:26 -0700
committerGravatar yang-g <yangg@google.com>2016-04-20 16:38:26 -0700
commite2914023068da2ded0f825cd1790b1c70f14e0a5 (patch)
treeabbade79a6e2b15dbe3748129d80ab3c18b19b9d /tools/codegen/core/gen_static_metadata.py
parent25df28ef75ba99e5d16743be7310c2920ddd8a32 (diff)
parent2aec20120020741ee64fcd22042c2e56d4cf0a5b (diff)
Merge remote-tracking branch 'upstream/master' into proto_comments
Diffstat (limited to 'tools/codegen/core/gen_static_metadata.py')
-rwxr-xr-xtools/codegen/core/gen_static_metadata.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py
index b4ba02bbe5..b38555e355 100755
--- a/tools/codegen/core/gen_static_metadata.py
+++ b/tools/codegen/core/gen_static_metadata.py
@@ -205,6 +205,7 @@ all_elems = sorted(list(all_elems), key=mangle)
args = sys.argv[1:]
H = None
C = None
+D = None
if args:
if 'header' in args:
H = sys.stdout
@@ -214,11 +215,17 @@ if args:
C = sys.stdout
else:
C = open('/dev/null', 'w')
+ if 'dictionary' in args:
+ D = sys.stdout
+ else:
+ D = open('/dev/null', 'w')
else:
H = open(os.path.join(
os.path.dirname(sys.argv[0]), '../../../src/core/lib/transport/static_metadata.h'), 'w')
C = open(os.path.join(
os.path.dirname(sys.argv[0]), '../../../src/core/lib/transport/static_metadata.c'), 'w')
+ D = open(os.path.join(
+ os.path.dirname(sys.argv[0]), '../../../test/core/end2end/fuzzers/hpack.dictionary'), 'w')
# copy-paste copyright notice from this file
with open(sys.argv[0]) as my_source:
@@ -235,6 +242,22 @@ with open(sys.argv[0]) as my_source:
copyright.append(line)
put_banner([H,C], [line[2:].rstrip() for line in copyright])
+
+hex_bytes = [ord(c) for c in "abcdefABCDEF0123456789"]
+
+
+def esc_dict(line):
+ out = "\""
+ for c in line:
+ if 32 <= c < 127:
+ if c != ord('"'):
+ out += chr(c)
+ else:
+ out += "\\\""
+ else:
+ out += "\\x%02X" % c
+ return out + "\""
+
put_banner([H,C],
"""WARNING: Auto-generated code.
@@ -263,6 +286,13 @@ print >>H
print >>C, 'grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT];'
print >>C
+print >>D, '# hpack fuzzing dictionary'
+for i, elem in enumerate(all_strs):
+ print >>D, '%s' % (esc_dict([len(elem)] + [ord(c) for c in elem]))
+for i, elem in enumerate(all_elems):
+ print >>D, '%s' % (esc_dict([0, len(elem[0])] + [ord(c) for c in elem[0]] +
+ [len(elem[1])] + [ord(c) for c in elem[1]]))
+
print >>H, '#define GRPC_STATIC_MDELEM_COUNT %d' % len(all_elems)
print >>H, 'extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];'
print >>H, 'extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];'