Commit | Line | Data |
---|---|---|
ffa8146c MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013, 2014 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Matthew Khouzam - Initial API and implementation | |
11 | * Marc-Andre Laperle | |
977ca87f | 12 | * Patrick Tasse - Add support for folder elements |
ffa8146c MK |
13 | *******************************************************************************/ |
14 | ||
15 | package org.eclipse.linuxtools.lttng2.kernel.ui.swtbot.tests; | |
16 | ||
17 | import static org.junit.Assert.assertFalse; | |
18 | import static org.junit.Assert.assertNotNull; | |
19 | import static org.junit.Assert.fail; | |
20 | ||
21 | import java.util.ArrayList; | |
22 | import java.util.Arrays; | |
23 | import java.util.List; | |
24 | ||
25 | import org.apache.log4j.ConsoleAppender; | |
26 | import org.apache.log4j.Logger; | |
27 | import org.apache.log4j.SimpleLayout; | |
977ca87f PT |
28 | import org.eclipse.core.resources.IProject; |
29 | import org.eclipse.core.resources.ResourcesPlugin; | |
ffa8146c | 30 | import org.eclipse.core.runtime.CoreException; |
ffa8146c MK |
31 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
32 | import org.eclipse.jface.viewers.StructuredSelection; | |
33 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow.ControlFlowView; | |
34 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesView; | |
ffa8146c MK |
35 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
36 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; | |
ffa8146c | 37 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
91e7f946 AM |
38 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent; |
39 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace; | |
40 | import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace; | |
ffa8146c MK |
41 | import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; |
42 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; | |
977ca87f PT |
43 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry; |
44 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; | |
306e18d0 | 45 | import org.eclipse.linuxtools.tmf.ui.swtbot.tests.SWTBotUtil; |
ffa8146c MK |
46 | import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers; |
47 | import org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramView; | |
ffa8146c MK |
48 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
49 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
50 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; | |
cbbd323f | 51 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
ffa8146c MK |
52 | import org.eclipse.swtbot.swt.finder.results.BoolResult; |
53 | import org.eclipse.swtbot.swt.finder.results.VoidResult; | |
54 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
55 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; | |
56 | import org.eclipse.ui.IEditorPart; | |
57 | import org.eclipse.ui.IEditorReference; | |
58 | import org.eclipse.ui.IViewPart; | |
59 | import org.eclipse.ui.IViewReference; | |
60 | import org.eclipse.ui.PlatformUI; | |
61 | import org.eclipse.ui.WorkbenchException; | |
62 | import org.junit.BeforeClass; | |
63 | import org.junit.Test; | |
cbbd323f | 64 | import org.junit.runner.RunWith; |
ffa8146c MK |
65 | |
66 | /** | |
67 | * SWTBot Smoke test for LTTng Kernel UI. | |
68 | * | |
69 | * @author Matthew Khouzam | |
70 | */ | |
cbbd323f | 71 | @RunWith(SWTBotJunit4ClassRunner.class) |
ffa8146c MK |
72 | public class ImportAndReadKernelSmokeTest { |
73 | ||
74 | private static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective"; | |
75 | private static final String TRACE_PROJECT_NAME = "test"; | |
76 | ||
77 | private static SWTWorkbenchBot fBot; | |
78 | private static CtfTmfTestTrace ctt = CtfTmfTestTrace.SYNTHETIC_TRACE; | |
79 | private ITmfEvent fDesired1; | |
80 | private ITmfEvent fDesired2; | |
81 | ||
82 | /** The Log4j logger instance. */ | |
83 | private static final Logger fLogger = Logger.getRootLogger(); | |
84 | ||
85 | /** | |
86 | * Test Class setup | |
87 | */ | |
88 | @BeforeClass | |
89 | public static void init() { | |
306e18d0 | 90 | SWTBotUtil.failIfUIThread(); |
ffa8146c MK |
91 | |
92 | /* set up for swtbot */ | |
93 | SWTBotPreferences.TIMEOUT = 300000; /* 300 second timeout */ | |
94 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); | |
95 | fBot = new SWTWorkbenchBot(); | |
96 | ||
97 | final List<SWTBotView> openViews = fBot.views(); | |
98 | for (SWTBotView view : openViews) { | |
99 | if (view.getTitle().equals("Welcome")) { | |
100 | view.close(); | |
101 | fBot.waitUntil(ConditionHelpers.ViewIsClosed(view)); | |
102 | } | |
103 | } | |
104 | /* Switch perspectives */ | |
105 | switchKernelPerspective(); | |
106 | /* Finish waiting for eclipse to load */ | |
306e18d0 | 107 | SWTBotUtil.waitForJobs(); |
ffa8146c MK |
108 | } |
109 | ||
110 | private static void switchKernelPerspective() { | |
111 | final Exception retE[] = new Exception[1]; | |
112 | if (!UIThreadRunnable.syncExec(new BoolResult() { | |
113 | @Override | |
114 | public Boolean run() { | |
115 | try { | |
116 | PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID, | |
117 | PlatformUI.getWorkbench().getActiveWorkbenchWindow()); | |
118 | } catch (WorkbenchException e) { | |
119 | retE[0] = e; | |
120 | return false; | |
121 | } | |
122 | return true; | |
123 | } | |
124 | })) { | |
125 | fail(retE[0].getMessage()); | |
126 | } | |
127 | ||
128 | } | |
129 | ||
ffa8146c MK |
130 | /** |
131 | * Main test case | |
132 | */ | |
133 | @Test | |
134 | public void test() { | |
306e18d0 | 135 | SWTBotUtil.createProject(TRACE_PROJECT_NAME); |
ffa8146c MK |
136 | openTrace(); |
137 | openEditor(); | |
138 | testHV(getViewPart("Histogram")); | |
139 | testCFV((ControlFlowView) getViewPart("Control Flow")); | |
140 | testRV((ResourcesView) getViewPart("Resources")); | |
141 | } | |
142 | ||
143 | private static void openTrace() { | |
144 | final Exception exception[] = new Exception[1]; | |
145 | exception[0] = null; | |
146 | UIThreadRunnable.syncExec(new VoidResult() { | |
147 | @Override | |
148 | public void run() { | |
149 | try { | |
977ca87f PT |
150 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME); |
151 | TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder(); | |
152 | TmfOpenTraceHelper.openTraceFromPath(destinationFolder, ctt.getPath(), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "org.eclipse.linuxtools.lttng2.kernel.tracetype"); | |
ffa8146c MK |
153 | } catch (CoreException e) { |
154 | exception[0] = e; | |
155 | } | |
156 | } | |
157 | }); | |
158 | if (exception[0] != null) { | |
159 | fail(exception[0].getMessage()); | |
160 | } | |
161 | ||
306e18d0 MK |
162 | SWTBotUtil.delay(1000); |
163 | SWTBotUtil.waitForJobs(); | |
ffa8146c MK |
164 | } |
165 | ||
166 | private void openEditor() { | |
167 | final List<IEditorReference> editorRefs = new ArrayList<>(); | |
168 | UIThreadRunnable.syncExec(new VoidResult() { | |
169 | @Override | |
170 | public void run() { | |
171 | IEditorReference[] ieds = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences(); | |
172 | editorRefs.addAll(Arrays.asList(ieds)); | |
173 | } | |
174 | ||
175 | }); | |
176 | assertFalse(editorRefs.isEmpty()); | |
177 | IEditorPart iep = null; | |
178 | for (IEditorReference ied : editorRefs) { | |
179 | if (ied.getTitle().equals(ctt.getTrace().getName())) { | |
180 | iep = ied.getEditor(true); | |
181 | break; | |
182 | } | |
183 | } | |
184 | assertNotNull(iep); | |
185 | fDesired1 = getEvent(100); | |
186 | fDesired2 = getEvent(10000); | |
187 | final TmfEventsEditor tmfEd = (TmfEventsEditor) iep; | |
188 | UIThreadRunnable.syncExec(new VoidResult() { | |
189 | @Override | |
190 | public void run() { | |
191 | tmfEd.setFocus(); | |
192 | tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1))); | |
193 | } | |
194 | }); | |
195 | ||
306e18d0 MK |
196 | SWTBotUtil.waitForJobs(); |
197 | SWTBotUtil.delay(1000); | |
ffa8146c MK |
198 | assertNotNull(tmfEd); |
199 | } | |
200 | ||
ffa8146c MK |
201 | private static void testCFV(ControlFlowView vp) { |
202 | assertNotNull(vp); | |
203 | } | |
204 | ||
205 | private void testHV(IViewPart vp) { | |
206 | SWTBotView hvBot = (new SWTWorkbenchBot()).viewById(HistogramView.ID); | |
207 | List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons(); | |
208 | for (SWTBotToolbarButton hvTool : hvTools) { | |
209 | if (hvTool.getToolTipText().toLowerCase().contains("lost")) { | |
210 | hvTool.click(); | |
211 | } | |
212 | } | |
213 | HistogramView hv = (HistogramView) vp; | |
214 | final TmfTimeSynchSignal signal = new TmfTimeSynchSignal(hv, fDesired1.getTimestamp()); | |
215 | final TmfTimeSynchSignal signal2 = new TmfTimeSynchSignal(hv, fDesired2.getTimestamp()); | |
216 | hv.updateTimeRange(100000); | |
306e18d0 | 217 | SWTBotUtil.waitForJobs(); |
ffa8146c MK |
218 | hv.currentTimeUpdated(signal); |
219 | hv.broadcast(signal); | |
306e18d0 MK |
220 | SWTBotUtil.waitForJobs(); |
221 | SWTBotUtil.delay(1000); | |
ffa8146c MK |
222 | |
223 | hv.updateTimeRange(1000000000); | |
306e18d0 | 224 | SWTBotUtil.waitForJobs(); |
ffa8146c MK |
225 | hv.currentTimeUpdated(signal2); |
226 | hv.broadcast(signal2); | |
306e18d0 MK |
227 | SWTBotUtil.waitForJobs(); |
228 | SWTBotUtil.delay(1000); | |
ffa8146c MK |
229 | assertNotNull(hv); |
230 | } | |
231 | ||
232 | private static void testRV(ResourcesView vp) { | |
233 | assertNotNull(vp); | |
234 | } | |
235 | ||
236 | private static CtfTmfEvent getEvent(int rank) { | |
7b3eb8c0 AM |
237 | try (CtfTmfTrace trace = CtfTmfTestTrace.SYNTHETIC_TRACE.getTrace()) { |
238 | ITmfContext ctx = trace.seekEvent(0); | |
239 | for (int i = 0; i < rank; i++) { | |
240 | trace.getNext(ctx); | |
241 | } | |
242 | return trace.getNext(ctx); | |
ffa8146c | 243 | } |
7b3eb8c0 | 244 | |
ffa8146c MK |
245 | } |
246 | ||
247 | private static IViewPart getViewPart(final String viewTile) { | |
248 | final IViewPart[] vps = new IViewPart[1]; | |
249 | UIThreadRunnable.syncExec(new VoidResult() { | |
250 | @Override | |
251 | public void run() { | |
252 | IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences(); | |
253 | for (IViewReference viewRef : viewRefs) { | |
254 | IViewPart vp = viewRef.getView(true); | |
255 | if (vp.getTitle().equals(viewTile)) { | |
256 | vps[0] = vp; | |
257 | return; | |
258 | } | |
259 | } | |
260 | } | |
261 | }); | |
262 | ||
263 | return vps[0]; | |
264 | } | |
265 | } |