tmf: Rename time range signals
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / kernel / ui / swtbot / tests / ImportAndReadKernelSmokeTest.java
CommitLineData
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 15package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
ffa8146c 16
ffa8146c
MK
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.fail;
19
ffa8146c
MK
20import java.util.List;
21
22import org.apache.log4j.ConsoleAppender;
23import org.apache.log4j.Logger;
24import org.apache.log4j.SimpleLayout;
ffa8146c
MK
25import org.eclipse.jface.viewers.SelectionChangedEvent;
26import org.eclipse.jface.viewers.StructuredSelection;
ffa8146c 27import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
bf0f892f 28import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
ffa8146c
MK
29import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
30import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
cbbd323f 31import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
ffa8146c
MK
32import org.eclipse.swtbot.swt.finder.results.BoolResult;
33import org.eclipse.swtbot.swt.finder.results.VoidResult;
34import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
35import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
e363eae1
AM
36import org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow.ControlFlowView;
37import org.eclipse.tracecompass.analysis.os.linux.ui.views.resources.ResourcesView;
2bdf0193 38import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
97c71024 39import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
2bdf0193 40import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
9722e5d7 41import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
2bdf0193 42import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
9722e5d7 43import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
2bdf0193 44import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
fa24d78b
AM
45import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
46import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
2bdf0193 47import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView;
ffa8146c
MK
48import org.eclipse.ui.IEditorPart;
49import org.eclipse.ui.IEditorReference;
50import org.eclipse.ui.IViewPart;
51import org.eclipse.ui.IViewReference;
52import org.eclipse.ui.PlatformUI;
53import org.eclipse.ui.WorkbenchException;
bf0f892f 54import org.hamcrest.Matcher;
f10c30a0 55import org.junit.AfterClass;
ffa8146c
MK
56import org.junit.BeforeClass;
57import org.junit.Test;
cbbd323f 58import 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
66public 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;
97c71024
AM
182 final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, fDesired1.getTimestamp());
183 final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, fDesired2.getTimestamp());
ffa8146c 184 hv.updateTimeRange(100000);
fa24d78b 185 SWTBotUtils.waitForJobs();
97c71024 186 hv.selectionRangeUpdated(signal);
ffa8146c 187 hv.broadcast(signal);
fa24d78b
AM
188 SWTBotUtils.waitForJobs();
189 SWTBotUtils.delay(1000);
ffa8146c
MK
190
191 hv.updateTimeRange(1000000000);
fa24d78b 192 SWTBotUtils.waitForJobs();
97c71024 193 hv.selectionRangeUpdated(signal2);
ffa8146c 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}
This page took 0.07322 seconds and 5 git commands to generate.