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