def test_controller_buffer(self): """test that a partial response gets successfully buffered by the controller, then fully read when more data arrives""" gdbmi = GdbController() to_be_buffered = b'^done,BreakpointTable={nr_rows="1",nr_' stream = 'teststream' verbose = False response = gdbmi._get_responses_list(to_be_buffered, stream, verbose) # Nothing should have been parsed yet assert (len(response) == 0) assert (gdbmi._incomplete_output[stream] == to_be_buffered) remaining_gdb_output = b'cols="6"}\n(gdb) \n' response = gdbmi._get_responses_list(remaining_gdb_output, stream, verbose) # Should have parsed response at this point assert (len(response) == 1) r = response[0] assert (r['stream'] == 'teststream') assert (r['type'] == 'result') assert (r['payload'] == { 'BreakpointTable': { 'nr_cols': '6', 'nr_rows': '1' } })
def test_controller_buffer(self): """test that a partial response gets successfully buffered by the controller, then fully read when more data arrives""" gdbmi = GdbController() to_be_buffered = b'^done,BreakpointTable={nr_rows="1",nr_' stream = "teststream" response = gdbmi._get_responses_list(to_be_buffered, stream) # Nothing should have been parsed yet assert len(response) == 0 assert gdbmi._incomplete_output[stream] == to_be_buffered remaining_gdb_output = b'cols="6"}\n(gdb) \n' response = gdbmi._get_responses_list(remaining_gdb_output, stream) # Should have parsed response at this point assert len(response) == 1 r = response[0] assert r["stream"] == "teststream" assert r["type"] == "result" assert r["payload"] == { "BreakpointTable": { "nr_cols": "6", "nr_rows": "1" } }
def test_controller_buffer_randomized(self): """ The following code reads a sample gdb mi stream randomly to ensure partial output is read and that the buffer is working as expected on all streams. """ test_directory = os.path.dirname(os.path.abspath(__file__)) datafile_path = '%s/response_samples.txt' % (test_directory) gdbmi = GdbController() for stream in gdbmi._incomplete_output.keys(): responses = [] with open(datafile_path, 'rb') as f: while(True): n = random.randint(1, 100) # read random number of bytes to simulate incomplete responses gdb_mi_simulated_output = f.read(n) if gdb_mi_simulated_output == b'': break # EOF # let the controller try to parse this additional raw gdb output responses += gdbmi._get_responses_list(gdb_mi_simulated_output, stream, False) assert(len(responses) == 141) # spot check a few assert_match(responses[0], {'message': None, 'type': 'console', 'payload': u'0x00007fe2c5c58920 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81\\n', 'stream': stream}) if not USING_WINDOWS: # can't get this to pass in windows assert_match(responses[71], {'stream': stream, 'message': u'done', 'type': 'result', 'payload': None, 'token': None}) assert_match(responses[82], {'message': None, 'type': 'output', 'payload': u'The inferior program printed this! Can you still parse it?', 'stream': stream}) assert_match(responses[137], {'stream': stream, 'message': u'thread-group-exited', 'type': 'notify', 'payload': {u'exit-code': u'0', u'id': u'i1'}, 'token': None}) assert_match(responses[138], {'stream': stream, 'message': u'thread-group-started', 'type': 'notify', 'payload': {u'pid': u'48337', u'id': u'i1'}, 'token': None}) assert_match(responses[139], {'stream': stream, 'message': u'tsv-created', 'type': 'notify', 'payload': {u'name': 'trace_timestamp', u'initial': '0'}, 'token': None}) assert_match(responses[140], {'stream': stream, 'message': u'tsv-created', 'type': 'notify', 'payload': {u'name': 'trace_timestamp', u'initial': '0'}, 'token': None}) for stream in gdbmi._incomplete_output.keys(): assert(gdbmi._incomplete_output[stream] is None)
def test_controller_buffer_randomized(self): """ The following code reads a sample gdb mi stream randomly to ensure partial output is read and that the buffer is working as expected on all streams. """ test_directory = os.path.dirname(os.path.abspath(__file__)) datafile_path = "%s/response_samples.txt" % (test_directory) gdbmi = GdbController() for stream in gdbmi._incomplete_output.keys(): responses = [] with open(datafile_path, "rb") as f: while True: n = random.randint(1, 100) # read random number of bytes to simulate incomplete responses gdb_mi_simulated_output = f.read(n) if gdb_mi_simulated_output == b"": break # EOF # let the controller try to parse this additional raw gdb output responses += gdbmi._get_responses_list( gdb_mi_simulated_output, stream) assert len(responses) == 141 # spot check a few assert_match( responses[0], { "message": None, "type": "console", "payload": u"0x00007fe2c5c58920 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81\\n", "stream": stream, }, ) if not USING_WINDOWS: # can't get this to pass in windows assert_match( responses[71], { "stream": stream, "message": u"done", "type": "result", "payload": None, "token": None, }, ) assert_match( responses[82], { "message": None, "type": "output", "payload": u"The inferior program printed this! Can you still parse it?", "stream": stream, }, ) assert_match( responses[137], { "stream": stream, "message": u"thread-group-exited", "type": "notify", "payload": { u"exit-code": u"0", u"id": u"i1" }, "token": None, }, ) assert_match( responses[138], { "stream": stream, "message": u"thread-group-started", "type": "notify", "payload": { u"pid": u"48337", u"id": u"i1" }, "token": None, }, ) assert_match( responses[139], { "stream": stream, "message": u"tsv-created", "type": "notify", "payload": { u"name": "trace_timestamp", u"initial": "0" }, "token": None, }, ) assert_match( responses[140], { "stream": stream, "message": u"tsv-created", "type": "notify", "payload": { u"name": "trace_timestamp", u"initial": "0" }, "token": None, }, ) for stream in gdbmi._incomplete_output.keys(): assert gdbmi._incomplete_output[stream] is None