From 935e88036d7aa8622f23ba3a717454aaee88c888 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 17 Jul 2014 16:57:40 -0400 Subject: [PATCH] Bug 438934 - Failure in MIMemoryTest.asynchronousReadWrite because of a concurency issue where the AsyncCompletionWaitor was being accessed by more than one thread but was not properly synchronized. Change-Id: I5c6f063ca519787a0cc45281c0632fcf07b763d5 Signed-off-by: Marc Khouzam Reviewed-on: https://git.eclipse.org/r/30089 Tested-by: Hudson CI --- .../gdb/framework/AsyncCompletionWaitor.java | 10 ++--- .../cdt/tests/dsf/gdb/tests/MIMemoryTest.java | 38 +------------------ 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/AsyncCompletionWaitor.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/AsyncCompletionWaitor.java index a1439d271d0..93424e29395 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/AsyncCompletionWaitor.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/AsyncCompletionWaitor.java @@ -89,7 +89,7 @@ public class AsyncCompletionWaitor { fNumWaiting = 0; } - public boolean isOK() { + public synchronized boolean isOK() { if ( fStatus == null ) { // We timed out return false; @@ -98,7 +98,7 @@ public class AsyncCompletionWaitor { return fStatus.isOK(); } - public String getMessage() { + public synchronized String getMessage() { if ( fStatus == null ) { return "Timed out"; //$NON-NLS-1$ } @@ -115,15 +115,15 @@ public class AsyncCompletionWaitor { return fullMessage.length() <= 2 ? fullMessage : fullMessage.substring(0, fullMessage.length() - 2); } - public void setReturnInfo(Object info) { + public synchronized void setReturnInfo(Object info) { fReturnInfo = info ; } - public Object getReturnInfo() { + public synchronized Object getReturnInfo() { return fReturnInfo; } - public void increment() { + public synchronized void increment() { if (fWaitFinished) { ((MultiStatus)fStatus).merge( new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIMemoryTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIMemoryTest.java index 86ce9de3a6b..8bdac904fbf 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIMemoryTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIMemoryTest.java @@ -22,8 +22,6 @@ import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.debug.service.IExpressions; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; import org.eclipse.cdt.dsf.debug.service.IFormattedValues; -import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext; -import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData; import org.eclipse.cdt.dsf.debug.service.IMemory; import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryChangedEvent; import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryDMContext; @@ -217,40 +215,8 @@ public class MIMemoryTest extends BaseTestCase { */ private IAddress evaluateExpression(IDMContext ctx, String expression) throws Throwable { - // Create the expression and format contexts - final IExpressionDMContext expressionDMC = SyncUtil.createExpression(ctx, expression); - final FormattedValueDMContext formattedValueDMC = SyncUtil.getFormattedValue(fExpressionService, expressionDMC, IFormattedValues.HEX_FORMAT); - - // Create the DataRequestMonitor which will store the operation result in the wait object - final DataRequestMonitor drm = - new DataRequestMonitor(fSession.getExecutor(), null) { - @Override - protected void handleCompleted() { - if (isSuccess()) { - fWait.setReturnInfo(getData()); - } - fWait.waitFinished(getStatus()); - } - }; - - // Evaluate the expression (asynchronously) - fSession.getExecutor().submit(new Runnable() { - @Override - public void run() { - fExpressionService.getFormattedExpressionValue(formattedValueDMC, drm); - } - }); - - // Wait for completion - fWait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER); - assertTrue(fWait.getMessage(), fWait.isOK()); - - // Return the string formatted by the back-end - String result = ""; - Object returnInfo = fWait.getReturnInfo(); - if (returnInfo instanceof FormattedValueDMData) - result = ((FormattedValueDMData) returnInfo).getFormattedValue(); - return new Addr64(result); + IExpressionDMContext expressionDMC = SyncUtil.createExpression(ctx, expression); + return new Addr64(SyncUtil.getExpressionValue(expressionDMC, IFormattedValues.HEX_FORMAT)); } /* ------------------------------------------------------------------------