1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Matthew Khouzam - Initial API and implementation
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.kernel
.ui
.swtbot
.tests
;
16 import static org
.junit
.Assert
.assertFalse
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.fail
;
20 import java
.util
.ArrayList
;
21 import java
.util
.Arrays
;
22 import java
.util
.List
;
24 import org
.apache
.log4j
.ConsoleAppender
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.apache
.log4j
.SimpleLayout
;
27 import org
.eclipse
.core
.runtime
.CoreException
;
28 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
29 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.controlflow
.ControlFlowView
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
.ResourcesView
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.TmfEventsEditor
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfOpenTraceHelper
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.swtbot
.tests
.SWTBotUtil
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.swtbot
.tests
.conditions
.ConditionHelpers
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.histogram
.HistogramView
;
43 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
44 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
45 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
46 import org
.eclipse
.swtbot
.swt
.finder
.results
.BoolResult
;
47 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
48 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
49 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotToolbarButton
;
50 import org
.eclipse
.ui
.IEditorPart
;
51 import org
.eclipse
.ui
.IEditorReference
;
52 import org
.eclipse
.ui
.IViewPart
;
53 import org
.eclipse
.ui
.IViewReference
;
54 import org
.eclipse
.ui
.PlatformUI
;
55 import org
.eclipse
.ui
.WorkbenchException
;
56 import org
.junit
.BeforeClass
;
57 import org
.junit
.Test
;
60 * SWTBot Smoke test for LTTng Kernel UI.
62 * @author Matthew Khouzam
64 public class ImportAndReadKernelSmokeTest
{
66 private static final String KERNEL_PERSPECTIVE_ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
67 private static final String TRACE_PROJECT_NAME
= "test";
69 private static SWTWorkbenchBot fBot
;
70 private static CtfTmfTestTrace ctt
= CtfTmfTestTrace
.SYNTHETIC_TRACE
;
71 private ITmfEvent fDesired1
;
72 private ITmfEvent fDesired2
;
74 /** The Log4j logger instance. */
75 private static final Logger fLogger
= Logger
.getRootLogger();
81 public static void init() {
82 SWTBotUtil
.failIfUIThread();
84 /* set up for swtbot */
85 SWTBotPreferences
.TIMEOUT
= 300000; /* 300 second timeout */
86 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
87 fBot
= new SWTWorkbenchBot();
89 final List
<SWTBotView
> openViews
= fBot
.views();
90 for (SWTBotView view
: openViews
) {
91 if (view
.getTitle().equals("Welcome")) {
93 fBot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
96 /* Switch perspectives */
97 switchKernelPerspective();
98 /* Finish waiting for eclipse to load */
99 SWTBotUtil
.waitForJobs();
102 private static void switchKernelPerspective() {
103 final Exception retE
[] = new Exception
[1];
104 if (!UIThreadRunnable
.syncExec(new BoolResult() {
106 public Boolean
run() {
108 PlatformUI
.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID
,
109 PlatformUI
.getWorkbench().getActiveWorkbenchWindow());
110 } catch (WorkbenchException e
) {
117 fail(retE
[0].getMessage());
127 SWTBotUtil
.createProject(TRACE_PROJECT_NAME
);
130 testHV(getViewPart("Histogram"));
131 testCFV((ControlFlowView
) getViewPart("Control Flow"));
132 testRV((ResourcesView
) getViewPart("Resources"));
135 private static void openTrace() {
136 final Exception exception
[] = new Exception
[1];
138 UIThreadRunnable
.syncExec(new VoidResult() {
142 (new TmfOpenTraceHelper()).openTraceFromPath("test", ctt
.getPath(), PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(), "org.eclipse.linuxtools.lttng2.kernel.tracetype");
143 } catch (CoreException e
) {
148 if (exception
[0] != null) {
149 fail(exception
[0].getMessage());
152 SWTBotUtil
.delay(1000);
153 SWTBotUtil
.waitForJobs();
156 private void openEditor() {
157 final List
<IEditorReference
> editorRefs
= new ArrayList
<>();
158 UIThreadRunnable
.syncExec(new VoidResult() {
161 IEditorReference
[] ieds
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
162 editorRefs
.addAll(Arrays
.asList(ieds
));
166 assertFalse(editorRefs
.isEmpty());
167 IEditorPart iep
= null;
168 for (IEditorReference ied
: editorRefs
) {
169 if (ied
.getTitle().equals(ctt
.getTrace().getName())) {
170 iep
= ied
.getEditor(true);
175 fDesired1
= getEvent(100);
176 fDesired2
= getEvent(10000);
177 final TmfEventsEditor tmfEd
= (TmfEventsEditor
) iep
;
178 UIThreadRunnable
.syncExec(new VoidResult() {
182 tmfEd
.selectionChanged(new SelectionChangedEvent(tmfEd
, new StructuredSelection(fDesired1
)));
186 SWTBotUtil
.waitForJobs();
187 SWTBotUtil
.delay(1000);
188 assertNotNull(tmfEd
);
191 private static void testCFV(ControlFlowView vp
) {
195 private void testHV(IViewPart vp
) {
196 SWTBotView hvBot
= (new SWTWorkbenchBot()).viewById(HistogramView
.ID
);
197 List
<SWTBotToolbarButton
> hvTools
= hvBot
.getToolbarButtons();
198 for (SWTBotToolbarButton hvTool
: hvTools
) {
199 if (hvTool
.getToolTipText().toLowerCase().contains("lost")) {
203 HistogramView hv
= (HistogramView
) vp
;
204 final TmfTimeSynchSignal signal
= new TmfTimeSynchSignal(hv
, fDesired1
.getTimestamp());
205 final TmfTimeSynchSignal signal2
= new TmfTimeSynchSignal(hv
, fDesired2
.getTimestamp());
206 hv
.updateTimeRange(100000);
207 SWTBotUtil
.waitForJobs();
208 hv
.currentTimeUpdated(signal
);
209 hv
.broadcast(signal
);
210 SWTBotUtil
.waitForJobs();
211 SWTBotUtil
.delay(1000);
213 hv
.updateTimeRange(1000000000);
214 SWTBotUtil
.waitForJobs();
215 hv
.currentTimeUpdated(signal2
);
216 hv
.broadcast(signal2
);
217 SWTBotUtil
.waitForJobs();
218 SWTBotUtil
.delay(1000);
222 private static void testRV(ResourcesView vp
) {
226 private static CtfTmfEvent
getEvent(int rank
) {
227 CtfTmfTrace trace
= CtfTmfTestTrace
.SYNTHETIC_TRACE
.getTrace();
231 ITmfContext ctx
= trace
.seekEvent(0);
232 for (int i
= 0; i
< rank
; i
++) {
235 final CtfTmfEvent retVal
= trace
.getNext(ctx
);
240 private static IViewPart
getViewPart(final String viewTile
) {
241 final IViewPart
[] vps
= new IViewPart
[1];
242 UIThreadRunnable
.syncExec(new VoidResult() {
245 IViewReference
[] viewRefs
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
246 for (IViewReference viewRef
: viewRefs
) {
247 IViewPart vp
= viewRef
.getView(true);
248 if (vp
.getTitle().equals(viewTile
)) {