diff options
author | IWAMOTO Toshihiro <iwamoto@valinux.co.jp> | 2016-10-07 16:37:59 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-10-12 09:08:55 +0900 |
commit | e8809649e6a5804d2e76a0a71382e1736c191a9b (patch) | |
tree | b5b3dc5c7ecf0a7505c8086a482fde0de26e9571 | |
parent | 6aa4adb0707ed89727b43a17f371b41110132ab5 (diff) |
test_parser: Enable tests for truncated packets
When there are files named "*.truncated%d" in the packet_data directories,
they are treated as special instructions; test method are generated
by truncating wire_msg from corresponding "*.packet" files.
Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/tests/unit/ofproto/test_parser.py | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/ryu/tests/unit/ofproto/test_parser.py b/ryu/tests/unit/ofproto/test_parser.py index dcbee23c..2f9061cc 100644 --- a/ryu/tests/unit/ofproto/test_parser.py +++ b/ryu/tests/unit/ofproto/test_parser.py @@ -29,6 +29,7 @@ from ryu.ofproto import ofproto_v1_3 from ryu.ofproto import ofproto_v1_4 from ryu.ofproto import ofproto_v1_5 from ryu.tests import test_lib +from ryu import exception import json @@ -199,12 +200,18 @@ class Test_Parser(unittest.TestCase): dp = ofproto_protocol.ProtocolDesc(version=version) if has_parser: - msg = ofproto_parser.msg(dp, version, msg_type, msg_len, xid, - wire_msg) - json_dict2 = self._msg_to_jsondict(msg) + try: + msg = ofproto_parser.msg(dp, version, msg_type, msg_len, xid, + wire_msg) + json_dict2 = self._msg_to_jsondict(msg) + except exception.OFPTruncatedMessage as e: + json_dict2 = {'OFPTruncatedMessage': + self._msg_to_jsondict(e.ofpmsg)} # XXXdebug code open(('/tmp/%s.json' % name), 'w').write(json.dumps(json_dict2)) eq_(json_dict, json_dict2) + if 'OFPTruncatedMessage' in json_dict2: + return # json -> OFPxxx -> json xid = json_dict[list(json_dict.keys())[0]].pop('xid', None) @@ -243,7 +250,6 @@ class Test_Parser(unittest.TestCase): def _add_tests(): import os import os.path - import fnmatch import functools this_dir = os.path.dirname(sys.modules[__name__].__file__) @@ -262,11 +268,28 @@ def _add_tests(): jdir = json_dir + '/' + ver n_added = 0 for file in os.listdir(pdir): - if not fnmatch.fnmatch(file, '*.packet'): + if file.endswith('.packet'): + truncated = None + elif '.truncated' in file: + # contents of .truncated files aren't relevant + s1, s2 = file.split('.truncated') + try: + truncated = int(s2) + except ValueError: + continue + file = s1 + '.packet' + else: continue wire_msg = open(pdir + '/' + file, 'rb').read() - json_str = open(jdir + '/' + file + '.json', 'r').read() + if not truncated: + json_str = open(jdir + '/' + file + '.json', 'r').read() + else: + json_str = open(jdir + '/' + file + + '.truncated%d.json' % truncated, 'r').read() + wire_msg = wire_msg[:truncated] method_name = ('test_' + file).replace('-', '_').replace('.', '_') + if truncated: + method_name += '_truncated%d' % truncated def _run(self, name, wire_msg, json_str): print('processing %s ...' % name) |