Skip to content

Commit

Permalink
Use line tags in tests
Browse files Browse the repository at this point in the history
The tests were relying on specific number of executable lines
in a function. However on some gdb/gcc combinations stopping
at a function stops at the line with the `{` and some
on the first line witin that function. Much of the tests
here assumed that latter. By using line tags we don't need
to worry about exact number of executables lines between entry
and area of interest.

Part of eclipse-cdt#816
  • Loading branch information
jonahgraham committed Dec 28, 2024
1 parent 87660ae commit 76a3626
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int envTest() {
char *home, *launchTest;
home = getenv("HOME");
launchTest = getenv("LAUNCHTEST");
return 0;
return 0; // END_ENV_TEST_LINE
}

int main (int argc, char *argv[])
Expand All @@ -29,7 +29,7 @@ int main (int argc, char *argv[])
var = 3;
var = 4; // three_steps_back_from_b_stopAtOther
var = 5;
stopAtOther(); // main_init
stopAtOther(); // MAIN_INIT_LINE
reverseTest(); // tests assume that every line between first and last
envTest(); // is steppable, so no blank lines allowed.
return 36; // LAST_LINE_IN_MAIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int add() {
int recursiveTest(int a) {
if (a == 1) return a;

return a + recursiveTest(--a); // The test expects this line to be exactly 2 lines below the first line of the method
return a + recursiveTest(--a); // RECURSIVE_LINE
}

int sameLineTest() {
Expand All @@ -36,15 +36,15 @@ int sameLineBreakpointTest() {

int doubleMethodTest() {
int a = 0;
bar(foo()); // The test expects this line to be one line below the star of the method
bar(foo()); // DOUBLE_METHOD_LINE
return 0;
}

int laterLineTest() {
int i = 0;
int i = 0; // LATER_LINE_ENTRY_LINE
i++;
i++;
foo(); // The test expects this line to be exactly 3 lines below the first line of the method
foo(); // LATER_LINE_LINE
i++;
i++;
return 0;
Expand All @@ -53,7 +53,7 @@ int laterLineTest() {
int laterLineNotHitTest() {
int i = 0;
if (i==100) { // Won't hit
foo(); // The test expects this line to be exactly 2 lines below the first line of the method
foo(); // LATER_LINE_NOT_HIT_LINE
}
i++;
i++;
Expand All @@ -62,8 +62,7 @@ int laterLineNotHitTest() {

int laterLineDifferentFileTest() {
int b = 0;
value(); // Must be one line below start of the method
// value() is from .h header file
value(); // LATER_LINE_DIFFERENT_FILE_LINE
}

int differentFileTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected String convertDetails(String details) {
*/
protected void checkArguments(String... expected) throws Throwable {

MIStoppedEvent stoppedEvent = runToTag("main_init");
MIStoppedEvent stoppedEvent = runToTag("MAIN_INIT");

// Check that argc is correct
final IExpressionDMContext argcDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
protected static final String SOURCE_NAME = "LaunchConfigurationAndRestartTestApp.cc";

protected static final String[] LINE_TAGS = new String[] { "FIRST_LINE_IN_MAIN", "LAST_LINE_IN_MAIN",
"three_steps_back_from_b_stopAtOther" };
"three_steps_back_from_b_stopAtOther", "END_ENV_TEST_LINE", "MAIN_INIT_LINE" };

protected int FIRST_LINE_IN_MAIN;
protected int LAST_LINE_IN_MAIN;
protected int three_steps_back_from_b_stopAtOther;
protected int END_ENV_TEST_LINE;
protected int MAIN_INIT_LINE;

// The exit code returned by the test program
private static final int TEST_EXIT_CODE = 36;
Expand Down Expand Up @@ -105,6 +107,8 @@ public void doBeforeTest() throws Exception {
FIRST_LINE_IN_MAIN = getLineForTag("FIRST_LINE_IN_MAIN");
LAST_LINE_IN_MAIN = getLineForTag("LAST_LINE_IN_MAIN");
three_steps_back_from_b_stopAtOther = getLineForTag("three_steps_back_from_b_stopAtOther");
END_ENV_TEST_LINE = getLineForTag("END_ENV_TEST_LINE");
MAIN_INIT_LINE = getLineForTag("MAIN_INIT_LINE");
}

@Override
Expand Down Expand Up @@ -287,8 +291,7 @@ public void testClearingEnvironment() throws Throwable {
setLaunchAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, false);
doLaunch();

SyncUtil.runToLocation("envTest");
MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER);
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(Integer.toString(END_ENV_TEST_LINE));

// The program has stored the content of $HOME into a variable called 'home'.
// Let's verify this variable is 0x0 which means $HOME does not exist.
Expand Down Expand Up @@ -329,8 +332,7 @@ public void testSettingEnvironment() throws Throwable {
setLaunchAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
doLaunch();

SyncUtil.runToLocation("envTest");
MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER);
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(Integer.toString(END_ENV_TEST_LINE));

// The program has stored the content of $LAUNCHTEST into a variable called 'launchTest'.
// Let's verify this variable is set to "IS SET".
Expand Down Expand Up @@ -390,8 +392,7 @@ public void testClearingAndSettingEnvironment() throws Throwable {
setLaunchAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
doLaunch();

SyncUtil.runToLocation("envTest");
MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER);
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(Integer.toString(END_ENV_TEST_LINE));

// The program has stored the content of $LAUNCHTEST into a variable called 'launchTest'.
// Let's verify this variable is set to "IS SET".
Expand Down Expand Up @@ -449,7 +450,7 @@ public void testSettingArguments() throws Throwable {
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "1 2 3\n4 5 6");
doLaunch();

MIStoppedEvent stoppedEvent = getInitialStoppedEvent();
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(Integer.toString(MAIN_INIT_LINE));

// Check that argc is correct
final IExpressionDMContext argcDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
protected int VALUE_LINE;
protected int ADD_WITH_ARG_LINE;
protected int ADD_NO_ARG_LINE;

protected static final String[] SOURCE_LINE_TAGS = { "FOO_LINE", "BAR_LINE", "ADD_WITH_ARG_LINE",
"ADD_NO_ARG_LINE", };
protected int DOUBLE_METHOD_LINE;
protected int LATER_LINE_LINE;
protected int LATER_LINE_NOT_HIT_LINE;
protected int LATER_LINE_DIFFERENT_FILE_LINE;
protected int RECURSIVE_LINE;
protected int LATER_LINE_ENTRY_LINE;

protected static final String[] SOURCE_LINE_TAGS = { "FOO_LINE", "BAR_LINE", "ADD_WITH_ARG_LINE", "ADD_NO_ARG_LINE",
"DOUBLE_METHOD_LINE", "LATER_LINE_LINE", "LATER_LINE_NOT_HIT_LINE", "LATER_LINE_DIFFERENT_FILE_LINE",
"RECURSIVE_LINE", "LATER_LINE_ENTRY_LINE" };
protected static final String[] HEADER_LINE_TAGS = { "VALUE_LINE", };

//Target Functions
Expand Down Expand Up @@ -121,6 +128,12 @@ public void doBeforeTest() throws Exception {
VALUE_LINE = getLineForTag("VALUE_LINE");
ADD_WITH_ARG_LINE = getLineForTag("ADD_WITH_ARG_LINE");
ADD_NO_ARG_LINE = getLineForTag("ADD_NO_ARG_LINE");
DOUBLE_METHOD_LINE = getLineForTag("DOUBLE_METHOD_LINE");
LATER_LINE_LINE = getLineForTag("LATER_LINE_LINE");
LATER_LINE_NOT_HIT_LINE = getLineForTag("LATER_LINE_NOT_HIT_LINE");
LATER_LINE_DIFFERENT_FILE_LINE = getLineForTag("LATER_LINE_DIFFERENT_FILE_LINE");
RECURSIVE_LINE = getLineForTag("RECURSIVE_LINE");
LATER_LINE_ENTRY_LINE = getLineForTag("LATER_LINE_ENTRY_LINE");
}

@Override
Expand Down Expand Up @@ -242,10 +255,9 @@ public void atLaterLine() throws Throwable {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());

FunctionDeclaration targetFunction = funcFoo;
int line = stoppedEvent.getFrame().getLine() + 3; // The method to stepInto is three lines below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_LINE, targetFunction, false);

validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, FOO_LINE, originalDepth + 1);
}
Expand All @@ -259,10 +271,9 @@ public void atLaterLineOnDifferentFile() throws Throwable {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());

FunctionDeclaration targetFunction = funcValue;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_DIFFERENT_FILE_LINE, targetFunction, false);

validateLocation(suspendedEvent, targetFunction.getElementName(), HEADER_NAME, VALUE_LINE, originalDepth + 1);
}
Expand All @@ -277,10 +288,9 @@ public void atDoubleMethodDeepCall() throws Throwable {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());

FunctionDeclaration targetFunction = funcFoo;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
DOUBLE_METHOD_LINE, targetFunction, false);

validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, FOO_LINE, originalDepth + 1);
}
Expand All @@ -295,10 +305,9 @@ public void atDoubleMethodShalowCall() throws Throwable {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());

FunctionDeclaration targetFunction = funcBar;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
DOUBLE_METHOD_LINE, targetFunction, false);

validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, BAR_LINE, originalDepth + 1);
}
Expand All @@ -314,10 +323,9 @@ public void recursiveMethod() throws Throwable {

FunctionDeclaration targetFunction = funcRecursive;

int line = stoppedEvent.getFrame().getLine() + 2; // The method to stepInto is two lines below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
RECURSIVE_LINE, targetFunction, false);

validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, finalLine, originalDepth + 1);
}
Expand All @@ -330,21 +338,21 @@ public void recursiveMethod() throws Throwable {
public void atPreviousLine() throws Throwable {
String functionName = "laterLineTest";
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(functionName);
int originalLine = stoppedEvent.getFrame().getLine();
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());

// Step past the function call
stoppedEvent = SyncUtil.step(4, StepType.STEP_OVER);
while (stoppedEvent.getFrame().getLine() <= LATER_LINE_LINE) {
stoppedEvent = SyncUtil.step(1, StepType.STEP_OVER);
}
// Set a bp one line below. We will check that this breakpoint hits when a stepInto is done
int bpline = originalLine + 4 + 1;
int bpline = LATER_LINE_LINE + 2;
SyncUtil.addBreakpoint(Integer.toString(bpline));

FunctionDeclaration targetFunction = funcFoo;
int line = originalLine + 3; // The method to stepInto is three lines below the start of the method

// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_LINE, targetFunction, false);

validateLocation(suspendedEvent, functionName, SOURCE_NAME, bpline, originalDepth);
}
Expand All @@ -360,10 +368,10 @@ public void atLaterLineThatIsNotHit() throws Throwable {
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());

FunctionDeclaration targetFunction = funcFoo;
int line = stoppedEvent.getFrame().getLine() + 2; // The method to stepInto is two lines below the start of the method
// Except we'll never reach it
// Set a bp a couple of lines below. We will check that this breakpoint hits and the stepInto is cancelled
int bpline = line + 2;
int line = LATER_LINE_NOT_HIT_LINE; // The method to stepInto is two lines below the start of the method
// Except we'll never reach it
// Set a bp a couple of lines below. We will check that this breakpoint hits and the stepInto is cancelled
int bpline = LATER_LINE_NOT_HIT_LINE + 2;
SyncUtil.addBreakpoint(Integer.toString(bpline));

// StepInto the method
Expand All @@ -388,22 +396,21 @@ public void atLaterLineStopAtBreakpoint() throws Throwable {
String functionName = "laterLineTest";
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(functionName);
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
int originalLine = stoppedEvent.getFrame().getLine();

// Set a breakpoint before the stepInto line
SyncUtil.addBreakpoint(Integer.toString(originalLine + 1));
int bpline = LATER_LINE_LINE - 1;
SyncUtil.addBreakpoint(Integer.toString(bpline));

int line = originalLine + 3; // The method to stepInto is three lines below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
funcFoo, false);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_LINE, funcFoo, false);

validateLocation(suspendedEvent, functionName, SOURCE_NAME, originalLine + 1, originalDepth);
validateLocation(suspendedEvent, functionName, SOURCE_NAME, bpline, originalDepth);

// Make sure the step to selection operation is no longer active by triggering a run to line before the step into selection line
suspendedEvent = triggerRunToLine(stoppedEvent.getDMContext(), SOURCE_NAME, originalLine + 2, false);
suspendedEvent = triggerRunToLine(stoppedEvent.getDMContext(), SOURCE_NAME, LATER_LINE_LINE, false);

validateLocation(suspendedEvent, functionName, SOURCE_NAME, originalLine + 2, originalDepth);
validateLocation(suspendedEvent, functionName, SOURCE_NAME, LATER_LINE_LINE, originalDepth);
}

/**
Expand All @@ -414,19 +421,16 @@ public void atLaterLineStopAtBreakpoint() throws Throwable {
public void atLaterLineSkipBreakpoints() throws Throwable {
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("laterLineTest");
int originalDepth = SyncUtil.getStackDepth(stoppedEvent.getDMContext());
int originalLine = stoppedEvent.getFrame().getLine();

// Set two breakpoints before the stepInto line
SyncUtil.addBreakpoint(Integer.toString(originalLine + 1));
SyncUtil.addBreakpoint(Integer.toString(originalLine + 2));

int line = originalLine + 3; // The method to stepInto is three lines below the start of the method
SyncUtil.addBreakpoint(Integer.toString(LATER_LINE_LINE - 2));
SyncUtil.addBreakpoint(Integer.toString(LATER_LINE_LINE - 1));

FunctionDeclaration targetFunction = funcFoo;

// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, true);
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
LATER_LINE_LINE, targetFunction, true);

validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, FOO_LINE, originalDepth + 1);
}
Expand All @@ -440,10 +444,9 @@ private void atDoubleMethodStopAtBreakpointCommon(int foo_line) throws Throwable
SyncUtil.addBreakpoint(Integer.toString(foo_line));

FunctionDeclaration targetFunction = funcBar;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, false); // Set not to skip breakpoints, but it should have no effect
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
DOUBLE_METHOD_LINE, targetFunction, false); // Set not to skip breakpoints, but it should have no effect

validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, BAR_LINE, originalDepth + 1);
}
Expand Down Expand Up @@ -480,10 +483,9 @@ private void atDoubleMethodSkipBreakpointCommon(int foo_line) throws Throwable {
SyncUtil.addBreakpoint(Integer.toString(foo_line));

FunctionDeclaration targetFunction = funcBar;
int line = stoppedEvent.getFrame().getLine() + 1; // The method to stepInto is one line below the start of the method
// StepInto the method
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME, line,
targetFunction, true); // Set skip breakpoints, which should have non impact
ISuspendedDMEvent suspendedEvent = triggerStepIntoSelection(stoppedEvent.getDMContext(), SOURCE_NAME,
DOUBLE_METHOD_LINE, targetFunction, true); // Set skip breakpoints, which should have non impact

validateLocation(suspendedEvent, targetFunction.getElementName(), SOURCE_NAME, BAR_LINE, originalDepth + 1);
}
Expand Down

0 comments on commit 76a3626

Please sign in to comment.