|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2011 Ericsson and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Ericsson - Initial Implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.cdt.tests.dsf.gdb.tests; |
| 12 |
|
| 13 |
import static org.junit.Assert.assertFalse; |
| 14 |
import static org.junit.Assert.assertTrue; |
| 15 |
import static org.junit.Assert.fail; |
| 16 |
|
| 17 |
import java.util.HashMap; |
| 18 |
import java.util.Map; |
| 19 |
import java.util.concurrent.ExecutionException; |
| 20 |
import java.util.concurrent.TimeUnit; |
| 21 |
import java.util.concurrent.TimeoutException; |
| 22 |
|
| 23 |
import org.eclipse.cdt.debug.core.CDIDebugModel; |
| 24 |
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; |
| 25 |
import org.eclipse.cdt.debug.core.model.ICBreakpointType; |
| 26 |
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; |
| 27 |
import org.eclipse.cdt.dsf.concurrent.Query; |
| 28 |
import org.eclipse.cdt.dsf.debug.service.IExpressions; |
| 29 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; |
| 30 |
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData; |
| 31 |
import org.eclipse.cdt.dsf.debug.service.IRunControl.StepType; |
| 32 |
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; |
| 33 |
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; |
| 34 |
import org.eclipse.cdt.dsf.mi.service.MIExpressions; |
| 35 |
import org.eclipse.cdt.dsf.mi.service.command.events.MIStoppedEvent; |
| 36 |
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; |
| 37 |
import org.eclipse.cdt.dsf.service.DsfServicesTracker; |
| 38 |
import org.eclipse.cdt.dsf.service.DsfSession; |
| 39 |
import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; |
| 40 |
import org.eclipse.cdt.tests.dsf.gdb.framework.BaseTestCase; |
| 41 |
import org.eclipse.cdt.tests.dsf.gdb.framework.SyncUtil; |
| 42 |
import org.eclipse.cdt.tests.dsf.gdb.launching.TestsPlugin; |
| 43 |
import org.eclipse.core.resources.IFile; |
| 44 |
import org.eclipse.core.runtime.CoreException; |
| 45 |
import org.eclipse.core.runtime.IPath; |
| 46 |
import org.eclipse.core.runtime.Path; |
| 47 |
import org.eclipse.debug.core.ILaunchManager; |
| 48 |
import org.junit.After; |
| 49 |
import org.junit.Before; |
| 50 |
import org.junit.Ignore; |
| 51 |
import org.junit.Test; |
| 52 |
import org.junit.runner.RunWith; |
| 53 |
|
| 54 |
@RunWith(BackgroundRunner.class) |
| 55 |
public class LaunchConfigurationAndRestartTest extends BaseTestCase { |
| 56 |
|
| 57 |
protected static final String PROGRAM_DIR = "data/launch/bin/"; |
| 58 |
protected static final String PROGRAM_NAME = "LaunchConfigurationAndRestartTestApp.exe"; |
| 59 |
protected static final String PROGRAM = PROGRAM_DIR + PROGRAM_NAME; |
| 60 |
|
| 61 |
protected static final int FIRST_LINE_IN_MAIN = 27; |
| 62 |
protected static final int LAST_LINE_IN_MAIN = 30; |
| 63 |
|
| 64 |
protected DsfSession fSession; |
| 65 |
protected DsfServicesTracker fServicesTracker; |
| 66 |
protected IExpressions fExpService; |
| 67 |
protected IGDBControl fGdbControl; |
| 68 |
|
| 69 |
// Indicates if a restart operation should be done |
| 70 |
// This allows us to re-use tests for restarts tests |
| 71 |
protected boolean fRestart; |
| 72 |
|
| 73 |
@Override |
| 74 |
@Before |
| 75 |
public void baseBeforeMethod() throws Exception { |
| 76 |
// The class BaseTestCase sets up the launch in its @BeforeClass method. |
| 77 |
// Usually this is ok, because every test uses the same launch configuration. |
| 78 |
// However, for the tests of this class, we are changing the launch |
| 79 |
// configuration every time. Therefore, we need to reset it to the default |
| 80 |
// before every test; that means in the @Before method instead of @BeforeClass |
| 81 |
|
| 82 |
// Reset the launch configuration |
| 83 |
super.baseBeforeClassMethod(); |
| 84 |
// Set the binary |
| 85 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, PROGRAM); |
| 86 |
|
| 87 |
// Can't run the launch right away because each test needs to first set some |
| 88 |
// parameters. The individual tests will be responsible for starting the launch. |
| 89 |
} |
| 90 |
|
| 91 |
// This method cannot be tagged as @Before, because the launch is not |
| 92 |
// running yet. We have to call this manually after all the proper |
| 93 |
// parameters have been set for the launch |
| 94 |
public void performLaunch() throws Exception { |
| 95 |
// perform the launch |
| 96 |
super.baseBeforeMethod(); |
| 97 |
|
| 98 |
fSession = getGDBLaunch().getSession(); |
| 99 |
Runnable runnable = new Runnable() { |
| 100 |
public void run() { |
| 101 |
fServicesTracker = new DsfServicesTracker(TestsPlugin.getBundleContext(), fSession.getId()); |
| 102 |
|
| 103 |
fExpService = fServicesTracker.getService(IExpressions.class); |
| 104 |
fGdbControl = fServicesTracker.getService(IGDBControl.class); |
| 105 |
} |
| 106 |
}; |
| 107 |
fSession.getExecutor().submit(runnable).get(); |
| 108 |
|
| 109 |
// Restart the program if we are testing such a case |
| 110 |
if (fRestart) { |
| 111 |
synchronized (this) { |
| 112 |
wait(1000); |
| 113 |
} |
| 114 |
fRestart = false; |
| 115 |
try { |
| 116 |
SyncUtil.restart(getGDBLaunch()); |
| 117 |
} catch (Throwable e) { |
| 118 |
fail("Restart failed: " + e.getMessage()); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
@After |
| 124 |
public void shutdown() throws Exception { |
| 125 |
if (fServicesTracker != null) fServicesTracker.dispose(); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
// HACK to get the full path of the program, which we need in other |
| 130 |
// tests. There must be a proper eclipse way to do this! |
| 131 |
private static String fFullProgramPath; |
| 132 |
@Test |
| 133 |
public void getFullPath() throws Throwable { |
| 134 |
performLaunch(); |
| 135 |
MIStoppedEvent stopped = getInitialStoppedEvent(); |
| 136 |
fFullProgramPath = stopped.getFrame().getFullname(); |
| 137 |
} |
| 138 |
|
| 139 |
// ********************************************************************* |
| 140 |
// Below are the tests for the launch configuration. |
| 141 |
// ********************************************************************* |
| 142 |
|
| 143 |
/** |
| 144 |
* This test will tell the launch to set the working directory to data/launch/src/ |
| 145 |
* and will verify that we can find the file LaunchConfigurationAndRestartTestApp.cpp. |
| 146 |
* This will confirm that GDB has been properly configured with the working dir. |
| 147 |
*/ |
| 148 |
@Test |
| 149 |
public void testSettingWorkingDirectory() throws Throwable { |
| 150 |
IPath path = new Path(fFullProgramPath); |
| 151 |
String dir = path.removeLastSegments(4).toPortableString() + "/" + PROGRAM_DIR; |
| 152 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, dir); |
| 153 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, dir + PROGRAM_NAME); |
| 154 |
|
| 155 |
performLaunch(); |
| 156 |
|
| 157 |
Query<MIInfo> query = new Query<MIInfo>() { |
| 158 |
@Override |
| 159 |
protected void execute(DataRequestMonitor<MIInfo> rm) { |
| 160 |
fGdbControl.queueCommand( |
| 161 |
fGdbControl.getCommandFactory().createMIFileExecFile( |
| 162 |
fGdbControl.getContext(), PROGRAM_NAME), |
| 163 |
rm); |
| 164 |
} |
| 165 |
}; |
| 166 |
try { |
| 167 |
fExpService.getExecutor().execute(query); |
| 168 |
query.get(500, TimeUnit.MILLISECONDS); |
| 169 |
} catch (InterruptedException e) { |
| 170 |
fail(e.getMessage()); |
| 171 |
} catch (ExecutionException e) { |
| 172 |
fail(e.getCause().getMessage()); |
| 173 |
} catch (TimeoutException e) { |
| 174 |
fail(e.getMessage()); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* This test will verify that a launch will fail if the gdbinit file |
| 180 |
* does not exist and is not called ".gdbinit". |
| 181 |
*/ |
| 182 |
@Test |
| 183 |
public void testSourceInvalidGdbInit() throws Throwable { |
| 184 |
setLaunchAttribute(IGDBLaunchConfigurationConstants.ATTR_GDB_INIT, |
| 185 |
"gdbinitThatDoesNotExist"); |
| 186 |
try { |
| 187 |
performLaunch(); |
| 188 |
} catch (CoreException e) { |
| 189 |
// Success of the test |
| 190 |
return; |
| 191 |
} |
| 192 |
|
| 193 |
fail("Launch seems to have succeeded even though the gdbinit file did not exist"); |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* This test will verify that a launch does not fail if the gdbinit file |
| 198 |
* is called ".gdbinit" and does not exist |
| 199 |
*/ |
| 200 |
@Test |
| 201 |
public void testSourceDefaultGdbInit() throws Throwable { |
| 202 |
setLaunchAttribute(IGDBLaunchConfigurationConstants.ATTR_GDB_INIT, |
| 203 |
".gdbinit"); |
| 204 |
try { |
| 205 |
performLaunch(); |
| 206 |
} catch (CoreException e) { |
| 207 |
fail("Launch has failed even though the gdbinit file has the default name of .gdbinit"); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* This test will tell the launch to use data/launch/src/launchConfigTestGdbinit |
| 213 |
* as the gdbinit file. We then verify the that the content was properly read. |
| 214 |
* launchConfigTestGdbinit will simply set some arguments for the program to read; |
| 215 |
* the arguments are "1 2 3 4 5 6". |
| 216 |
*/ |
| 217 |
@Test |
| 218 |
public void testSourceGdbInit() throws Throwable { |
| 219 |
setLaunchAttribute(IGDBLaunchConfigurationConstants.ATTR_GDB_INIT, |
| 220 |
"data/launch/src/launchConfigTestGdbinit"); |
| 221 |
performLaunch(); |
| 222 |
|
| 223 |
MIStoppedEvent stoppedEvent = getInitialStoppedEvent(); |
| 224 |
|
| 225 |
// Check that argc is correct |
| 226 |
final IExpressionDMContext argcDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argc"); |
| 227 |
Query<FormattedValueDMData> query = new Query<FormattedValueDMData>() { |
| 228 |
@Override |
| 229 |
protected void execute(DataRequestMonitor<FormattedValueDMData> rm) { |
| 230 |
fExpService.getFormattedExpressionValue( |
| 231 |
fExpService.getFormattedValueContext(argcDmc, MIExpressions.DETAILS_FORMAT), rm); |
| 232 |
} |
| 233 |
}; |
| 234 |
try { |
| 235 |
fExpService.getExecutor().execute(query); |
| 236 |
FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS); |
| 237 |
|
| 238 |
// Argc should be 7: the program name and the six arguments |
| 239 |
assertTrue("Expected 7 but got " + value.getFormattedValue(), |
| 240 |
value.getFormattedValue().trim().equals("7")); |
| 241 |
} catch (InterruptedException e) { |
| 242 |
fail(e.getMessage()); |
| 243 |
} catch (ExecutionException e) { |
| 244 |
fail(e.getCause().getMessage()); |
| 245 |
} catch (TimeoutException e) { |
| 246 |
fail(e.getMessage()); |
| 247 |
} |
| 248 |
|
| 249 |
// Check that argv is also correct. For simplicity we only check the last argument |
| 250 |
final IExpressionDMContext argvDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argv[argc-1]"); |
| 251 |
Query<FormattedValueDMData> query2 = new Query<FormattedValueDMData>() { |
| 252 |
@Override |
| 253 |
protected void execute(DataRequestMonitor<FormattedValueDMData> rm) { |
| 254 |
fExpService.getFormattedExpressionValue( |
| 255 |
fExpService.getFormattedValueContext(argvDmc, MIExpressions.DETAILS_FORMAT), rm); |
| 256 |
} |
| 257 |
}; |
| 258 |
try { |
| 259 |
fExpService.getExecutor().execute(query2); |
| 260 |
FormattedValueDMData value = query2.get(500, TimeUnit.MILLISECONDS); |
| 261 |
assertTrue("Expected \"6\" but got " + value.getFormattedValue(), |
| 262 |
value.getFormattedValue().trim().endsWith("\"6\"")); |
| 263 |
} catch (InterruptedException e) { |
| 264 |
fail(e.getMessage()); |
| 265 |
} catch (ExecutionException e) { |
| 266 |
fail(e.getCause().getMessage()); |
| 267 |
} catch (TimeoutException e) { |
| 268 |
fail(e.getMessage()); |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
/** |
| 273 |
* Repeat the test testSourceGdbInit, but after a restart. |
| 274 |
*/ |
| 275 |
@Test |
| 276 |
public void testSourceGdbInitRestart() throws Throwable { |
| 277 |
fRestart = true; |
| 278 |
testSourceGdbInit(); |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* This test will tell the launch to clear the environment variables. We will |
| 283 |
* then check that the variable $HOME cannot be found by the program. |
| 284 |
*/ |
| 285 |
@Test |
| 286 |
public void testClearingEnvironment() throws Throwable { |
| 287 |
setLaunchAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, false); |
| 288 |
performLaunch(); |
| 289 |
|
| 290 |
SyncUtil.runToLocation("envTest"); |
| 291 |
MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER); |
| 292 |
|
| 293 |
// The program has stored the content of $HOME into a variable called 'home'. |
| 294 |
// Let's verify this variable is 0x0 which means $HOME does not exist. |
| 295 |
final IExpressionDMContext exprDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "home"); |
| 296 |
Query<FormattedValueDMData> query = new Query<FormattedValueDMData>() { |
| 297 |
@Override |
| 298 |
protected void execute(DataRequestMonitor<FormattedValueDMData> rm) { |
| 299 |
fExpService.getFormattedExpressionValue( |
| 300 |
fExpService.getFormattedValueContext(exprDmc, MIExpressions.DETAILS_FORMAT), rm); |
| 301 |
} |
| 302 |
}; |
| 303 |
try { |
| 304 |
fExpService.getExecutor().execute(query); |
| 305 |
FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS); |
| 306 |
assertTrue("Expected 0x0 but got " + value.getFormattedValue(), |
| 307 |
value.getFormattedValue().equals("0x0")); |
| 308 |
} catch (InterruptedException e) { |
| 309 |
fail(e.getMessage()); |
| 310 |
} catch (ExecutionException e) { |
| 311 |
fail(e.getCause().getMessage()); |
| 312 |
} catch (TimeoutException e) { |
| 313 |
fail(e.getMessage()); |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Repeat the test testClearingEnvironment, but after a restart. |
| 319 |
*/ |
| 320 |
@Test |
| 321 |
public void testClearingEnvironmentRestart() throws Throwable { |
| 322 |
fRestart = true; |
| 323 |
testClearingEnvironment(); |
| 324 |
} |
| 325 |
|
| 326 |
/** |
| 327 |
* This test will tell the launch to set a new environment variable LAUNCHTEST. |
| 328 |
* We will then check that this new variable can be read by the program. |
| 329 |
*/ |
| 330 |
@Test |
| 331 |
public void testSettingEnvironment() throws Throwable { |
| 332 |
setLaunchAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true); |
| 333 |
|
| 334 |
Map<String, String> map = new HashMap<String, String>(1); |
| 335 |
map.put("LAUNCHTEST", "IS SET"); |
| 336 |
setLaunchAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map); |
| 337 |
performLaunch(); |
| 338 |
|
| 339 |
SyncUtil.runToLocation("envTest"); |
| 340 |
MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER); |
| 341 |
|
| 342 |
// The program has stored the content of $LAUNCHTEST into a variable called 'launchTest'. |
| 343 |
// Let's verify this variable is set to "IS SET". |
| 344 |
final IExpressionDMContext exprDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "launchTest"); |
| 345 |
Query<FormattedValueDMData> query = new Query<FormattedValueDMData>() { |
| 346 |
@Override |
| 347 |
protected void execute(DataRequestMonitor<FormattedValueDMData> rm) { |
| 348 |
fExpService.getFormattedExpressionValue( |
| 349 |
fExpService.getFormattedValueContext(exprDmc, MIExpressions.DETAILS_FORMAT), rm); |
| 350 |
} |
| 351 |
}; |
| 352 |
try { |
| 353 |
fExpService.getExecutor().execute(query); |
| 354 |
FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS); |
| 355 |
assertTrue("Expected a string ending with \"IS SET\" but got " + value.getFormattedValue(), |
| 356 |
value.getFormattedValue().trim().endsWith("\"IS SET\"")); |
| 357 |
} catch (InterruptedException e) { |
| 358 |
fail(e.getMessage()); |
| 359 |
} catch (ExecutionException e) { |
| 360 |
fail(e.getCause().getMessage()); |
| 361 |
} catch (TimeoutException e) { |
| 362 |
fail(e.getMessage()); |
| 363 |
} |
| 364 |
|
| 365 |
// Check that the normal environment is there by checking that $HOME (which is stored in 'home" exists. |
| 366 |
final IExpressionDMContext exprDmc2 = SyncUtil.createExpression(stoppedEvent.getDMContext(), "home"); |
| 367 |
Query<FormattedValueDMData> query2 = new Query<FormattedValueDMData>() { |
| 368 |
@Override |
| 369 |
protected void execute(DataRequestMonitor<FormattedValueDMData> rm) { |
| 370 |
fExpService.getFormattedExpressionValue( |
| 371 |
fExpService.getFormattedValueContext(exprDmc2, MIExpressions.DETAILS_FORMAT), rm); |
| 372 |
} |
| 373 |
}; |
| 374 |
try { |
| 375 |
fExpService.getExecutor().execute(query2); |
| 376 |
FormattedValueDMData value = query2.get(500, TimeUnit.MILLISECONDS); |
| 377 |
assertFalse("Expected something else than 0x0", |
| 378 |
value.getFormattedValue().equals("0x0")); |
| 379 |
} catch (InterruptedException e) { |
| 380 |
fail(e.getMessage()); |
| 381 |
} catch (ExecutionException e) { |
| 382 |
fail(e.getCause().getMessage()); |
| 383 |
} catch (TimeoutException e) { |
| 384 |
fail(e.getMessage()); |
| 385 |
} |
| 386 |
|
| 387 |
} |
| 388 |
|
| 389 |
/** |
| 390 |
* Repeat the test testSettingEnvironment, but after a restart. |
| 391 |
*/ |
| 392 |
@Test |
| 393 |
public void testSettingEnvironmentRestart() throws Throwable { |
| 394 |
fRestart = true; |
| 395 |
testSettingEnvironment(); |
| 396 |
} |
| 397 |
|
| 398 |
/** |
| 399 |
* This test will tell the launch to clear the environment variables and then |
| 400 |
* set a new environment variable LAUNCHTEST. We will then check that the variable |
| 401 |
* $HOME cannot be found by the program and that the new variable LAUNCHTEST can be |
| 402 |
* read by the program. |
| 403 |
*/ |
| 404 |
@Test |
| 405 |
public void testClearingAndSettingEnvironment() throws Throwable { |
| 406 |
setLaunchAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, false); |
| 407 |
|
| 408 |
Map<String, String> map = new HashMap<String, String>(1); |
| 409 |
map.put("LAUNCHTEST", "IS SET"); |
| 410 |
setLaunchAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map); |
| 411 |
performLaunch(); |
| 412 |
|
| 413 |
SyncUtil.runToLocation("envTest"); |
| 414 |
MIStoppedEvent stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER); |
| 415 |
|
| 416 |
// The program has stored the content of $LAUNCHTEST into a variable called 'launchTest'. |
| 417 |
// Let's verify this variable is set to "IS SET". |
| 418 |
final IExpressionDMContext exprDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "launchTest"); |
| 419 |
Query<FormattedValueDMData> query = new Query<FormattedValueDMData>() { |
| 420 |
@Override |
| 421 |
protected void execute(DataRequestMonitor<FormattedValueDMData> rm) { |
| 422 |
fExpService.getFormattedExpressionValue( |
| 423 |
fExpService.getFormattedValueContext(exprDmc, MIExpressions.DETAILS_FORMAT), rm); |
| 424 |
} |
| 425 |
}; |
| 426 |
try { |
| 427 |
fExpService.getExecutor().execute(query); |
| 428 |
FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS); |
| 429 |
assertTrue("Expected a string ending with \"IS SET\" but got " + value.getFormattedValue(), |
| 430 |
value.getFormattedValue().trim().endsWith("\"IS SET\"")); |
| 431 |
} catch (InterruptedException e) { |
| 432 |
fail(e.getMessage()); |
| 433 |
} catch (ExecutionException e) { |
| 434 |
fail(e.getCause().getMessage()); |
| 435 |
} catch (TimeoutException e) { |
| 436 |
fail(e.getMessage()); |
| 437 |
} |
| 438 |
|
| 439 |
// The program has stored the content of $HOME into a variable called 'home'. |
| 440 |
// Let's verify this variable is 0x0 which means it does not exist. |
| 441 |
final IExpressionDMContext exprDmc2 = SyncUtil.createExpression(stoppedEvent.getDMContext(), "home"); |
| 442 |
Query<FormattedValueDMData> query2 = new Query<FormattedValueDMData>() { |
| 443 |
@Override |
| 444 |
protected void execute(DataRequestMonitor<FormattedValueDMData> rm) { |
| 445 |
fExpService.getFormattedExpressionValue( |
| 446 |
fExpService.getFormattedValueContext(exprDmc2, MIExpressions.DETAILS_FORMAT), rm); |
| 447 |
} |
| 448 |
}; |
| 449 |
try { |
| 450 |
fExpService.getExecutor().execute(query2); |
| 451 |
FormattedValueDMData value = query2.get(500, TimeUnit.MILLISECONDS); |
| 452 |
assertTrue("Expected 0x0 but got " + value.getFormattedValue(), |
| 453 |
value.getFormattedValue().equals("0x0")); |
| 454 |
} catch (InterruptedException e) { |
| 455 |
fail(e.getMessage()); |
| 456 |
} catch (ExecutionException e) { |
| 457 |
fail(e.getCause().getMessage()); |
| 458 |
} catch (TimeoutException e) { |
| 459 |
fail(e.getMessage()); |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
/** |
| 464 |
* Repeat the test testClearingAndSettingEnvironment, but after a restart. |
| 465 |
*/ |
| 466 |
@Test |
| 467 |
public void testClearingAndSettingEnvironmentRestart() throws Throwable { |
| 468 |
fRestart = true; |
| 469 |
testClearingAndSettingEnvironment(); |
| 470 |
} |
| 471 |
|
| 472 |
/** |
| 473 |
* This test will tell the launch to set some arguments for the program. We will |
| 474 |
* then check that the program has the same arguments. |
| 475 |
*/ |
| 476 |
@Test |
| 477 |
public void testSettingArguments() throws Throwable { |
| 478 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "1 2 3\n4 5 6"); |
| 479 |
performLaunch(); |
| 480 |
|
| 481 |
MIStoppedEvent stoppedEvent = getInitialStoppedEvent(); |
| 482 |
|
| 483 |
// Check that argc is correct |
| 484 |
final IExpressionDMContext argcDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argc"); |
| 485 |
Query<FormattedValueDMData> query = new Query<FormattedValueDMData>() { |
| 486 |
@Override |
| 487 |
protected void execute(DataRequestMonitor<FormattedValueDMData> rm) { |
| 488 |
fExpService.getFormattedExpressionValue( |
| 489 |
fExpService.getFormattedValueContext(argcDmc, MIExpressions.DETAILS_FORMAT), rm); |
| 490 |
} |
| 491 |
}; |
| 492 |
try { |
| 493 |
fExpService.getExecutor().execute(query); |
| 494 |
FormattedValueDMData value = query.get(500, TimeUnit.MILLISECONDS); |
| 495 |
|
| 496 |
// Argc should be 7: the program name and the six arguments |
| 497 |
assertTrue("Expected 7 but got " + value.getFormattedValue(), |
| 498 |
value.getFormattedValue().trim().equals("7")); |
| 499 |
} catch (InterruptedException e) { |
| 500 |
fail(e.getMessage()); |
| 501 |
} catch (ExecutionException e) { |
| 502 |
fail(e.getCause().getMessage()); |
| 503 |
} catch (TimeoutException e) { |
| 504 |
fail(e.getMessage()); |
| 505 |
} |
| 506 |
|
| 507 |
// Check that argv is also correct. For simplicity we only check the last argument |
| 508 |
final IExpressionDMContext argvDmc = SyncUtil.createExpression(stoppedEvent.getDMContext(), "argv[argc-1]"); |
| 509 |
Query<FormattedValueDMData> query2 = new Query<FormattedValueDMData>() { |
| 510 |
@Override |
| 511 |
protected void execute(DataRequestMonitor<FormattedValueDMData> rm) { |
| 512 |
fExpService.getFormattedExpressionValue( |
| 513 |
fExpService.getFormattedValueContext(argvDmc, MIExpressions.DETAILS_FORMAT), rm); |
| 514 |
} |
| 515 |
}; |
| 516 |
try { |
| 517 |
fExpService.getExecutor().execute(query2); |
| 518 |
FormattedValueDMData value = query2.get(500, TimeUnit.MILLISECONDS); |
| 519 |
assertTrue("Expected \"6\" but got " + value.getFormattedValue(), |
| 520 |
value.getFormattedValue().trim().endsWith("\"6\"")); |
| 521 |
} catch (InterruptedException e) { |
| 522 |
fail(e.getMessage()); |
| 523 |
} catch (ExecutionException e) { |
| 524 |
fail(e.getCause().getMessage()); |
| 525 |
} catch (TimeoutException e) { |
| 526 |
fail(e.getMessage()); |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
/** |
| 531 |
* Repeat the test testSettingArguments, but after a restart. |
| 532 |
*/ |
| 533 |
@Test |
| 534 |
public void testSettingArgumentsRestart() throws Throwable { |
| 535 |
fRestart = true; |
| 536 |
testSettingArguments(); |
| 537 |
} |
| 538 |
|
| 539 |
/** |
| 540 |
* This test will tell the launch to "stop on main" at method main(), which we will verify. |
| 541 |
*/ |
| 542 |
@Test |
| 543 |
public void testStopAtMain() throws Throwable { |
| 544 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, true); |
| 545 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, "main"); |
| 546 |
performLaunch(); |
| 547 |
|
| 548 |
MIStoppedEvent stoppedEvent = getInitialStoppedEvent(); |
| 549 |
assertTrue("Expected to stop at main:27 but got " + |
| 550 |
stoppedEvent.getFrame().getFunction() + ":" + |
| 551 |
Integer.toString(stoppedEvent.getFrame().getLine()), |
| 552 |
stoppedEvent.getFrame().getFunction().equals("main") && |
| 553 |
stoppedEvent.getFrame().getLine() == 27); |
| 554 |
} |
| 555 |
|
| 556 |
/** |
| 557 |
* Repeat the test testStopAtMain, but after a restart. |
| 558 |
*/ |
| 559 |
@Test |
| 560 |
public void testStopAtMainRestart() throws Throwable { |
| 561 |
fRestart = true; |
| 562 |
testStopAtMain(); |
| 563 |
} |
| 564 |
|
| 565 |
/** |
| 566 |
* This test will tell the launch to "stop on main" at method stopAtOther(), |
| 567 |
* which we will then verify. |
| 568 |
*/ |
| 569 |
@Test |
| 570 |
public void testStopAtOther() throws Throwable { |
| 571 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, true); |
| 572 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, "stopAtOther"); |
| 573 |
performLaunch(); |
| 574 |
|
| 575 |
MIStoppedEvent stoppedEvent = getInitialStoppedEvent(); |
| 576 |
assertTrue("Expected to stop at stopAtOther but got " + |
| 577 |
stoppedEvent.getFrame().getFunction() + ":", |
| 578 |
stoppedEvent.getFrame().getFunction().equals("stopAtOther")); |
| 579 |
} |
| 580 |
|
| 581 |
/** |
| 582 |
* Repeat the test testStopAtOther, but after a restart. |
| 583 |
*/ |
| 584 |
@Test |
| 585 |
public void testStopAtOtherRestart() throws Throwable { |
| 586 |
fRestart = true; |
| 587 |
testStopAtOther(); |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
/** |
| 592 |
* This test will set a breakpoint at some place in the program and will tell |
| 593 |
* the launch to NOT "stop on main". We will verify that the first stop is |
| 594 |
* at the breakpoint that we set. |
| 595 |
*/ |
| 596 |
@Ignore |
| 597 |
@Test |
| 598 |
public void testNoStopAtMain() throws Throwable { |
| 599 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false); |
| 600 |
// Set this one as well to make sure it gets ignored |
| 601 |
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, "main"); |
| 602 |
|
| 603 |
// We need to set the breakpoint before the launch is started, but the only way to do that is |
| 604 |
// to set it in the platorm. Ok, but how do I get an IResource that points to my binary? |
| 605 |
// The current workspace is the JUnit runtime workspace instead of the workspace containing |
| 606 |
// the JUnit tests. |
| 607 |
|
| 608 |
IFile fakeFile = null; |
| 609 |
CDIDebugModel.createLineBreakpoint(PROGRAM, fakeFile, ICBreakpointType.REGULAR, LAST_LINE_IN_MAIN + 1, true, 0, "", true); //$NON-NLS-1$ |
| 610 |
performLaunch(); |
| 611 |
|
| 612 |
MIStoppedEvent stoppedEvent = getInitialStoppedEvent(); |
| 613 |
assertTrue("Expected to stop at envTest but got " + |
| 614 |
stoppedEvent.getFrame().getFunction() + ":", |
| 615 |
stoppedEvent.getFrame().getFunction().equals("envTest")); |
| 616 |
} |
| 617 |
|
| 618 |
/** |
| 619 |
* Repeat the test testNoStopAtMain, but after a restart. |
| 620 |
*/ |
| 621 |
@Ignore |
| 622 |
@Test |
| 623 |
public void testNoStopAtMainRestart() throws Throwable { |
| 624 |
fRestart = true; |
| 625 |
testNoStopAtMain(); |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
} |