Skip to content

Commit 5c9de29

Browse files
committed
tests: add ‘step over’ and ‘step out’ helpers
1 parent 72cc59b commit 5c9de29

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

testing/esp/debug_backend.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class Gdb:
114114
TARGET_STOP_REASON_BP = 3
115115
TARGET_STOP_REASON_WP = 4
116116
TARGET_STOP_REASON_STEPPED = 5
117+
TARGET_STOP_REASON_FN_FINISHED = 6
117118

118119
@staticmethod
119120
def get_logger():
@@ -139,6 +140,8 @@ def _on_notify(self, rec):
139140
self._target_stop_reason = self.TARGET_STOP_REASON_WP
140141
elif rec['payload']['reason'] == 'end-stepping-range':
141142
self._target_stop_reason = self.TARGET_STOP_REASON_STEPPED
143+
elif rec['payload']['reason'] == 'function-finished':
144+
self._target_stop_reason = self.TARGET_STOP_REASON_FN_FINISHED
142145
elif rec['payload']['reason'] == 'signal-received':
143146
if rec['payload']['signal-name'] == 'SIGINT':
144147
self._target_stop_reason = self.TARGET_STOP_REASON_SIGINT
@@ -261,7 +264,19 @@ def exec_next(self):
261264
# -exec-next [--reverse]
262265
res,_ = self._mi_cmd_run('-exec-next')
263266
if res != 'running':
264-
raise DebuggerError('Failed to step program!')
267+
raise DebuggerError('Failed to step over!')
268+
269+
def exec_step(self):
270+
# -exec-step [--reverse]
271+
res,_ = self._mi_cmd_run('-exec-step')
272+
if res != 'running':
273+
raise DebuggerError('Failed to step in!')
274+
275+
def exec_finish(self):
276+
# -exec-finish [--reverse]
277+
res,_ = self._mi_cmd_run('-exec-finish')
278+
if res != 'running':
279+
raise DebuggerError('Failed to step out!')
265280

266281
def data_eval_expr(self, expr):
267282
# -data-evaluate-expression expr

testing/esp/debug_backend_tests.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,29 @@ def resume_exec(self, loc=None):
209209

210210

211211
def step(self):
212-
""" Performs program step
212+
""" Performs program step (step over, "next" command in GDB)
213213
"""
214214
self.gdb.exec_next()
215215
self.gdb.wait_target_state(dbg.Gdb.TARGET_STATE_RUNNING, 5)
216216
rsn = self.gdb.wait_target_state(dbg.Gdb.TARGET_STATE_STOPPED, 5)
217217
self.assertEqual(rsn, dbg.Gdb.TARGET_STOP_REASON_STEPPED)
218218

219+
def step_in(self):
220+
""" Performs program step (step in, "step" command in GDB)
221+
"""
222+
self.gdb.exec_step()
223+
self.gdb.wait_target_state(dbg.Gdb.TARGET_STATE_RUNNING, 5)
224+
rsn = self.gdb.wait_target_state(dbg.Gdb.TARGET_STATE_STOPPED, 5)
225+
self.assertEqual(rsn, dbg.Gdb.TARGET_STOP_REASON_STEPPED)
226+
227+
def step_out(self):
228+
""" Runs until current function retunrs (step out, "finish" command in GDB)
229+
"""
230+
self.gdb.exec_finish()
231+
self.gdb.wait_target_state(dbg.Gdb.TARGET_STATE_RUNNING, 5)
232+
rsn = self.gdb.wait_target_state(dbg.Gdb.TARGET_STATE_STOPPED, 5)
233+
self.assertEqual(rsn, dbg.Gdb.TARGET_STOP_REASON_FN_FINISHED)
234+
219235
class DebuggerTestAppTests(DebuggerTestsBase):
220236
""" Base class for tests which need special app running on target
221237
"""

0 commit comments

Comments
 (0)