1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

[dsf-gdb] debug tests: Use line tags where possible

The goal is to eliminate direct source line number references in tests,
so that modifying test cases is easier.

Change-Id: I9a4964478e9486bff137fb9aec199cee144c2af4
Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
This commit is contained in:
Simon Marchi 2015-04-24 13:36:27 -04:00
parent e8cc363899
commit c389f49659
11 changed files with 109 additions and 60 deletions

View file

@ -17,14 +17,14 @@ int integerBlock[ARRAY_SIZE];
void zeroBlocks(int abc)
{
for (int i = 0; i < ARRAY_SIZE; i++) {
charBlock[i] = '\0';
integerBlock[i] = 0;
charBlock[i] = '\0'; // LINE_NUMBER_1
integerBlock[i] = 0; // LINE_NUMBER_2
}
}
void setBlocks()
{
for (int i = 0; i < ARRAY_SIZE; i++) {
for (int i = 0; i < ARRAY_SIZE; i++) { // LINE_NUMBER_3
charBlock[i] = (char) i;
integerBlock[i] = i;
}
@ -33,7 +33,7 @@ void setBlocks()
void loop()
{
int j = 10;
int i = 0;
int i = 0; // LINE_NUMBER_4
for (i = 0; i < ARRAY_SIZE; i++)
j = i;
}
@ -46,6 +46,6 @@ int main()
loop();
setBlocks();
SLEEP(1);
a++;
return 0;
a++; // LINE_NUMBER_5
return 0; // LINE_NUMBER_6
}

View file

@ -11,10 +11,10 @@ int main() {
std::cout << "Exception caught" << std::endl;
}
}
// For setting a catchpoint while target is running
std::cout << "Sleeping..." << std::endl;
SLEEP(2);
SLEEP(2); // LINE_NUMBER_SLEEP_CALL
std::cout << "...awake!" << std::endl;
try {
std::cout << "Throwing exception" << std::endl;
@ -23,6 +23,6 @@ int main() {
catch (int exc) {
std::cout << "Exception caught" << std::endl;
}
return 0;
}

View file

@ -24,10 +24,11 @@ int envTest() {
int main (int argc, char *argv[])
{
envTest();
envTest(); // FIRST_LINE_IN_MAIN
reverseTest();
stopAtOther();
return 36;
return 36; // LAST_LINE_IN_MAIN
// Return special value to allow
// testing exit code feature
}

View file

@ -32,7 +32,7 @@ void setBlocks()
int main()
{
zeroBlocks();
zeroBlocks(); // LINE_NUMBER
setBlocks();
return 0;
}

View file

@ -1,7 +1,4 @@
//
////
//
int value() {
int a = 1; // Must be at line 5
return 1;
int a = 1; // VALUE_LINE
return 1;
}

View file

@ -1,43 +1,26 @@
#include "StepIntoSelection.h"
//
//
//
//
//
//
//
// The first line of the below method must be at line 10
int foo() {
int i = 0; // The tests expect this to be at line 11
int i = 0; // FOO_LINE
return 1;
}
//
//
//
//
//
int bar(int i) {
int b = 0; // The tests expect this to be at line 20
int b = 0; // BAR_LINE
return i + b;
}
//
//
//
//
//
//
int add(int a) {
return a + 1; // The tests expect this to be at line 30
return a + 1; // ADD_WITH_ARG_LINE
}
//
//
int add() {
return 1; // The tests expect this to be at line 35
return 1; // ADD_NO_ARG_LINE
}
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
}

View file

@ -74,9 +74,16 @@ import org.junit.runners.Parameterized;
public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase {
public @Rule IntermittentRule intermittentRule = new IntermittentRule();
protected static final String EXEC_NAME = "LaunchConfigurationAndRestartTestApp.exe";
protected static final String SOURCE_NAME = "LaunchConfigurationAndRestartTestApp.cc";
protected static final String[] LINE_TAGS = new String[] {
"FIRST_LINE_IN_MAIN",
"LAST_LINE_IN_MAIN",
};
protected int FIRST_LINE_IN_MAIN;
protected int LAST_LINE_IN_MAIN;
protected static final int FIRST_LINE_IN_MAIN = 27;
protected static final int LAST_LINE_IN_MAIN = 30;
// The exit code returned by the test program
private static final int TEST_EXIT_CODE = 36;
@ -94,7 +101,13 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
removeTeminatedLaunchesBeforeTest();
setLaunchAttributes();
// Can't run the launch right away because each test needs to first set some
// parameters. The individual tests will be responsible for starting the launch.
// parameters. The individual tests will be responsible for starting the launch.
// Looks up line tags in source file(s).
resolveLineTagLocations(SOURCE_NAME, LINE_TAGS);
FIRST_LINE_IN_MAIN = getLineForTag("FIRST_LINE_IN_MAIN");
LAST_LINE_IN_MAIN = getLineForTag("LAST_LINE_IN_MAIN");
}
@Override

View file

@ -134,13 +134,24 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase {
protected final String EXPRESSION_TAG = MIBreakpoints.EXPRESSION;
protected final String READ_TAG = MIBreakpoints.READ;
protected final String WRITE_TAG = MIBreakpoints.WRITE;
// Target application 'special' locations
protected final int LINE_NUMBER_1 = 20;
protected final int LINE_NUMBER_2 = 21;
protected final int LINE_NUMBER_3 = 27;
protected final int LINE_NUMBER_4 = 36;
protected final int LINE_NUMBER_5 = 49;
protected final int LINE_NUMBER_6 = 50;
private static final String[] LINE_TAGS = new String[] {
"LINE_NUMBER_1",
"LINE_NUMBER_2",
"LINE_NUMBER_3",
"LINE_NUMBER_4",
"LINE_NUMBER_5",
"LINE_NUMBER_6",
};
private int LINE_NUMBER_1;
private int LINE_NUMBER_2;
private int LINE_NUMBER_3;
private int LINE_NUMBER_4;
private int LINE_NUMBER_5;
private int LINE_NUMBER_6;
protected final String FUNCTION = "zeroBlocks";
protected final String SIGNED_FUNCTION = "zeroBlocks(int)";
protected final String NO_CONDITION = "";
@ -200,6 +211,16 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase {
IContainerDMContext containerDmc = SyncUtil.getContainerContext();
fBreakpointsDmc = DMContexts.getAncestorOfType(containerDmc, IBreakpointsTargetDMContext.class);
assert (fBreakpointsDmc != null);
// Look up line tags in source file.
resolveLineTagLocations(SOURCE_NAME, LINE_TAGS);
LINE_NUMBER_1 = getLineForTag("LINE_NUMBER_1");
LINE_NUMBER_2 = getLineForTag("LINE_NUMBER_2");
LINE_NUMBER_3 = getLineForTag("LINE_NUMBER_3");
LINE_NUMBER_4 = getLineForTag("LINE_NUMBER_4");
LINE_NUMBER_5 = getLineForTag("LINE_NUMBER_5");
LINE_NUMBER_6 = getLineForTag("LINE_NUMBER_6");
}
@Override

View file

@ -85,7 +85,11 @@ public class MICatchpointsTest extends BaseParametrizedTestCase {
private static final String EXEC_NAME = "CatchpointTestApp.exe"; //$NON-NLS-1$
private static final String SOURCE_NAME = "CatchpointTestApp.cc"; //$NON-NLS-1$
public static final int LINE_NUMBER_SLEEP_CALL = 17;
private int LINE_NUMBER_SLEEP_CALL;
private static final String[] LINE_TAGS = {
"LINE_NUMBER_SLEEP_CALL",
};
// Asynchronous Completion
private final AsyncCompletionWaitor fWait = new AsyncCompletionWaitor();
@ -177,6 +181,9 @@ public class MICatchpointsTest extends BaseParametrizedTestCase {
IContainerDMContext containerDmc = SyncUtil.getContainerContext();
fBreakpointsDmc = DMContexts.getAncestorOfType(containerDmc, IBreakpointsTargetDMContext.class);
assertNotNull(fBreakpointsDmc);
resolveLineTagLocations(SOURCE_NAME, LINE_TAGS);
LINE_NUMBER_SLEEP_CALL = getLineForTag("LINE_NUMBER_SLEEP_CALL");
}
@Override

View file

@ -62,9 +62,14 @@ import org.junit.runners.Parameterized;
public class MIDisassemblyTest extends BaseParametrizedTestCase {
private static final String EXEC_NAME = "MemoryTestApp.exe";
private static final String SOURCE_NAME = "MemoryTestApp.cc";
private static final int LINE_NUMBER = 35;
private static final String INVALID_SOURCE_NAME = "invalid_filename";
protected static final String[] LINE_TAGS = {
"LINE_NUMBER",
};
protected int LINE_NUMBER;
private DsfSession fSession;
private DsfServicesTracker fServicesTracker;
private IDisassemblyDMContext fDisassemblyDmc;
@ -103,6 +108,8 @@ public class MIDisassemblyTest extends BaseParametrizedTestCase {
fDisassemblyDmc = DMContexts.getAncestorOfType(containerDmc, IDisassemblyDMContext.class);
assert(fDisassemblyDmc != null);
resolveLineTagLocations(SOURCE_NAME, LINE_TAGS);
LINE_NUMBER = getLineForTag("LINE_NUMBER");
}
@Override

View file

@ -56,12 +56,23 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
private static final String EXEC_NAME = "StepIntoSelectionTestApp.exe";
private static final String SOURCE_NAME = "StepIntoSelectionTestApp.cc";
private static final String HEADER_NAME = "StepIntoSelection.h";
private static final int FOO_LINE = 11;
private static final int BAR_LINE = 20;
private static final int VALUE_LINE = 5;
private static final int ADD_WITH_ARG_LINE = 30;
private static final int ADD_NO_ARG_LINE = 35;
protected int FOO_LINE;
protected int BAR_LINE;
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 static final String[] HEADER_LINE_TAGS = {
"VALUE_LINE",
};
//Target Functions
private final static FunctionDeclaration funcFoo = new FunctionDeclaration(null, "foo");
private final static FunctionDeclaration funcBar = new FunctionDeclaration(null, "bar");
@ -107,6 +118,15 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
};
fSession = getGDBLaunch().getSession();
fSession.getExecutor().submit(runnable).get();
resolveLineTagLocations(SOURCE_NAME, SOURCE_LINE_TAGS);
resolveLineTagLocations(HEADER_NAME, HEADER_LINE_TAGS);
FOO_LINE = getLineForTag("FOO_LINE");
BAR_LINE = getLineForTag("BAR_LINE");
VALUE_LINE = getLineForTag("VALUE_LINE");
ADD_WITH_ARG_LINE = getLineForTag("ADD_WITH_ARG_LINE");
ADD_NO_ARG_LINE = getLineForTag("ADD_NO_ARG_LINE");
}
@Override