def test_fast_decode2(self): for _ in range(0, X): for buf in data_ira: rcp_message_id = rcp_tlv_def.RCP_MSG_TYPE_IRA rcp_seq = RCPSequence(gcp_msg_def.ManagementREQ, rcp_message_id, 0, rcp_tlv_def.RCP_OPERATION_TYPE_NONE) rcp_seq.buffer = buf parent_fmt = rcp_tlv_def.RCP_SEQ_RCP_MSG_TLV_SET_MAPPING[ rcp_message_id] parent_gpb = config() ret = rcp_seq._fast_decode2(parent_fmt, parent_gpb, 0, len(buf), 0) self.assertEqual(ret, gcp_object.GCPObject.DECODE_DONE) for buf in data_rex: rcp_message_id = rcp_tlv_def.RCP_MSG_TYPE_REX rcp_seq = RCPSequence(gcp_msg_def.ManagementREQ, rcp_message_id, 0, rcp_tlv_def.RCP_OPERATION_TYPE_NONE) rcp_seq.buffer = buf parent_fmt = rcp_tlv_def.RCP_SEQ_RCP_MSG_TLV_SET_MAPPING[ rcp_message_id] parent_gpb = config() ret = rcp_seq._fast_decode2(parent_fmt, parent_gpb, 0, len(buf), 0) self.assertEqual(ret, gcp_object.GCPObject.DECODE_DONE)
def test_fuzzing_fast_decode2(self): if ENABLE_FUZZING <= 0: return class Logger: def error(self, *args): pass def warn(self, *args): pass for n in [0, 0xFF] + range( 1, 0xFE): # run edge cases, then intermediate values for ref_data in data_ira + data_rex + data_ntf: l = len(ref_data) for i in reversed(range(0, l)): buf = ref_data[:] # copy data buf[i] = n # mutate # Decode rcp_message_id = rcp_tlv_def.RCP_MSG_TYPE_REX rcp_seq = RCPSequence(gcp_msg_def.ManagementREQ, rcp_message_id, 0, rcp_tlv_def.RCP_OPERATION_TYPE_NONE) rcp_seq.buffer = buf rcp_seq.logger = Logger() parent_fmt = rcp_tlv_def.RCP_SEQ_RCP_MSG_TLV_SET_MAPPING[ rcp_message_id] parent_gpb = config() #print(n, i) ret = rcp_seq._fast_decode2(parent_fmt, parent_gpb, 0, len(buf), 0) #if ret is gcp_object.GCPObject.DECODE_FAILED: # print(n, i) self.assertTrue(ret in [ gcp_object.GCPObject.DECODE_DONE, gcp_object.GCPObject.DECODE_FRAGMENTED ])