diff options
author | Pawel Piech | 2012-05-01 04:19:38 +0000 |
---|---|---|
committer | Eugene Tarassov | 2012-05-11 18:57:20 +0000 |
commit | b83ec96307bae55571efb0bc11eea9c33659ad22 (patch) | |
tree | cb643acaf719fd5fd3e92d6651e89abad9b37d8c /tests | |
parent | a085832e6a99ba77526599026a19b4b934be9ae1 (diff) | |
download | org.eclipse.tcf-b83ec96307bae55571efb0bc11eea9c33659ad22.tar.gz org.eclipse.tcf-b83ec96307bae55571efb0bc11eea9c33659ad22.tar.xz org.eclipse.tcf-b83ec96307bae55571efb0bc11eea9c33659ad22.zip |
Bug 379189 - [tests] Add test to measure stepping performance
Added tests that validate instruction pointer annotations.
Diffstat (limited to 'tests')
8 files changed, 366 insertions, 5 deletions
diff --git a/tests/plugins/org.eclipse.tcf.debug.test/META-INF/MANIFEST.MF b/tests/plugins/org.eclipse.tcf.debug.test/META-INF/MANIFEST.MF index 3c0aa9eb6..b3136d046 100644 --- a/tests/plugins/org.eclipse.tcf.debug.test/META-INF/MANIFEST.MF +++ b/tests/plugins/org.eclipse.tcf.debug.test/META-INF/MANIFEST.MF @@ -14,7 +14,11 @@ Require-Bundle: org.eclipse.ui, org.eclipse.cdt.debug.core;bundle-version="7.2.0", org.eclipse.tcf.cdt.ui;bundle-version="1.0.0", org.eclipse.tcf.te.tcf.locator;bundle-version="1.0.0", - org.eclipse.tcf.te.tests;bundle-version="1.0.0" + org.eclipse.tcf.te.tests;bundle-version="1.0.0", + org.eclipse.ui.workbench.texteditor;bundle-version="3.8.0", + org.eclipse.jface.text;bundle-version="3.8.0", + org.eclipse.ui.ide;bundle-version="3.8.0", + org.eclipse.core.filesystem;bundle-version="1.3.200" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: org.eclipse.debug.internal.ui.viewers.model diff --git a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/AbstractTcfUITest.java b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/AbstractTcfUITest.java index 6016324bf..7995951c7 100644 --- a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/AbstractTcfUITest.java +++ b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/AbstractTcfUITest.java @@ -96,6 +96,8 @@ public abstract class AbstractTcfUITest extends TcfTestCase implements IViewerUp protected VirtualViewerUpdatesListener fVariablesViewListener; protected VariablesVirtualTreeModelViewer fRegistersViewViewer; protected VirtualViewerUpdatesListener fRegistersViewListener; + protected TestSourceDisplayService fSourceDisplayService; + protected SourceDisplayListener fSourceDisplayListener; protected Object fTestRunKey; @@ -286,6 +288,8 @@ public abstract class AbstractTcfUITest extends TcfTestCase implements IViewerUp fVariablesViewListener = new VirtualViewerUpdatesListener(fVariablesViewViewer); fRegistersViewViewer = new VariablesVirtualTreeModelViewer(IDebugUIConstants.ID_REGISTER_VIEW, fDebugContextProvider); fRegistersViewListener = new VirtualViewerUpdatesListener(fRegistersViewViewer); + fSourceDisplayService = new TestSourceDisplayService(fDebugContextProvider); + fSourceDisplayListener = new SourceDisplayListener(); } }); } @@ -294,6 +298,8 @@ public abstract class AbstractTcfUITest extends TcfTestCase implements IViewerUp final Display display = Display.getDefault(); display.syncExec(new Runnable() { public void run() { + fSourceDisplayListener.dispose(); + fSourceDisplayService.dispose(); fDebugViewListener.dispose(); fDebugContextProvider.dispose(); fDebugViewViewer.dispose(); diff --git a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/SampleTest.java b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/SampleTest.java index 7ab497620..0585cb4c9 100644 --- a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/SampleTest.java +++ b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/SampleTest.java @@ -36,7 +36,6 @@ public class SampleTest extends AbstractTcfUITest { VirtualItem threadItem = fDebugViewListener.findElement(processItem, new Pattern[] { Pattern.compile(".*" + fThreadId + ".*") } ); Assert.assertTrue(threadItem != null); - VirtualItem frameItem = fDebugViewListener.findElement(threadItem, new Pattern[] { Pattern.compile(".*tcf_test_func0.*")}); Assert.assertTrue(frameItem != null); } @@ -87,6 +86,51 @@ public class SampleTest extends AbstractTcfUITest { previousThreadLabel = topFrameLabel; } } + + public void testSteppingSourceDisplay() throws Exception { + initProcessModel("tcf_test_func0"); + + // Execute step loop + String previousThreadLabel = null; + for (int stepNum = 0; stepNum < 100; stepNum++) { + fDebugViewListener.reset(); + fSourceDisplayListener.reset(); + + resumeAndWaitForSuspend(fThreadCtx, IRunControl.RM_STEP_INTO_LINE); + CodeArea area = calcPCCodeArea(); + if (area != null) { + fSourceDisplayListener.setCodeArea(calcPCCodeArea()); + } + + fDebugViewListener.waitTillFinished(MODEL_CHANGED_COMPLETE | CONTENT_SEQUENCE_COMPLETE | LABEL_UPDATES_RUNNING); + if (area != null) { + fSourceDisplayListener.waitTillFinished(); + } + + VirtualItem topFrameItem = fDebugViewListener.findElement( + new Pattern[] { Pattern.compile(".*"), Pattern.compile(".*"), Pattern.compile(".*" + fProcessId + ".*\\(Step.*"), Pattern.compile(".*")}); + Assert.assertTrue(topFrameItem != null); + String topFrameLabel = ((String[])topFrameItem.getData(VirtualItem.LABEL_KEY))[0]; + Assert.assertTrue(!topFrameLabel.equals(previousThreadLabel)); + previousThreadLabel = topFrameLabel; + } + } + + private CodeArea calcPCCodeArea() throws ExecutionException, InterruptedException { + return new Transaction<CodeArea>() { + @Override + protected CodeArea process() throws Transaction.InvalidCacheException ,ExecutionException { + String pc = validate(fRunControlCM.getState(fThreadId)).pc; + BigInteger pcNumber = new BigInteger(pc); + BigInteger pcNumberPlusOne = pcNumber.add(BigInteger.valueOf(1)); + CodeArea[] areas = validate(fLineNumbersCM.mapToSource(fThreadId, pcNumber, pcNumberPlusOne)); + if (areas.length >= 1) { + return areas[0]; + } + return null; + } + }.get(); + } public void testSymbolsCMResetOnContextRemove() throws Exception { initProcessModel("tcf_test_func0"); diff --git a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/SourceDisplayListener.java b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/SourceDisplayListener.java new file mode 100644 index 000000000..b59df2a12 --- /dev/null +++ b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/SourceDisplayListener.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.debug.test; + +import java.util.Iterator; + +import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IAnnotationModelListener; +import org.eclipse.tcf.services.ILineNumbers.CodeArea; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.FileStoreEditorInput; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * + */ +public class SourceDisplayListener implements IPartListener, IAnnotationModelListener { + + private static final String ANNOTATION_TOP_FRAME = "org.eclipse.tcf.debug.top_frame"; + + private IWorkbenchPage fPage; + private ITextEditor fActiveEditor; + + private IPath fExpectedFile; + private int fExpectedLine; + + private boolean fFileFound = false; + private boolean fAnnotationFound = false; + private IAnnotationModel fAnnotationModel = null; + + public SourceDisplayListener() { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + fPage = window.getActivePage(); + fPage.addPartListener(this); + fPage.getWorkbenchWindow().getShell().getDisplay().asyncExec(new Runnable() { + public void run() { + partBroughtToTop(fPage.getActiveEditor()); + } + }); + } + + public void dispose() { + if (fAnnotationModel != null) { + fAnnotationModel.removeAnnotationModelListener(this); + fAnnotationModel = null; + } + fPage.removePartListener(this); + } + + public void reset() { + fFileFound = false; + fAnnotationFound = false; + } + + public void setCodeArea(CodeArea area) { + fExpectedFile = new Path(area.file); + fExpectedLine = area.start_line; + checkFile(); + } + + public void waitTillFinished() throws InterruptedException { + synchronized(this) { + while(!isFinished()) { + wait(100); + } + } + } + + public synchronized boolean isFinished() { + return fFileFound && fAnnotationFound; + } + + public void partActivated(IWorkbenchPart part) { + System.out.println("activated"); + partBroughtToTop(part); + } + + public void partBroughtToTop(IWorkbenchPart part) { + System.out.println("top"); + fActiveEditor = null; + if (fAnnotationModel != null) { + fAnnotationModel.removeAnnotationModelListener(this); + } + + if (part instanceof ITextEditor) { + fActiveEditor = ((ITextEditor)part); + checkFile(); + } + } + public void partClosed(IWorkbenchPart part) { + System.out.println("closed"); + + } + public void partDeactivated(IWorkbenchPart part) { + System.out.println("deactivated"); + } + public void partOpened(IWorkbenchPart part) { + System.out.println("opened"); + } + + public void modelChanged(IAnnotationModel model) { + checkAnnotations(); + } + + private synchronized void checkFile() { + if (fActiveEditor == null) return; + IEditorInput input = fActiveEditor.getEditorInput(); + IPath location = null; + + if (input instanceof IFileEditorInput) { + IFile file = ((IFileEditorInput)input).getFile(); + location = file.getLocation(); + } else if (input instanceof FileStoreEditorInput) { + location = URIUtil.toPath(((FileStoreEditorInput)input).getURI()); + } + + if (location != null && fExpectedFile != null && + location.lastSegment().equals(fExpectedFile.lastSegment())) + { + fFileFound = true; + + IDocumentProvider docProvider = fActiveEditor.getDocumentProvider(); + fAnnotationModel = docProvider.getAnnotationModel(fActiveEditor.getEditorInput()); + fAnnotationModel.addAnnotationModelListener(this); + + checkAnnotations(); + } + } + + private synchronized void checkAnnotations() { + Position expectedPosition = calcExpectedPosition(); + if (checkTopFrameAnnotation(expectedPosition)) { + fAnnotationFound = true; + } + } + + private Position calcExpectedPosition() { + IDocument doc = fActiveEditor.getDocumentProvider().getDocument(fActiveEditor.getEditorInput()); + if (doc == null) return null; + try { + IRegion region = doc.getLineInformation(fExpectedLine - 1); + return new Position(region.getOffset(), region.getLength()); + } catch (BadLocationException e) { + } + return null; + } + + private boolean checkTopFrameAnnotation(Position pos) { + if (fAnnotationModel == null) return false; + + for (Iterator<?> itr = fAnnotationModel.getAnnotationIterator(); itr.hasNext();) { + Annotation ann = (Annotation)itr.next(); + if ( ANNOTATION_TOP_FRAME.equals(ann.getType()) ) { + // Compare requested line to annotation location. + if (pos.equals(fAnnotationModel.getPosition(ann))) { + return true; + } + } + } + return false; + } + +} diff --git a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/TestDebugContextProvider.java b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/TestDebugContextProvider.java index 7d127ab7a..26793b6b5 100644 --- a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/TestDebugContextProvider.java +++ b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/TestDebugContextProvider.java @@ -17,6 +17,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDeltaVisitor; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy; import org.eclipse.debug.internal.ui.viewers.model.provisional.ITreeModelViewer; +import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.contexts.AbstractDebugContextProvider; import org.eclipse.debug.ui.contexts.DebugContextEvent; import org.eclipse.jface.viewers.ISelection; @@ -26,6 +27,8 @@ import org.eclipse.jface.viewers.ITreeSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TreePath; import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; /** * Copied from org.eclipse.debug.internal.ui.views.launch.LaunchView class. @@ -36,6 +39,7 @@ import org.eclipse.swt.widgets.Display; @SuppressWarnings("restriction") public class TestDebugContextProvider extends AbstractDebugContextProvider implements IModelChangedListener, ISelectionChangedListener{ + private IWorkbenchWindow fWindow = null; private ISelection fContext = null; private ITreeModelViewer fViewer = null; private Visitor fVisitor = new Visitor(); @@ -82,9 +86,16 @@ public class TestDebugContextProvider extends AbstractDebugContextProvider imple fViewer = viewer; fViewer.addModelChangedListener(this); fViewer.addSelectionChangedListener(this); + fWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (fWindow != null) { + DebugUITools.getDebugContextManager().getContextService(fWindow).addDebugContextProvider(this); + } } protected void dispose() { + if (fWindow != null) { + DebugUITools.getDebugContextManager().getContextService(fWindow).removeDebugContextProvider(this); + } fContext = null; fViewer.removeModelChangedListener(this); fViewer.removeSelectionChangedListener(this); diff --git a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/TestSourceDisplayService.java b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/TestSourceDisplayService.java new file mode 100644 index 000000000..81ebc8dac --- /dev/null +++ b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/TestSourceDisplayService.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.debug.test; + +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.ui.contexts.DebugContextEvent; +import org.eclipse.debug.ui.contexts.IDebugContextListener; +import org.eclipse.debug.ui.contexts.IDebugContextProvider; +import org.eclipse.debug.ui.sourcelookup.ISourceDisplay; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +/** + * + */ +public class TestSourceDisplayService implements IDebugContextListener { + + private IDebugContextProvider fDebugContextProvider; + + public TestSourceDisplayService(IDebugContextProvider debugContextProvider) { + fDebugContextProvider = debugContextProvider; + fDebugContextProvider.addDebugContextListener(this); + } + + public void dispose() { + fDebugContextProvider.removeDebugContextListener(this); + } + + public void debugContextChanged(DebugContextEvent event) { + if ((event.getFlags() & DebugContextEvent.ACTIVATED) == 0) return; + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window == null) return; + + if (event.getContext() instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection)event.getContext(); + if (structuredSelection.size() == 1) { + Object context = (structuredSelection).getFirstElement(); + IWorkbenchPage page = null; + page = window.getActivePage(); + ISourceDisplay adapter = (ISourceDisplay) DebugPlugin.getAdapter(context, ISourceDisplay.class); + if (adapter != null) { + adapter.displaySource(context, page, false); + } + } + } + } + +} diff --git a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/services/LineNumbersCM.java b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/services/LineNumbersCM.java index 639554384..23f513343 100644 --- a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/services/LineNumbersCM.java +++ b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/services/LineNumbersCM.java @@ -13,11 +13,8 @@ package org.eclipse.tcf.debug.test.services; import java.util.Map; import java.util.concurrent.ExecutionException; -import org.eclipse.tcf.debug.test.util.CallbackCache; -import org.eclipse.tcf.debug.test.util.DataCallback; import org.eclipse.tcf.debug.test.util.ICache; import org.eclipse.tcf.debug.test.util.TokenCache; -import org.eclipse.tcf.debug.test.util.Transaction; import org.eclipse.tcf.debug.test.util.TransactionCache; import org.eclipse.tcf.protocol.IToken; import org.eclipse.tcf.services.ILineNumbers; diff --git a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/services/SymbolsCM.java b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/services/SymbolsCM.java index b0c276c2f..f87b90f6a 100644 --- a/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/services/SymbolsCM.java +++ b/tests/plugins/org.eclipse.tcf.debug.test/src/org/eclipse/tcf/debug/test/services/SymbolsCM.java @@ -250,6 +250,60 @@ public class SymbolsCM extends AbstractCacheManager { return mapCache(new ContextCacheKey(id)); } + private class LocationInfoCache extends SymbolCache<Map<String,Object>> { + public LocationInfoCache(InnerLocationInfoCache inner) { + super(inner); + } + @Override + protected String getSymbolId() { + return ((InnerLocationInfoCache)fInner).fId; + } + } + + class InnerLocationInfoCache extends TokenCache<Map<String,Object>> implements ISymbols.DoneGetLocationInfo { + final String fId; + + public InnerLocationInfoCache(String id) { + fId = id; + } + @Override + protected IToken retrieveToken() { + return fService.getLocationInfo(fId, this); + } + + public void doneGetLocationInfo(IToken token, Exception error, Map<String,Object> props) { + set(token, props, error); + } + + public void resetContext() { + if (isValid()) reset(); + } + } + + private class LocationInfoCacheKey extends IdKey<LocationInfoCache> { + public LocationInfoCacheKey(String id) { + super(LocationInfoCache.class, id); + } + @Override LocationInfoCache createCache() { return new LocationInfoCache( new InnerLocationInfoCache(fId)); } + } + + public ICache<Map<String, Object>> getLocationInfo(String symbol_id) { + return mapCache(new LocationInfoCacheKey(symbol_id)); + } + + /** + * Client call back interface for getLocationInfo(). + */ + interface DoneGetLocationInfo { + /** + * Called when location information retrieval is done. + * @param token - command handle. + * @param error � error description if operation failed, null if succeeded. + * @param props - symbol location properties, see LOC_*. + */ + void doneGetLocationInfo(IToken token, Exception error, Map<String,Object> props); + } + private class FindCache extends SymbolCache<String> { public FindCache(InnerFindCache inner) { super(inner); |