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 | |
12 | *******************************************************************************/ | |
13 | ||
14 | package org.eclipse.linuxtools.lttng2.kernel.ui.swtbot.tests; | |
15 | ||
16 | import static org.junit.Assert.assertFalse; | |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.fail; | |
19 | ||
20 | import java.util.ArrayList; | |
21 | import java.util.Arrays; | |
22 | import java.util.List; | |
23 | ||
24 | import org.apache.log4j.ConsoleAppender; | |
25 | import org.apache.log4j.Logger; | |
26 | import org.apache.log4j.SimpleLayout; | |
ffa8146c | 27 | import org.eclipse.core.runtime.CoreException; |
ffa8146c MK |
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; | |
ffa8146c MK |
32 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
33 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; | |
ffa8146c | 34 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
91e7f946 AM |
35 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent; |
36 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace; | |
37 | import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace; | |
ffa8146c MK |
38 | import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; |
39 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; | |
306e18d0 | 40 | import org.eclipse.linuxtools.tmf.ui.swtbot.tests.SWTBotUtil; |
ffa8146c MK |
41 | import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers; |
42 | import org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramView; | |
ffa8146c MK |
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; | |
58 | ||
59 | /** | |
60 | * SWTBot Smoke test for LTTng Kernel UI. | |
61 | * | |
62 | * @author Matthew Khouzam | |
63 | */ | |
64 | public class ImportAndReadKernelSmokeTest { | |
65 | ||
66 | private static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective"; | |
67 | private static final String TRACE_PROJECT_NAME = "test"; | |
68 | ||
69 | private static SWTWorkbenchBot fBot; | |
70 | private static CtfTmfTestTrace ctt = CtfTmfTestTrace.SYNTHETIC_TRACE; | |
71 | private ITmfEvent fDesired1; | |
72 | private ITmfEvent fDesired2; | |
73 | ||
74 | /** The Log4j logger instance. */ | |
75 | private static final Logger fLogger = Logger.getRootLogger(); | |
76 | ||
77 | /** | |
78 | * Test Class setup | |
79 | */ | |
80 | @BeforeClass | |
81 | public static void init() { | |
306e18d0 | 82 | SWTBotUtil.failIfUIThread(); |
ffa8146c MK |
83 | |
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(); | |
88 | ||
89 | final List<SWTBotView> openViews = fBot.views(); | |
90 | for (SWTBotView view : openViews) { | |
91 | if (view.getTitle().equals("Welcome")) { | |
92 | view.close(); | |
93 | fBot.waitUntil(ConditionHelpers.ViewIsClosed(view)); | |
94 | } | |
95 | } | |
96 | /* Switch perspectives */ | |
97 | switchKernelPerspective(); | |
98 | /* Finish waiting for eclipse to load */ | |
306e18d0 | 99 | SWTBotUtil.waitForJobs(); |
ffa8146c MK |
100 | } |
101 | ||
102 | private static void switchKernelPerspective() { | |
103 | final Exception retE[] = new Exception[1]; | |
104 | if (!UIThreadRunnable.syncExec(new BoolResult() { | |
105 | @Override | |
106 | public Boolean run() { | |
107 | try { | |
108 | PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID, | |
109 | PlatformUI.getWorkbench().getActiveWorkbenchWindow()); | |
110 | } catch (WorkbenchException e) { | |
111 | retE[0] = e; | |
112 | return false; | |
113 | } | |
114 | return true; | |
115 | } | |
116 | })) { | |
117 | fail(retE[0].getMessage()); | |
118 | } | |
119 | ||
120 | } | |
121 | ||
ffa8146c MK |
122 | /** |
123 | * Main test case | |
124 | */ | |
125 | @Test | |
126 | public void test() { | |
306e18d0 | 127 | SWTBotUtil.createProject(TRACE_PROJECT_NAME); |
ffa8146c MK |
128 | openTrace(); |
129 | openEditor(); | |
130 | testHV(getViewPart("Histogram")); | |
131 | testCFV((ControlFlowView) getViewPart("Control Flow")); | |
132 | testRV((ResourcesView) getViewPart("Resources")); | |
133 | } | |
134 | ||
135 | private static void openTrace() { | |
136 | final Exception exception[] = new Exception[1]; | |
137 | exception[0] = null; | |
138 | UIThreadRunnable.syncExec(new VoidResult() { | |
139 | @Override | |
140 | public void run() { | |
141 | try { | |
142 | (new TmfOpenTraceHelper()).openTraceFromPath("test", ctt.getPath(), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "org.eclipse.linuxtools.lttng2.kernel.tracetype"); | |
143 | } catch (CoreException e) { | |
144 | exception[0] = e; | |
145 | } | |
146 | } | |
147 | }); | |
148 | if (exception[0] != null) { | |
149 | fail(exception[0].getMessage()); | |
150 | } | |
151 | ||
306e18d0 MK |
152 | SWTBotUtil.delay(1000); |
153 | SWTBotUtil.waitForJobs(); | |
ffa8146c MK |
154 | } |
155 | ||
156 | private void openEditor() { | |
157 | final List<IEditorReference> editorRefs = new ArrayList<>(); | |
158 | UIThreadRunnable.syncExec(new VoidResult() { | |
159 | @Override | |
160 | public void run() { | |
161 | IEditorReference[] ieds = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences(); | |
162 | editorRefs.addAll(Arrays.asList(ieds)); | |
163 | } | |
164 | ||
165 | }); | |
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); | |
171 | break; | |
172 | } | |
173 | } | |
174 | assertNotNull(iep); | |
175 | fDesired1 = getEvent(100); | |
176 | fDesired2 = getEvent(10000); | |
177 | final TmfEventsEditor tmfEd = (TmfEventsEditor) iep; | |
178 | UIThreadRunnable.syncExec(new VoidResult() { | |
179 | @Override | |
180 | public void run() { | |
181 | tmfEd.setFocus(); | |
182 | tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1))); | |
183 | } | |
184 | }); | |
185 | ||
306e18d0 MK |
186 | SWTBotUtil.waitForJobs(); |
187 | SWTBotUtil.delay(1000); | |
ffa8146c MK |
188 | assertNotNull(tmfEd); |
189 | } | |
190 | ||
ffa8146c MK |
191 | private static void testCFV(ControlFlowView vp) { |
192 | assertNotNull(vp); | |
193 | } | |
194 | ||
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")) { | |
200 | hvTool.click(); | |
201 | } | |
202 | } | |
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); | |
306e18d0 | 207 | SWTBotUtil.waitForJobs(); |
ffa8146c MK |
208 | hv.currentTimeUpdated(signal); |
209 | hv.broadcast(signal); | |
306e18d0 MK |
210 | SWTBotUtil.waitForJobs(); |
211 | SWTBotUtil.delay(1000); | |
ffa8146c MK |
212 | |
213 | hv.updateTimeRange(1000000000); | |
306e18d0 | 214 | SWTBotUtil.waitForJobs(); |
ffa8146c MK |
215 | hv.currentTimeUpdated(signal2); |
216 | hv.broadcast(signal2); | |
306e18d0 MK |
217 | SWTBotUtil.waitForJobs(); |
218 | SWTBotUtil.delay(1000); | |
ffa8146c MK |
219 | assertNotNull(hv); |
220 | } | |
221 | ||
222 | private static void testRV(ResourcesView vp) { | |
223 | assertNotNull(vp); | |
224 | } | |
225 | ||
226 | private static CtfTmfEvent getEvent(int rank) { | |
227 | CtfTmfTrace trace = CtfTmfTestTrace.SYNTHETIC_TRACE.getTrace(); | |
228 | if (trace == null) { | |
229 | return null; | |
230 | } | |
231 | ITmfContext ctx = trace.seekEvent(0); | |
232 | for (int i = 0; i < rank; i++) { | |
233 | trace.getNext(ctx); | |
234 | } | |
235 | final CtfTmfEvent retVal = trace.getNext(ctx); | |
236 | trace.dispose(); | |
237 | return retVal; | |
238 | } | |
239 | ||
240 | private static IViewPart getViewPart(final String viewTile) { | |
241 | final IViewPart[] vps = new IViewPart[1]; | |
242 | UIThreadRunnable.syncExec(new VoidResult() { | |
243 | @Override | |
244 | public void run() { | |
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)) { | |
249 | vps[0] = vp; | |
250 | return; | |
251 | } | |
252 | } | |
253 | } | |
254 | }); | |
255 | ||
256 | return vps[0]; | |
257 | } | |
258 | } |