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