Commit | Line | Data |
---|---|---|
2e65d221 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 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 | ||
10 | package org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests; | |
11 | ||
12 | import static org.junit.Assert.assertEquals; | |
13 | import static org.junit.Assert.assertNotNull; | |
325d8cac | 14 | import static org.junit.Assert.assertTrue; |
2e65d221 BH |
15 | |
16 | import java.io.File; | |
17 | import java.net.URL; | |
18 | ||
19 | import org.apache.log4j.ConsoleAppender; | |
20 | import org.apache.log4j.Logger; | |
21 | import org.apache.log4j.SimpleLayout; | |
325d8cac BH |
22 | import org.eclipse.core.resources.IProject; |
23 | import org.eclipse.core.resources.IWorkspace; | |
24 | import org.eclipse.core.resources.ResourcesPlugin; | |
2e65d221 | 25 | import org.eclipse.core.runtime.FileLocator; |
325d8cac | 26 | import org.eclipse.core.runtime.IPath; |
2e65d221 BH |
27 | import org.eclipse.core.runtime.Path; |
28 | import org.eclipse.jdt.annotation.NonNull; | |
29 | import org.eclipse.remote.core.IRemoteConnection; | |
30 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | |
31 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
325d8cac | 32 | import org.eclipse.swtbot.swt.finder.SWTBot; |
2e65d221 BH |
33 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
34 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
325d8cac BH |
35 | import org.eclipse.swtbot.swt.finder.waits.Conditions; |
36 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; | |
37 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; | |
2e65d221 BH |
38 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; |
39 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; | |
40 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; | |
41 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
42 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
325d8cac | 43 | import org.eclipse.tracecompass.ctf.core.tests.shared.LttngKernelTraceGenerator; |
2e65d221 BH |
44 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState; |
45 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState; | |
46 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy; | |
47 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView; | |
48 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
49 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent; | |
50 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent; | |
51 | import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory; | |
325d8cac BH |
52 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement; |
53 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder; | |
54 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; | |
55 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry; | |
2e65d221 BH |
56 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; |
57 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
58 | import org.eclipse.ui.IViewPart; | |
59 | import org.junit.After; | |
60 | import org.junit.Before; | |
61 | import org.junit.BeforeClass; | |
62 | import org.junit.Test; | |
63 | import org.junit.runner.RunWith; | |
64 | import org.osgi.framework.FrameworkUtil; | |
65 | ||
66 | /** | |
325d8cac | 67 | * Test for the LTTng Control view in Trace Compass |
2e65d221 BH |
68 | * |
69 | * @author Bernd Hufmann | |
70 | */ | |
71 | @RunWith(SWTBotJunit4ClassRunner.class) | |
72 | public class ControlViewTest { | |
73 | ||
2e65d221 BH |
74 | |
75 | // ------------------------------------------------------------------------ | |
76 | // Constants | |
77 | // ------------------------------------------------------------------------ | |
155ccbfe | 78 | private static final String TEST_STREAM = "CreateSessionTestLTTng2_8.cfg"; |
3d09f0a5 BH |
79 | /** The initialize scenario name */ |
80 | protected static final String INIT_SCENARIO_NAME = "Initialize"; | |
155ccbfe | 81 | private static final String CREATE_SESSION_WITH_LTTNG_2_8_SCENARIO_NAME = "CreateSession_2.8"; |
2e65d221 BH |
82 | |
83 | private static final String SESSION_NAME = "mysession"; | |
84 | private static final String UST_CHANNEL_NAME = ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME; | |
3d09f0a5 | 85 | private static final String NODE_NAME = "myNode"; |
a959e694 | 86 | private static final String PERSPECTIVE_ID = "org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests.perspective"; |
2e65d221 BH |
87 | |
88 | // ------------------------------------------------------------------------ | |
89 | // Test data | |
90 | // ------------------------------------------------------------------------ | |
3d09f0a5 BH |
91 | |
92 | /** The Log4j logger instance. */ | |
93 | protected static final Logger fLogger = Logger.getRootLogger(); | |
94 | /** The workbench bot */ | |
95 | protected static SWTWorkbenchBot fBot; | |
2e65d221 | 96 | private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection(); |
3d09f0a5 BH |
97 | /** The test remote system proxy */ |
98 | protected @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost); | |
99 | /** The trace control tree */ | |
100 | protected SWTBotTree fTree; | |
101 | /** The trace control root component */ | |
102 | protected ITraceControlComponent fRoot; | |
103 | /** The target node component */ | |
104 | protected TargetNodeComponent fNode; | |
105 | ||
3d09f0a5 BH |
106 | /** The test file */ |
107 | protected String fTestFile; | |
2e65d221 BH |
108 | |
109 | // ------------------------------------------------------------------------ | |
110 | // Housekeeping | |
111 | // ------------------------------------------------------------------------ | |
112 | ||
113 | /** | |
114 | * Initialization | |
115 | */ | |
116 | @BeforeClass | |
117 | public static void init() { | |
118 | SWTBotUtils.initialize(); | |
119 | ||
120 | Thread.currentThread().setName("SWTBot Thread"); // for the debugger | |
121 | /* set up for swtbot */ | |
122 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
123 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout())); | |
124 | fBot = new SWTWorkbenchBot(); | |
125 | ||
126 | SWTBotUtils.closeView("welcome", fBot); | |
127 | ||
128 | /* finish waiting for eclipse to load */ | |
129 | SWTBotUtils.waitForJobs(); | |
a959e694 BR |
130 | |
131 | SWTBotUtils.switchToPerspective(PERSPECTIVE_ID); | |
2e65d221 BH |
132 | } |
133 | ||
134 | /** | |
135 | * Open a trace in an editor | |
136 | * | |
137 | * @throws Exception | |
138 | * if problem occurs | |
139 | */ | |
140 | @Before | |
141 | public void beforeTest() throws Exception { | |
142 | SWTBotUtils.openView(ControlView.ID); | |
143 | SWTBotUtils.waitForJobs(); | |
144 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("testfiles" + File.separator + getTestStream()), null); | |
145 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
146 | fTestFile = testfile.getAbsolutePath(); | |
3d09f0a5 BH |
147 | |
148 | // Create root component | |
149 | SWTBotView viewBot = fBot.viewById(ControlView.ID); | |
150 | viewBot.setFocus(); | |
151 | IViewPart part = viewBot.getViewReference().getView(true); | |
152 | ControlView view = (ControlView) part; | |
153 | fRoot = view.getTraceControlRoot(); | |
154 | ||
155 | // Create node component | |
156 | fNode = new TargetNodeComponent(getNodeName(), fRoot, fProxy); | |
157 | fRoot.addChild(fNode); | |
158 | fTree = viewBot.bot().tree(); | |
2e65d221 BH |
159 | } |
160 | ||
161 | /** | |
162 | * Close the editor | |
163 | */ | |
164 | @After | |
165 | public void tearDown() { | |
166 | fBot.closeAllEditors(); | |
3d09f0a5 BH |
167 | if (fRoot != null) { |
168 | fRoot.removeAllChildren(); | |
169 | } | |
2e65d221 BH |
170 | } |
171 | ||
172 | /** | |
173 | * Get the test stream file name to use for the test suite | |
174 | * | |
175 | * @return the name of the test stream file | |
176 | */ | |
177 | protected String getTestStream() { | |
178 | return TEST_STREAM; | |
179 | } | |
180 | ||
3d09f0a5 BH |
181 | /** |
182 | * Get the session name | |
183 | * | |
184 | * @return the session name for this test | |
185 | */ | |
186 | protected String getSessionName() { | |
187 | return SESSION_NAME; | |
188 | } | |
189 | ||
190 | /** | |
191 | * Get the node name | |
192 | * | |
193 | * @return the node name for the test | |
194 | */ | |
195 | protected String getNodeName() { | |
196 | return NODE_NAME; | |
197 | } | |
198 | ||
2e65d221 BH |
199 | /** |
200 | * Test basic trace session generation. | |
201 | */ | |
202 | @Test | |
203 | public void testTraceSessionTree() { | |
204 | ||
205 | fProxy.setTestFile(fTestFile); | |
206 | fProxy.setScenario(INIT_SCENARIO_NAME); | |
207 | ||
3d09f0a5 | 208 | testConnectToNode(); |
2e65d221 | 209 | // Set the scenario |
155ccbfe | 210 | fProxy.setScenario(CREATE_SESSION_WITH_LTTNG_2_8_SCENARIO_NAME); |
3d09f0a5 BH |
211 | testCreateSession(); |
212 | testEnableKernelEvent(); | |
213 | testEnableSyscalls(); | |
214 | testEnableUstChannel(); | |
215 | testEnableUstEvents(); | |
216 | testStartStopTracing(TraceSessionState.ACTIVE); | |
217 | testStartStopTracing(TraceSessionState.INACTIVE); | |
325d8cac BH |
218 | // Import without experiment creation |
219 | testImport(false, true); | |
220 | SWTBotUtils.clearTracesFolder(fBot, ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
221 | // Import with experiment creation (default experiment name) | |
222 | testImport(true, true); | |
223 | SWTBotUtils.clearTracesFolder(fBot, ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
224 | /* | |
225 | * Import with experiment creation, test experiment already exists and | |
226 | * with experiment name validation | |
227 | */ | |
228 | testImport(true, false); | |
229 | SWTBotUtils.clearExperimentFolder(fBot, ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
3d09f0a5 BH |
230 | testDestroySession(); |
231 | testDisconnectFromNode(); | |
5206e69c | 232 | SWTBotUtils.deleteProject(ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT, fBot); |
2e65d221 BH |
233 | } |
234 | ||
235 | /** | |
236 | * Test connect to node | |
2e65d221 | 237 | */ |
3d09f0a5 BH |
238 | protected void testConnectToNode() { |
239 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); | |
2e65d221 BH |
240 | nodeItem.select(); |
241 | SWTBotMenu menuBot = nodeItem.contextMenu(ControlViewSwtBotUtil.CONNECT_MENU_ITEM); | |
242 | menuBot.click(); | |
243 | SWTBotUtils.waitForJobs(); | |
244 | ||
245 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.SESSION_GROUP_NAME, nodeItem)); | |
246 | ||
247 | // Verify that node is connected | |
3d09f0a5 BH |
248 | fBot.waitUntil(ControlViewSwtBotUtil.isStateChanged(fNode, TargetNodeState.CONNECTED)); |
249 | assertEquals(TargetNodeState.CONNECTED, fNode.getTargetNodeState()); | |
2e65d221 BH |
250 | } |
251 | ||
252 | /** | |
253 | * Test create session | |
2e65d221 | 254 | */ |
3d09f0a5 BH |
255 | protected void testCreateSession() { |
256 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); | |
2e65d221 BH |
257 | |
258 | SWTBotTreeItem sessionGroupItem = nodeItem.getNode(ControlViewSwtBotUtil.SESSION_GROUP_NAME); | |
259 | ||
260 | sessionGroupItem.select(); | |
261 | SWTBotMenu menuBot = sessionGroupItem.contextMenu(ControlViewSwtBotUtil.CREATE_SESSION_MENU_ITEM); | |
262 | menuBot.click(); | |
263 | ||
264 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.CREATE_SESSION_DIALOG_TITLE).activate(); | |
265 | ||
266 | SWTBotText sessionText = shell.bot().textWithLabel(ControlViewSwtBotUtil.SESSION_NAME_LABEL); | |
267 | sessionText.setText(SESSION_NAME); | |
268 | ||
269 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
270 | SWTBotUtils.waitForJobs(); | |
271 | ||
272 | sessionGroupItem.expand(); | |
273 | ||
3d09f0a5 | 274 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(getSessionName(), sessionGroupItem)); |
2e65d221 BH |
275 | assertEquals(1, sessionGroupItem.getNodes().size()); |
276 | ||
3d09f0a5 BH |
277 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, |
278 | getNodeName(), | |
2e65d221 | 279 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 BH |
280 | getSessionName()); |
281 | assertEquals(getSessionName(), sessionItem.getText()); | |
2e65d221 BH |
282 | } |
283 | ||
284 | /** | |
285 | * Test enable event (all kernel tracepoints) on session level | |
2e65d221 | 286 | */ |
3d09f0a5 BH |
287 | protected void testEnableKernelEvent() { |
288 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
289 | getNodeName(), | |
2e65d221 | 290 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 291 | getSessionName()); |
2e65d221 BH |
292 | |
293 | sessionItem.select(); | |
294 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
295 | menuBot.click(); | |
296 | ||
297 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
298 | ||
9ee91a86 BH |
299 | shell.bot().radioInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.TRACEPOINTS_GROUP_NAME).click(); |
300 | ||
2e65d221 | 301 | SWTBotTree tracepointsTree = shell.bot().tree(); |
65635cc8 BH |
302 | SWTBotTreeItem allItem = SWTBotUtils.getTreeItem(fBot, tracepointsTree, ControlViewSwtBotUtil.ALL_TREE_NODE); |
303 | allItem.check(); | |
2e65d221 BH |
304 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); |
305 | SWTBotUtils.waitForJobs(); | |
306 | ||
307 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, sessionItem)); | |
308 | ||
3d09f0a5 BH |
309 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, |
310 | getNodeName(), | |
2e65d221 | 311 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 312 | getSessionName(), |
2e65d221 BH |
313 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
314 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME); | |
315 | assertEquals(ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, channelItem.getText()); | |
316 | ||
3d09f0a5 BH |
317 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
318 | getNodeName(), | |
2e65d221 | 319 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 320 | getSessionName(), |
2e65d221 BH |
321 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
322 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, | |
323 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); | |
324 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); | |
325 | ||
3d09f0a5 BH |
326 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, |
327 | getNodeName(), | |
2e65d221 | 328 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 329 | getSessionName(), |
2e65d221 BH |
330 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
331 | assertEquals(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, kernelDomainItem.getText()); | |
332 | } | |
333 | ||
334 | /** | |
335 | * Test enable Event (syscall) on domain level | |
2e65d221 | 336 | */ |
3d09f0a5 BH |
337 | protected void testEnableSyscalls() { |
338 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
339 | getNodeName(), | |
2e65d221 | 340 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 341 | getSessionName(), |
2e65d221 BH |
342 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
343 | kernelDomainItem.select(); | |
344 | SWTBotMenu menuBot = kernelDomainItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
345 | menuBot.click(); | |
346 | ||
347 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
348 | shell.bot().radioInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.SYSCALL_GROUP_NAME).click(); | |
349 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
350 | SWTBotUtils.waitForJobs(); | |
351 | } | |
352 | ||
353 | /** | |
354 | * Test enable UST channel on session level (default values) | |
2e65d221 | 355 | */ |
3d09f0a5 BH |
356 | protected void testEnableUstChannel() { |
357 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
358 | getNodeName(), | |
2e65d221 | 359 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 360 | getSessionName()); |
2e65d221 BH |
361 | sessionItem.select(); |
362 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_CHANNEL_MENU_ITEM); | |
363 | menuBot.click(); | |
364 | ||
365 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_CHANNEL_DIALOG_TITLE).activate(); | |
366 | SWTBotText channelText = shell.bot().textWithLabel(ControlViewSwtBotUtil.CHANNEL_NAME_LABEL); | |
367 | channelText.setText(UST_CHANNEL_NAME); | |
368 | ||
369 | shell.bot().radioInGroup(ControlViewSwtBotUtil.UST_GROUP_NAME, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click(); | |
370 | shell.bot().radioInGroup(ControlViewSwtBotUtil.BUFFERTYPE_PER_UID, ControlViewSwtBotUtil.BUFFERTYPE_GROUP_NAME).click(); | |
371 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
372 | SWTBotUtils.waitForJobs(); | |
373 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.UST_DOMAIN_NAME, sessionItem)); | |
374 | } | |
375 | ||
376 | /** | |
377 | * Test enable event (all tracepoints) on channel level | |
2e65d221 | 378 | */ |
3d09f0a5 BH |
379 | protected void testEnableUstEvents() { |
380 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
381 | getNodeName(), | |
2e65d221 | 382 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 383 | getSessionName(), ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
2e65d221 BH |
384 | UST_CHANNEL_NAME); |
385 | assertEquals(UST_CHANNEL_NAME, channelItem.getText()); | |
386 | ||
387 | channelItem.select(); | |
388 | SWTBotMenu menuBot = channelItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_MENU_ITEM); | |
389 | menuBot.click(); | |
390 | ||
391 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
392 | SWTBotTree tracepointsTree = shell.bot().tree(); | |
393 | tracepointsTree.select(ControlViewSwtBotUtil.ALL_TREE_NODE); | |
394 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
395 | SWTBotUtils.waitForJobs(); | |
396 | ||
3d09f0a5 BH |
397 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
398 | getNodeName(), | |
2e65d221 | 399 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 400 | getSessionName(), |
2e65d221 BH |
401 | ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
402 | UST_CHANNEL_NAME, | |
403 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); | |
404 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); | |
405 | } | |
406 | ||
407 | /** | |
408 | * Test start or stop tracing | |
409 | * | |
2e65d221 BH |
410 | * @param state |
411 | * the state to change to | |
412 | */ | |
3d09f0a5 BH |
413 | protected void testStartStopTracing(TraceSessionState state) { |
414 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
415 | getNodeName(), | |
2e65d221 | 416 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 417 | getSessionName()); |
2e65d221 BH |
418 | sessionItem.select(); |
419 | ||
420 | if (state == TraceSessionState.ACTIVE) { | |
421 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.START_MENU_ITEM); | |
422 | menuBot.click(); | |
423 | SWTBotUtils.waitForJobs(); | |
424 | } else { | |
425 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.STOP_MENU_ITEM); | |
426 | menuBot.click(); | |
427 | SWTBotUtils.waitForJobs(); | |
428 | } | |
3d09f0a5 | 429 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); |
2e65d221 BH |
430 | |
431 | fBot.waitUntil(ControlViewSwtBotUtil.isSessionStateChanged(sessionComp, state)); | |
432 | assertEquals(state, sessionComp.getSessionState()); | |
433 | } | |
434 | ||
435 | /** | |
436 | * Test destroy session | |
2e65d221 | 437 | */ |
3d09f0a5 BH |
438 | protected void testDestroySession() { |
439 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
440 | getNodeName(), | |
2e65d221 | 441 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 442 | getSessionName()); |
2e65d221 BH |
443 | |
444 | sessionItem.select(); | |
445 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.DESTROY_MENU_ITEM); | |
446 | menuBot.click(); | |
447 | ||
448 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.DESTROY_CONFIRM_DIALOG_TITLE).activate(); | |
449 | shell.bot().button(ControlViewSwtBotUtil.CONFIRM_DIALOG_OK_BUTTON).click(); | |
450 | SWTBotUtils.waitForJobs(); | |
451 | ||
3d09f0a5 BH |
452 | SWTBotTreeItem sessionGroupItem = SWTBotUtils.getTreeItem(fBot, fTree, |
453 | getNodeName(), ControlViewSwtBotUtil.SESSION_GROUP_NAME); | |
2e65d221 BH |
454 | |
455 | fBot.waitUntil(ConditionHelpers.isTreeChildNodeRemoved(0, sessionGroupItem)); | |
456 | assertEquals(0, sessionGroupItem.getNodes().size()); | |
457 | } | |
458 | ||
459 | /** | |
460 | * Test disconnect from node | |
2e65d221 | 461 | */ |
3d09f0a5 BH |
462 | protected void testDisconnectFromNode() { |
463 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); | |
2e65d221 BH |
464 | nodeItem.select(); |
465 | SWTBotMenu menuBot = nodeItem.contextMenu(ControlViewSwtBotUtil.DISCONNECT_MENU_ITEM); | |
466 | menuBot.click(); | |
467 | SWTBotUtils.waitForJobs(); | |
468 | ||
469 | // Verify that node is connected | |
3d09f0a5 BH |
470 | fBot.waitUntil(ControlViewSwtBotUtil.isStateChanged(fNode, TargetNodeState.DISCONNECTED)); |
471 | assertEquals(TargetNodeState.DISCONNECTED, fNode.getTargetNodeState()); | |
2e65d221 BH |
472 | assertEquals(0, nodeItem.getNodes().size()); |
473 | } | |
325d8cac BH |
474 | |
475 | /** | |
476 | * Test import | |
477 | * | |
478 | * @param createExperiment | |
479 | * flag to indicate to create an experiment or not | |
480 | * @param defaultExperiment | |
481 | * flag to indicate to use default experiment or not | |
482 | */ | |
483 | protected void testImport(boolean createExperiment, boolean defaultExperiment) { | |
484 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
485 | getNodeName(), | |
486 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
487 | getSessionName()); | |
488 | sessionItem.select(); | |
489 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); | |
490 | ||
491 | String pathString = sessionComp.isSnapshotSession() ? sessionComp.getSnapshotInfo().getSnapshotPath() : sessionComp.getSessionPath(); | |
492 | IPath path = new Path(pathString); | |
493 | ||
494 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
495 | ||
496 | //get location of workspace (java.io.File) | |
497 | File workspaceDirectory = workspace.getRoot().getLocation().toFile(); | |
498 | Path workspacePath = new Path(workspaceDirectory.toString()); | |
499 | ||
500 | // Only do tests if session path is in workspace | |
501 | if (workspacePath.isPrefixOf(path)) { | |
502 | ||
503 | generateTrace(path); | |
504 | ||
505 | // Open import wizard | |
506 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); | |
507 | menuBot.click(); | |
508 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); | |
509 | ||
510 | // This will create the Remote project if needed | |
511 | closeImportWizard(shell, ControlViewSwtBotUtil.CANCEL_BUTTON); | |
512 | ||
513 | // Verify that remote project was created by import wizard | |
514 | TmfProjectElement tmfProject = verifyRemoteProject(); | |
515 | ||
516 | // Re-open import wizard | |
517 | menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); | |
518 | menuBot.click(); | |
519 | shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); | |
520 | ||
521 | // Prepare and verify experiment handling | |
522 | String experimentName = prepareAndVerifyExperimentHandling(shell.bot(), createExperiment, defaultExperiment, path); | |
523 | ||
524 | // Finish and import | |
525 | closeImportWizard(shell, ControlViewSwtBotUtil.FINISH_BUTTON); | |
526 | ||
527 | // Verify experiment folder | |
528 | verifyExperimentFolder(createExperiment, tmfProject, experimentName); | |
529 | } | |
530 | } | |
531 | ||
532 | ||
533 | private static TmfProjectElement verifyRemoteProject() { | |
534 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
535 | // verify that project was created | |
536 | assertTrue(project.exists()); | |
537 | TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true); | |
538 | return tmfProject; | |
539 | } | |
540 | ||
541 | private static void verifyExperimentFolder(boolean createExperiment, TmfProjectElement tmfProject, String experimentName) { | |
542 | TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder(); | |
543 | if (createExperiment) { | |
544 | if (experimentName != null) { | |
545 | TmfExperimentElement expElement = expFolder.getExperiment(experimentName); | |
546 | assertNotNull(expElement); | |
547 | assertEquals(1, expElement.getTraces().size()); | |
548 | } | |
549 | } else { | |
550 | assertTrue(expFolder.getExperiments().size() == 0); | |
551 | } | |
552 | } | |
553 | ||
554 | private static void generateTrace(IPath path) { | |
555 | File traceParent = path.toFile(); | |
556 | traceParent.mkdirs(); | |
557 | LttngKernelTraceGenerator.generateLttngKernelTrace(path.append(ControlViewSwtBotUtil.KERNEL_TRACE_NAME).toFile()); | |
558 | } | |
559 | ||
560 | private static void closeImportWizard(SWTBotShell shell, String buttonName) { | |
561 | SWTBotButton button = shell.bot().button(buttonName); | |
562 | shell.bot().waitUntil(Conditions.widgetIsEnabled(button)); | |
563 | button.click(); | |
564 | fBot.waitUntil(Conditions.shellCloses(shell)); | |
565 | SWTBotUtils.waitForJobs(); | |
566 | } | |
567 | ||
568 | private static String prepareAndVerifyExperimentHandling(SWTBot bot, boolean createExperiment, boolean defaultExperiment, IPath path) { | |
569 | String experimentName = path.lastSegment(); | |
570 | if (createExperiment) { | |
571 | SWTBotCheckBox checkBox = bot.checkBox(); | |
572 | checkBox.click(); | |
573 | if (!defaultExperiment) { | |
574 | experimentName = verifyExperimentNameHandling(bot, experimentName); | |
575 | } | |
576 | } | |
577 | return experimentName; | |
578 | } | |
579 | ||
580 | private static @NonNull String verifyExperimentNameHandling(SWTBot bot, String aExperimentName) { | |
581 | String experimentName = aExperimentName; | |
582 | ||
583 | // experiment already exists | |
584 | checkFinishButton(bot, false); | |
585 | ||
586 | SWTBotText expText = bot.textInGroup(ControlViewSwtBotUtil.OPTION_GROUP_NAME); | |
587 | ||
588 | // Invalid experiment name (only whitespaces) | |
589 | expText.setText(String.valueOf(' ')); | |
590 | checkFinishButton(bot, false); | |
591 | ||
592 | // Invalid experiment name | |
593 | expText.setText(String.valueOf('/')); | |
594 | checkFinishButton(bot, false); | |
595 | ||
596 | // Set valid experiment name | |
597 | experimentName += '_'; | |
598 | expText.setText(experimentName); | |
599 | return experimentName; | |
600 | } | |
601 | ||
602 | private static void checkFinishButton(SWTBot bot, boolean isEnabled) { | |
603 | final SWTBotButton finishButton = bot.button(ControlViewSwtBotUtil.FINISH_BUTTON); | |
604 | assertTrue(finishButton.isEnabled() == isEnabled); | |
605 | } | |
606 | ||
2e65d221 | 607 | } |