[lldb][test] Handle potential compiler differences in TestEmptyFuncThreadStepOut.py#210050
Conversation
…readStepOut.py Fixes llvm#195958 It was reported that this test sometimes failed in CI because lldb would step out to line 6 instead of line 7. Jim Ingham expained on the issue that both could be valid locations (llvm#195958 (comment)). There's no garauntee that "step out" would go to the source line after the call you step out of. All it does is go to the first location outside of the call. If the compiler so chose, that could be on the same line as the call. I was not able to reproduce this failure mode, but I think it was happening in CI before, and is possible. So I've made the test accept line 6 or 7. Anything further than that we've gone too far and the test will fail.
|
@llvm/pr-subscribers-lldb Author: David Spickett (DavidSpickett) ChangesFixes #195958 It was reported that this test sometimes failed in CI because lldb would step out to line 6 instead of line 7. Jim Ingham expained on the issue that both could be valid locations (#195958 (comment)). There's no garauntee that "step out" would go to the source line after the call you step out of. All it does is go to the first location outside of the call. If the compiler so chose, that could be on the same line as the call. I was not able to reproduce this failure mode, but I think it was happening in CI before, and is possible. So I've made the test accept line 6 or 7. Anything further than that we've gone too far and the test will fail. Full diff: https://github.com/llvm/llvm-project/pull/210050.diff 2 Files Affected:
diff --git a/lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py b/lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py
index c95a57ff55815..abf3f1c4ebbf4 100644
--- a/lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py
+++ b/lldb/test/API/functionalities/thread/finish-from-empty-func/TestEmptyFuncThreadStepOut.py
@@ -41,7 +41,6 @@ def test_finish_from_empty_function(self):
if self.TraceOn():
self.runCmd("bt")
- correct_stepped_out_line = line_number("main.c", "leaving main")
return_statement_line = line_number("main.c", "return 0")
safety_bp = target.BreakpointCreateByLocation(
lldb.SBFileSpec("main.c"), return_statement_line
@@ -54,9 +53,19 @@ def test_finish_from_empty_function(self):
if self.TraceOn():
self.runCmd("bt")
- frame = thread.GetSelectedFrame()
- self.assertEqual(
- frame.line_entry.GetLine(),
- correct_stepped_out_line,
+ # Compilers may generate source locations differently, so we expect to
+ # either be:
+ # * On the line of the second done() call, or -
+ # * On the puts() line below.
+ #
+ # If we reach the return statement, we did not step out correctly.
+ stepped_out_lines = [
+ line_number("main.c", "leaving main"),
+ line_number("main.c", "Second call to done"),
+ ]
+
+ self.assertIn(
+ thread.GetSelectedFrame().line_entry.GetLine(),
+ stepped_out_lines,
"Step-out lost control of execution, ran too far",
)
diff --git a/lldb/test/API/functionalities/thread/finish-from-empty-func/main.c b/lldb/test/API/functionalities/thread/finish-from-empty-func/main.c
index b3f90db5e2562..e0165d7dcc987 100644
--- a/lldb/test/API/functionalities/thread/finish-from-empty-func/main.c
+++ b/lldb/test/API/functionalities/thread/finish-from-empty-func/main.c
@@ -3,7 +3,7 @@ void done() {}
int main() {
puts("in main");
done(); // Set breakpoint here
- done();
+ done(); // Second call to done
puts("leaving main");
return 0;
}
|
jimingham
left a comment
There was a problem hiding this comment.
LGTM.
step-out is odd because unlike all the other stepping modes it doesn't guarantee that it will finish out source lines, but rather that it stops immediately on returning to the parent frame. So you can't know for certain whether a step out will stop in the calling line, or the following line.
So this is a more appropriate test.
Fixes #195958
It was reported that this test sometimes failed in CI because lldb would step out to line 6 instead of line 7.
Jim Ingham expained on the issue that both could be valid locations (#195958 (comment)).
There's no garauntee that "step out" would go to the source line after the call you step out of. All it does is go to the first location outside of the call. If the compiler so chose, that could be on the same line as the call.
I was not able to reproduce this failure mode, but I think it was happening in CI before, and is possible. So I've made the test accept line 6 or 7. Anything further than that we've gone too far and the test will fail.