Commit | Line | Data |
---|---|---|
ffa8146c | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2015 Ericsson |
ffa8146c MK |
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 | ||
9bc60be7 | 15 | package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests; |
ffa8146c | 16 | |
ffa8146c MK |
17 | import static org.junit.Assert.assertNotNull; |
18 | import static org.junit.Assert.fail; | |
19 | ||
ffa8146c MK |
20 | import java.util.List; |
21 | ||
22 | import org.apache.log4j.ConsoleAppender; | |
23 | import org.apache.log4j.Logger; | |
24 | import org.apache.log4j.SimpleLayout; | |
ffa8146c MK |
25 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
26 | import org.eclipse.jface.viewers.StructuredSelection; | |
ffa8146c | 27 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
bf0f892f | 28 | import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory; |
ffa8146c MK |
29 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; |
30 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; | |
cbbd323f | 31 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
ffa8146c MK |
32 | import org.eclipse.swtbot.swt.finder.results.BoolResult; |
33 | import org.eclipse.swtbot.swt.finder.results.VoidResult; | |
34 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
35 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; | |
e363eae1 AM |
36 | import org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow.ControlFlowView; |
37 | import org.eclipse.tracecompass.analysis.os.linux.ui.views.resources.ResourcesView; | |
2bdf0193 AM |
38 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
39 | import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal; | |
40 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
9722e5d7 | 41 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; |
2bdf0193 | 42 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
9722e5d7 | 43 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
2bdf0193 | 44 | import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor; |
fa24d78b AM |
45 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; |
46 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
2bdf0193 | 47 | import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView; |
ffa8146c MK |
48 | import org.eclipse.ui.IEditorPart; |
49 | import org.eclipse.ui.IEditorReference; | |
50 | import org.eclipse.ui.IViewPart; | |
51 | import org.eclipse.ui.IViewReference; | |
52 | import org.eclipse.ui.PlatformUI; | |
53 | import org.eclipse.ui.WorkbenchException; | |
bf0f892f | 54 | import org.hamcrest.Matcher; |
f10c30a0 | 55 | import org.junit.AfterClass; |
ffa8146c MK |
56 | import org.junit.BeforeClass; |
57 | import org.junit.Test; | |
cbbd323f | 58 | import org.junit.runner.RunWith; |
ffa8146c MK |
59 | |
60 | /** | |
61 | * SWTBot Smoke test for LTTng Kernel UI. | |
62 | * | |
63 | * @author Matthew Khouzam | |
64 | */ | |
cbbd323f | 65 | @RunWith(SWTBotJunit4ClassRunner.class) |
ffa8146c MK |
66 | public class ImportAndReadKernelSmokeTest { |
67 | ||
7777d5f0 | 68 | private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype"; |
ffa8146c MK |
69 | private static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective"; |
70 | private static final String TRACE_PROJECT_NAME = "test"; | |
553bccd6 | 71 | private static final CtfTmfTestTrace CTT = CtfTmfTestTrace.SYNTHETIC_TRACE; |
ffa8146c MK |
72 | |
73 | private static SWTWorkbenchBot fBot; | |
ffa8146c MK |
74 | private ITmfEvent fDesired1; |
75 | private ITmfEvent fDesired2; | |
76 | ||
77 | /** The Log4j logger instance. */ | |
78 | private static final Logger fLogger = Logger.getRootLogger(); | |
79 | ||
80 | /** | |
81 | * Test Class setup | |
82 | */ | |
83 | @BeforeClass | |
84 | public static void init() { | |
fa24d78b | 85 | SWTBotUtils.failIfUIThread(); |
ffa8146c MK |
86 | |
87 | /* set up for swtbot */ | |
bf0f892f | 88 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ |
f10c30a0 | 89 | fLogger.removeAllAppenders(); |
ffa8146c MK |
90 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); |
91 | fBot = new SWTWorkbenchBot(); | |
92 | ||
93 | final List<SWTBotView> openViews = fBot.views(); | |
94 | for (SWTBotView view : openViews) { | |
95 | if (view.getTitle().equals("Welcome")) { | |
96 | view.close(); | |
97 | fBot.waitUntil(ConditionHelpers.ViewIsClosed(view)); | |
98 | } | |
99 | } | |
100 | /* Switch perspectives */ | |
101 | switchKernelPerspective(); | |
102 | /* Finish waiting for eclipse to load */ | |
fa24d78b | 103 | SWTBotUtils.waitForJobs(); |
ffa8146c MK |
104 | } |
105 | ||
f10c30a0 MK |
106 | /** |
107 | * Test Class teardown | |
108 | */ | |
109 | @AfterClass | |
110 | public static void terminate() { | |
111 | fLogger.removeAllAppenders(); | |
112 | } | |
113 | ||
ffa8146c MK |
114 | private static void switchKernelPerspective() { |
115 | final Exception retE[] = new Exception[1]; | |
116 | if (!UIThreadRunnable.syncExec(new BoolResult() { | |
117 | @Override | |
118 | public Boolean run() { | |
119 | try { | |
120 | PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID, | |
121 | PlatformUI.getWorkbench().getActiveWorkbenchWindow()); | |
122 | } catch (WorkbenchException e) { | |
123 | retE[0] = e; | |
124 | return false; | |
125 | } | |
126 | return true; | |
127 | } | |
128 | })) { | |
129 | fail(retE[0].getMessage()); | |
130 | } | |
131 | ||
132 | } | |
133 | ||
ffa8146c MK |
134 | /** |
135 | * Main test case | |
136 | */ | |
137 | @Test | |
138 | public void test() { | |
fa24d78b AM |
139 | SWTBotUtils.createProject(TRACE_PROJECT_NAME); |
140 | SWTBotUtils.openTrace(TRACE_PROJECT_NAME, CTT.getPath(), TRACE_TYPE); | |
ffa8146c MK |
141 | openEditor(); |
142 | testHV(getViewPart("Histogram")); | |
143 | testCFV((ControlFlowView) getViewPart("Control Flow")); | |
144 | testRV((ResourcesView) getViewPart("Resources")); | |
93c91230 MAL |
145 | |
146 | fBot.closeAllEditors(); | |
fa24d78b | 147 | SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot); |
ffa8146c MK |
148 | } |
149 | ||
ffa8146c | 150 | private void openEditor() { |
553bccd6 | 151 | Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(CTT.getTrace().getName()); |
bf0f892f | 152 | IEditorPart iep = fBot.editor(matcher).getReference().getEditor(true); |
ffa8146c MK |
153 | fDesired1 = getEvent(100); |
154 | fDesired2 = getEvent(10000); | |
155 | final TmfEventsEditor tmfEd = (TmfEventsEditor) iep; | |
156 | UIThreadRunnable.syncExec(new VoidResult() { | |
157 | @Override | |
158 | public void run() { | |
159 | tmfEd.setFocus(); | |
160 | tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(fDesired1))); | |
161 | } | |
162 | }); | |
163 | ||
fa24d78b AM |
164 | SWTBotUtils.waitForJobs(); |
165 | SWTBotUtils.delay(1000); | |
ffa8146c MK |
166 | assertNotNull(tmfEd); |
167 | } | |
168 | ||
ffa8146c MK |
169 | private static void testCFV(ControlFlowView vp) { |
170 | assertNotNull(vp); | |
171 | } | |
172 | ||
173 | private void testHV(IViewPart vp) { | |
174 | SWTBotView hvBot = (new SWTWorkbenchBot()).viewById(HistogramView.ID); | |
175 | List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons(); | |
176 | for (SWTBotToolbarButton hvTool : hvTools) { | |
177 | if (hvTool.getToolTipText().toLowerCase().contains("lost")) { | |
178 | hvTool.click(); | |
179 | } | |
180 | } | |
181 | HistogramView hv = (HistogramView) vp; | |
182 | final TmfTimeSynchSignal signal = new TmfTimeSynchSignal(hv, fDesired1.getTimestamp()); | |
183 | final TmfTimeSynchSignal signal2 = new TmfTimeSynchSignal(hv, fDesired2.getTimestamp()); | |
184 | hv.updateTimeRange(100000); | |
fa24d78b | 185 | SWTBotUtils.waitForJobs(); |
ffa8146c MK |
186 | hv.currentTimeUpdated(signal); |
187 | hv.broadcast(signal); | |
fa24d78b AM |
188 | SWTBotUtils.waitForJobs(); |
189 | SWTBotUtils.delay(1000); | |
ffa8146c MK |
190 | |
191 | hv.updateTimeRange(1000000000); | |
fa24d78b | 192 | SWTBotUtils.waitForJobs(); |
ffa8146c MK |
193 | hv.currentTimeUpdated(signal2); |
194 | hv.broadcast(signal2); | |
fa24d78b AM |
195 | SWTBotUtils.waitForJobs(); |
196 | SWTBotUtils.delay(1000); | |
ffa8146c MK |
197 | assertNotNull(hv); |
198 | } | |
199 | ||
200 | private static void testRV(ResourcesView vp) { | |
201 | assertNotNull(vp); | |
202 | } | |
203 | ||
204 | private static CtfTmfEvent getEvent(int rank) { | |
7b3eb8c0 AM |
205 | try (CtfTmfTrace trace = CtfTmfTestTrace.SYNTHETIC_TRACE.getTrace()) { |
206 | ITmfContext ctx = trace.seekEvent(0); | |
207 | for (int i = 0; i < rank; i++) { | |
208 | trace.getNext(ctx); | |
209 | } | |
210 | return trace.getNext(ctx); | |
ffa8146c | 211 | } |
7b3eb8c0 | 212 | |
ffa8146c MK |
213 | } |
214 | ||
215 | private static IViewPart getViewPart(final String viewTile) { | |
216 | final IViewPart[] vps = new IViewPart[1]; | |
217 | UIThreadRunnable.syncExec(new VoidResult() { | |
218 | @Override | |
219 | public void run() { | |
220 | IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences(); | |
221 | for (IViewReference viewRef : viewRefs) { | |
222 | IViewPart vp = viewRef.getView(true); | |
223 | if (vp.getTitle().equals(viewTile)) { | |
224 | vps[0] = vp; | |
225 | return; | |
226 | } | |
227 | } | |
228 | } | |
229 | }); | |
230 | ||
231 | return vps[0]; | |
232 | } | |
233 | } |