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 | 298 | SWTBotTree tracepointsTree = shell.bot().tree(); |
65635cc8 BH |
299 | SWTBotTreeItem allItem = SWTBotUtils.getTreeItem(fBot, tracepointsTree, ControlViewSwtBotUtil.ALL_TREE_NODE); |
300 | allItem.check(); | |
2e65d221 BH |
301 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); |
302 | SWTBotUtils.waitForJobs(); | |
303 | ||
304 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, sessionItem)); | |
305 | ||
3d09f0a5 BH |
306 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, |
307 | getNodeName(), | |
2e65d221 | 308 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 309 | getSessionName(), |
2e65d221 BH |
310 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
311 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME); | |
312 | assertEquals(ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, channelItem.getText()); | |
313 | ||
3d09f0a5 BH |
314 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
315 | getNodeName(), | |
2e65d221 | 316 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 317 | getSessionName(), |
2e65d221 BH |
318 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
319 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, | |
320 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); | |
321 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); | |
322 | ||
3d09f0a5 BH |
323 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, |
324 | getNodeName(), | |
2e65d221 | 325 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 326 | getSessionName(), |
2e65d221 BH |
327 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
328 | assertEquals(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, kernelDomainItem.getText()); | |
329 | } | |
330 | ||
331 | /** | |
332 | * Test enable Event (syscall) on domain level | |
2e65d221 | 333 | */ |
3d09f0a5 BH |
334 | protected void testEnableSyscalls() { |
335 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
336 | getNodeName(), | |
2e65d221 | 337 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 338 | getSessionName(), |
2e65d221 BH |
339 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
340 | kernelDomainItem.select(); | |
341 | SWTBotMenu menuBot = kernelDomainItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
342 | menuBot.click(); | |
343 | ||
344 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
345 | shell.bot().radioInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.SYSCALL_GROUP_NAME).click(); | |
346 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
347 | SWTBotUtils.waitForJobs(); | |
348 | } | |
349 | ||
350 | /** | |
351 | * Test enable UST channel on session level (default values) | |
2e65d221 | 352 | */ |
3d09f0a5 BH |
353 | protected void testEnableUstChannel() { |
354 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
355 | getNodeName(), | |
2e65d221 | 356 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 357 | getSessionName()); |
2e65d221 BH |
358 | sessionItem.select(); |
359 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_CHANNEL_MENU_ITEM); | |
360 | menuBot.click(); | |
361 | ||
362 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_CHANNEL_DIALOG_TITLE).activate(); | |
363 | SWTBotText channelText = shell.bot().textWithLabel(ControlViewSwtBotUtil.CHANNEL_NAME_LABEL); | |
364 | channelText.setText(UST_CHANNEL_NAME); | |
365 | ||
366 | shell.bot().radioInGroup(ControlViewSwtBotUtil.UST_GROUP_NAME, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click(); | |
367 | shell.bot().radioInGroup(ControlViewSwtBotUtil.BUFFERTYPE_PER_UID, ControlViewSwtBotUtil.BUFFERTYPE_GROUP_NAME).click(); | |
368 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
369 | SWTBotUtils.waitForJobs(); | |
370 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.UST_DOMAIN_NAME, sessionItem)); | |
371 | } | |
372 | ||
373 | /** | |
374 | * Test enable event (all tracepoints) on channel level | |
2e65d221 | 375 | */ |
3d09f0a5 BH |
376 | protected void testEnableUstEvents() { |
377 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
378 | getNodeName(), | |
2e65d221 | 379 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 380 | getSessionName(), ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
2e65d221 BH |
381 | UST_CHANNEL_NAME); |
382 | assertEquals(UST_CHANNEL_NAME, channelItem.getText()); | |
383 | ||
384 | channelItem.select(); | |
385 | SWTBotMenu menuBot = channelItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_MENU_ITEM); | |
386 | menuBot.click(); | |
387 | ||
388 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
389 | SWTBotTree tracepointsTree = shell.bot().tree(); | |
390 | tracepointsTree.select(ControlViewSwtBotUtil.ALL_TREE_NODE); | |
391 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
392 | SWTBotUtils.waitForJobs(); | |
393 | ||
3d09f0a5 BH |
394 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
395 | getNodeName(), | |
2e65d221 | 396 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 397 | getSessionName(), |
2e65d221 BH |
398 | ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
399 | UST_CHANNEL_NAME, | |
400 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); | |
401 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); | |
402 | } | |
403 | ||
404 | /** | |
405 | * Test start or stop tracing | |
406 | * | |
2e65d221 BH |
407 | * @param state |
408 | * the state to change to | |
409 | */ | |
3d09f0a5 BH |
410 | protected void testStartStopTracing(TraceSessionState state) { |
411 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
412 | getNodeName(), | |
2e65d221 | 413 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 414 | getSessionName()); |
2e65d221 BH |
415 | sessionItem.select(); |
416 | ||
417 | if (state == TraceSessionState.ACTIVE) { | |
418 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.START_MENU_ITEM); | |
419 | menuBot.click(); | |
420 | SWTBotUtils.waitForJobs(); | |
421 | } else { | |
422 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.STOP_MENU_ITEM); | |
423 | menuBot.click(); | |
424 | SWTBotUtils.waitForJobs(); | |
425 | } | |
3d09f0a5 | 426 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); |
2e65d221 BH |
427 | |
428 | fBot.waitUntil(ControlViewSwtBotUtil.isSessionStateChanged(sessionComp, state)); | |
429 | assertEquals(state, sessionComp.getSessionState()); | |
430 | } | |
431 | ||
432 | /** | |
433 | * Test destroy session | |
2e65d221 | 434 | */ |
3d09f0a5 BH |
435 | protected void testDestroySession() { |
436 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
437 | getNodeName(), | |
2e65d221 | 438 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 439 | getSessionName()); |
2e65d221 BH |
440 | |
441 | sessionItem.select(); | |
442 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.DESTROY_MENU_ITEM); | |
443 | menuBot.click(); | |
444 | ||
445 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.DESTROY_CONFIRM_DIALOG_TITLE).activate(); | |
446 | shell.bot().button(ControlViewSwtBotUtil.CONFIRM_DIALOG_OK_BUTTON).click(); | |
447 | SWTBotUtils.waitForJobs(); | |
448 | ||
3d09f0a5 BH |
449 | SWTBotTreeItem sessionGroupItem = SWTBotUtils.getTreeItem(fBot, fTree, |
450 | getNodeName(), ControlViewSwtBotUtil.SESSION_GROUP_NAME); | |
2e65d221 BH |
451 | |
452 | fBot.waitUntil(ConditionHelpers.isTreeChildNodeRemoved(0, sessionGroupItem)); | |
453 | assertEquals(0, sessionGroupItem.getNodes().size()); | |
454 | } | |
455 | ||
456 | /** | |
457 | * Test disconnect from node | |
2e65d221 | 458 | */ |
3d09f0a5 BH |
459 | protected void testDisconnectFromNode() { |
460 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); | |
2e65d221 BH |
461 | nodeItem.select(); |
462 | SWTBotMenu menuBot = nodeItem.contextMenu(ControlViewSwtBotUtil.DISCONNECT_MENU_ITEM); | |
463 | menuBot.click(); | |
464 | SWTBotUtils.waitForJobs(); | |
465 | ||
466 | // Verify that node is connected | |
3d09f0a5 BH |
467 | fBot.waitUntil(ControlViewSwtBotUtil.isStateChanged(fNode, TargetNodeState.DISCONNECTED)); |
468 | assertEquals(TargetNodeState.DISCONNECTED, fNode.getTargetNodeState()); | |
2e65d221 BH |
469 | assertEquals(0, nodeItem.getNodes().size()); |
470 | } | |
325d8cac BH |
471 | |
472 | /** | |
473 | * Test import | |
474 | * | |
475 | * @param createExperiment | |
476 | * flag to indicate to create an experiment or not | |
477 | * @param defaultExperiment | |
478 | * flag to indicate to use default experiment or not | |
479 | */ | |
480 | protected void testImport(boolean createExperiment, boolean defaultExperiment) { | |
481 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
482 | getNodeName(), | |
483 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
484 | getSessionName()); | |
485 | sessionItem.select(); | |
486 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); | |
487 | ||
488 | String pathString = sessionComp.isSnapshotSession() ? sessionComp.getSnapshotInfo().getSnapshotPath() : sessionComp.getSessionPath(); | |
489 | IPath path = new Path(pathString); | |
490 | ||
491 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
492 | ||
493 | //get location of workspace (java.io.File) | |
494 | File workspaceDirectory = workspace.getRoot().getLocation().toFile(); | |
495 | Path workspacePath = new Path(workspaceDirectory.toString()); | |
496 | ||
497 | // Only do tests if session path is in workspace | |
498 | if (workspacePath.isPrefixOf(path)) { | |
499 | ||
500 | generateTrace(path); | |
501 | ||
502 | // Open import wizard | |
503 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); | |
504 | menuBot.click(); | |
505 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); | |
506 | ||
507 | // This will create the Remote project if needed | |
508 | closeImportWizard(shell, ControlViewSwtBotUtil.CANCEL_BUTTON); | |
509 | ||
510 | // Verify that remote project was created by import wizard | |
511 | TmfProjectElement tmfProject = verifyRemoteProject(); | |
512 | ||
513 | // Re-open import wizard | |
514 | menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); | |
515 | menuBot.click(); | |
516 | shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); | |
517 | ||
518 | // Prepare and verify experiment handling | |
519 | String experimentName = prepareAndVerifyExperimentHandling(shell.bot(), createExperiment, defaultExperiment, path); | |
520 | ||
521 | // Finish and import | |
522 | closeImportWizard(shell, ControlViewSwtBotUtil.FINISH_BUTTON); | |
523 | ||
524 | // Verify experiment folder | |
525 | verifyExperimentFolder(createExperiment, tmfProject, experimentName); | |
526 | } | |
527 | } | |
528 | ||
529 | ||
530 | private static TmfProjectElement verifyRemoteProject() { | |
531 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
532 | // verify that project was created | |
533 | assertTrue(project.exists()); | |
534 | TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true); | |
535 | return tmfProject; | |
536 | } | |
537 | ||
538 | private static void verifyExperimentFolder(boolean createExperiment, TmfProjectElement tmfProject, String experimentName) { | |
539 | TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder(); | |
540 | if (createExperiment) { | |
541 | if (experimentName != null) { | |
542 | TmfExperimentElement expElement = expFolder.getExperiment(experimentName); | |
543 | assertNotNull(expElement); | |
544 | assertEquals(1, expElement.getTraces().size()); | |
545 | } | |
546 | } else { | |
547 | assertTrue(expFolder.getExperiments().size() == 0); | |
548 | } | |
549 | } | |
550 | ||
551 | private static void generateTrace(IPath path) { | |
552 | File traceParent = path.toFile(); | |
553 | traceParent.mkdirs(); | |
554 | LttngKernelTraceGenerator.generateLttngKernelTrace(path.append(ControlViewSwtBotUtil.KERNEL_TRACE_NAME).toFile()); | |
555 | } | |
556 | ||
557 | private static void closeImportWizard(SWTBotShell shell, String buttonName) { | |
558 | SWTBotButton button = shell.bot().button(buttonName); | |
559 | shell.bot().waitUntil(Conditions.widgetIsEnabled(button)); | |
560 | button.click(); | |
561 | fBot.waitUntil(Conditions.shellCloses(shell)); | |
562 | SWTBotUtils.waitForJobs(); | |
563 | } | |
564 | ||
565 | private static String prepareAndVerifyExperimentHandling(SWTBot bot, boolean createExperiment, boolean defaultExperiment, IPath path) { | |
566 | String experimentName = path.lastSegment(); | |
567 | if (createExperiment) { | |
568 | SWTBotCheckBox checkBox = bot.checkBox(); | |
569 | checkBox.click(); | |
570 | if (!defaultExperiment) { | |
571 | experimentName = verifyExperimentNameHandling(bot, experimentName); | |
572 | } | |
573 | } | |
574 | return experimentName; | |
575 | } | |
576 | ||
577 | private static @NonNull String verifyExperimentNameHandling(SWTBot bot, String aExperimentName) { | |
578 | String experimentName = aExperimentName; | |
579 | ||
580 | // experiment already exists | |
581 | checkFinishButton(bot, false); | |
582 | ||
583 | SWTBotText expText = bot.textInGroup(ControlViewSwtBotUtil.OPTION_GROUP_NAME); | |
584 | ||
585 | // Invalid experiment name (only whitespaces) | |
586 | expText.setText(String.valueOf(' ')); | |
587 | checkFinishButton(bot, false); | |
588 | ||
589 | // Invalid experiment name | |
590 | expText.setText(String.valueOf('/')); | |
591 | checkFinishButton(bot, false); | |
592 | ||
593 | // Set valid experiment name | |
594 | experimentName += '_'; | |
595 | expText.setText(experimentName); | |
596 | return experimentName; | |
597 | } | |
598 | ||
599 | private static void checkFinishButton(SWTBot bot, boolean isEnabled) { | |
600 | final SWTBotButton finishButton = bot.button(ControlViewSwtBotUtil.FINISH_BUTTON); | |
601 | assertTrue(finishButton.isEnabled() == isEnabled); | |
602 | } | |
603 | ||
2e65d221 | 604 | } |