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(); | |
2e65d221 BH |
244 | |
245 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.SESSION_GROUP_NAME, nodeItem)); | |
246 | ||
247 | // Verify that node is connected | |
3d09f0a5 | 248 | fBot.waitUntil(ControlViewSwtBotUtil.isStateChanged(fNode, TargetNodeState.CONNECTED)); |
f3023b37 PT |
249 | // Wait for node configuration jobs |
250 | WaitUtils.waitForJobs(); | |
3d09f0a5 | 251 | assertEquals(TargetNodeState.CONNECTED, fNode.getTargetNodeState()); |
2e65d221 BH |
252 | } |
253 | ||
254 | /** | |
255 | * Test create session | |
2e65d221 | 256 | */ |
3d09f0a5 BH |
257 | protected void testCreateSession() { |
258 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); | |
2e65d221 BH |
259 | |
260 | SWTBotTreeItem sessionGroupItem = nodeItem.getNode(ControlViewSwtBotUtil.SESSION_GROUP_NAME); | |
261 | ||
262 | sessionGroupItem.select(); | |
263 | SWTBotMenu menuBot = sessionGroupItem.contextMenu(ControlViewSwtBotUtil.CREATE_SESSION_MENU_ITEM); | |
264 | menuBot.click(); | |
265 | ||
266 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.CREATE_SESSION_DIALOG_TITLE).activate(); | |
267 | ||
268 | SWTBotText sessionText = shell.bot().textWithLabel(ControlViewSwtBotUtil.SESSION_NAME_LABEL); | |
269 | sessionText.setText(SESSION_NAME); | |
270 | ||
271 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
f0beeb4a | 272 | WaitUtils.waitForJobs(); |
2e65d221 BH |
273 | |
274 | sessionGroupItem.expand(); | |
275 | ||
3d09f0a5 | 276 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(getSessionName(), sessionGroupItem)); |
2e65d221 BH |
277 | assertEquals(1, sessionGroupItem.getNodes().size()); |
278 | ||
3d09f0a5 BH |
279 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, |
280 | getNodeName(), | |
2e65d221 | 281 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 BH |
282 | getSessionName()); |
283 | assertEquals(getSessionName(), sessionItem.getText()); | |
2e65d221 BH |
284 | } |
285 | ||
286 | /** | |
287 | * Test enable event (all kernel tracepoints) on session level | |
2e65d221 | 288 | */ |
3d09f0a5 BH |
289 | protected void testEnableKernelEvent() { |
290 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
291 | getNodeName(), | |
2e65d221 | 292 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 293 | getSessionName()); |
2e65d221 BH |
294 | |
295 | sessionItem.select(); | |
296 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
297 | menuBot.click(); | |
298 | ||
299 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
300 | ||
9ee91a86 BH |
301 | shell.bot().radioInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.TRACEPOINTS_GROUP_NAME).click(); |
302 | ||
207ff523 | 303 | SWTBotTree tracepointsTree = shell.bot().treeInGroup(ControlViewSwtBotUtil.TRACEPOINTS_GROUP_NAME); |
65635cc8 BH |
304 | SWTBotTreeItem allItem = SWTBotUtils.getTreeItem(fBot, tracepointsTree, ControlViewSwtBotUtil.ALL_TREE_NODE); |
305 | allItem.check(); | |
2e65d221 | 306 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); |
f0beeb4a | 307 | WaitUtils.waitForJobs(); |
2e65d221 BH |
308 | |
309 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, sessionItem)); | |
310 | ||
3d09f0a5 BH |
311 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, |
312 | getNodeName(), | |
2e65d221 | 313 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 314 | getSessionName(), |
2e65d221 BH |
315 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
316 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME); | |
317 | assertEquals(ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, channelItem.getText()); | |
318 | ||
3d09f0a5 BH |
319 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
320 | getNodeName(), | |
2e65d221 | 321 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 322 | getSessionName(), |
2e65d221 BH |
323 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
324 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, | |
325 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); | |
326 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); | |
327 | ||
3d09f0a5 BH |
328 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, |
329 | getNodeName(), | |
2e65d221 | 330 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 331 | getSessionName(), |
2e65d221 BH |
332 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
333 | assertEquals(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, kernelDomainItem.getText()); | |
334 | } | |
335 | ||
336 | /** | |
337 | * Test enable Event (syscall) on domain level | |
2e65d221 | 338 | */ |
3d09f0a5 | 339 | protected void testEnableSyscalls() { |
207ff523 BR |
340 | // Case 1: Enabling all syscalls |
341 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
342 | getNodeName(), | |
343 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
344 | getSessionName()); | |
345 | ||
346 | sessionItem.select(); | |
347 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
348 | menuBot.click(); | |
349 | ||
350 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
351 | shell.bot().radioInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.SYSCALL_GROUP_NAME).click(); | |
352 | ||
353 | SWTBotTree syscallsTree = shell.bot().treeInGroup(ControlViewSwtBotUtil.SYSCALL_GROUP_NAME); | |
354 | SWTBotTreeItem allItem = SWTBotUtils.getTreeItem(fBot, syscallsTree, ControlViewSwtBotUtil.ALL_TREE_NODE); | |
355 | allItem.check(); | |
356 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
f0beeb4a | 357 | WaitUtils.waitForJobs(); |
207ff523 BR |
358 | |
359 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, sessionItem)); | |
360 | ||
3d09f0a5 BH |
361 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, |
362 | getNodeName(), | |
2e65d221 | 363 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 364 | getSessionName(), |
2e65d221 | 365 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
207ff523 BR |
366 | assertEquals(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, kernelDomainItem.getText()); |
367 | ||
368 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
369 | getNodeName(), | |
370 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
371 | getSessionName(), | |
372 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, | |
373 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME); | |
374 | assertEquals(ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, channelItem.getText()); | |
375 | ||
376 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
377 | getNodeName(), | |
378 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
379 | getSessionName(), | |
380 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, | |
381 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, | |
382 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); | |
383 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); | |
384 | ||
385 | // Case 2: Enabling three syscalls (write, read, close) from the syscall tree | |
386 | sessionItem.select(); | |
387 | menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
2e65d221 BH |
388 | menuBot.click(); |
389 | ||
207ff523 | 390 | shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); |
2e65d221 | 391 | shell.bot().radioInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.SYSCALL_GROUP_NAME).click(); |
207ff523 BR |
392 | syscallsTree = shell.bot().treeInGroup(ControlViewSwtBotUtil.SYSCALL_GROUP_NAME); |
393 | allItem = SWTBotUtils.getTreeItem(fBot, syscallsTree, ControlViewSwtBotUtil.ALL_TREE_NODE); | |
394 | allItem.expand(); | |
395 | // Enable 'write' syscall | |
396 | SWTBotTreeItem writeItem = SWTBotUtils.getTreeItem(fBot, syscallsTree, ControlViewSwtBotUtil.ALL_TREE_NODE, ControlViewSwtBotUtil.SYSCALL_WRITE_EVENT); | |
397 | writeItem.check(); | |
398 | // Enable 'read' syscall | |
399 | SWTBotTreeItem readItem = SWTBotUtils.getTreeItem(fBot, syscallsTree, ControlViewSwtBotUtil.ALL_TREE_NODE, ControlViewSwtBotUtil.SYSCALL_READ_EVENT); | |
400 | readItem.check(); | |
401 | // Enable 'close' syscall | |
402 | SWTBotTreeItem closeItem = SWTBotUtils.getTreeItem(fBot, syscallsTree, ControlViewSwtBotUtil.ALL_TREE_NODE, ControlViewSwtBotUtil.SYSCALL_CLOSE_EVENT); | |
403 | closeItem.check(); | |
2e65d221 | 404 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); |
f0beeb4a | 405 | WaitUtils.waitForJobs(); |
207ff523 BR |
406 | |
407 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, sessionItem)); | |
408 | ||
409 | kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
410 | getNodeName(), | |
411 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
412 | getSessionName(), | |
413 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); | |
414 | assertEquals(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, kernelDomainItem.getText()); | |
415 | ||
416 | channelItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
417 | getNodeName(), | |
418 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
419 | getSessionName(), | |
420 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, | |
421 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME); | |
422 | assertEquals(ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, channelItem.getText()); | |
423 | ||
424 | eventItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
425 | getNodeName(), | |
426 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
427 | getSessionName(), | |
428 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, | |
429 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, | |
430 | ControlViewSwtBotUtil.SYSCALL_WRITE_EVENT); | |
431 | assertEquals(ControlViewSwtBotUtil.SYSCALL_WRITE_EVENT, eventItem.getText()); | |
432 | ||
433 | eventItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
434 | getNodeName(), | |
435 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
436 | getSessionName(), | |
437 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, | |
438 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, | |
439 | ControlViewSwtBotUtil.SYSCALL_READ_EVENT); | |
440 | assertEquals(ControlViewSwtBotUtil.SYSCALL_READ_EVENT, eventItem.getText()); | |
441 | ||
442 | eventItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
443 | getNodeName(), | |
444 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
445 | getSessionName(), | |
446 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, | |
447 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, | |
448 | ControlViewSwtBotUtil.SYSCALL_CLOSE_EVENT); | |
449 | assertEquals(ControlViewSwtBotUtil.SYSCALL_CLOSE_EVENT, eventItem.getText()); | |
2e65d221 BH |
450 | } |
451 | ||
452 | /** | |
453 | * Test enable UST channel on session level (default values) | |
2e65d221 | 454 | */ |
3d09f0a5 BH |
455 | protected void testEnableUstChannel() { |
456 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
457 | getNodeName(), | |
2e65d221 | 458 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 459 | getSessionName()); |
2e65d221 BH |
460 | sessionItem.select(); |
461 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_CHANNEL_MENU_ITEM); | |
462 | menuBot.click(); | |
463 | ||
464 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_CHANNEL_DIALOG_TITLE).activate(); | |
465 | SWTBotText channelText = shell.bot().textWithLabel(ControlViewSwtBotUtil.CHANNEL_NAME_LABEL); | |
466 | channelText.setText(UST_CHANNEL_NAME); | |
467 | ||
468 | shell.bot().radioInGroup(ControlViewSwtBotUtil.UST_GROUP_NAME, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click(); | |
469 | shell.bot().radioInGroup(ControlViewSwtBotUtil.BUFFERTYPE_PER_UID, ControlViewSwtBotUtil.BUFFERTYPE_GROUP_NAME).click(); | |
470 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
f0beeb4a | 471 | WaitUtils.waitForJobs(); |
2e65d221 BH |
472 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.UST_DOMAIN_NAME, sessionItem)); |
473 | } | |
474 | ||
475 | /** | |
476 | * Test enable event (all tracepoints) on channel level | |
2e65d221 | 477 | */ |
3d09f0a5 BH |
478 | protected void testEnableUstEvents() { |
479 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
480 | getNodeName(), | |
2e65d221 | 481 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 482 | getSessionName(), ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
2e65d221 BH |
483 | UST_CHANNEL_NAME); |
484 | assertEquals(UST_CHANNEL_NAME, channelItem.getText()); | |
485 | ||
486 | channelItem.select(); | |
487 | SWTBotMenu menuBot = channelItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_MENU_ITEM); | |
488 | menuBot.click(); | |
489 | ||
490 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
491 | SWTBotTree tracepointsTree = shell.bot().tree(); | |
492 | tracepointsTree.select(ControlViewSwtBotUtil.ALL_TREE_NODE); | |
493 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
f0beeb4a | 494 | WaitUtils.waitForJobs(); |
2e65d221 | 495 | |
3d09f0a5 BH |
496 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
497 | getNodeName(), | |
2e65d221 | 498 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 499 | getSessionName(), |
2e65d221 BH |
500 | ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
501 | UST_CHANNEL_NAME, | |
502 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); | |
503 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); | |
504 | } | |
505 | ||
506 | /** | |
507 | * Test start or stop tracing | |
508 | * | |
2e65d221 BH |
509 | * @param state |
510 | * the state to change to | |
511 | */ | |
3d09f0a5 BH |
512 | protected void testStartStopTracing(TraceSessionState state) { |
513 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
514 | getNodeName(), | |
2e65d221 | 515 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 516 | getSessionName()); |
2e65d221 BH |
517 | sessionItem.select(); |
518 | ||
519 | if (state == TraceSessionState.ACTIVE) { | |
520 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.START_MENU_ITEM); | |
521 | menuBot.click(); | |
f0beeb4a | 522 | WaitUtils.waitForJobs(); |
2e65d221 BH |
523 | } else { |
524 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.STOP_MENU_ITEM); | |
525 | menuBot.click(); | |
f0beeb4a | 526 | WaitUtils.waitForJobs(); |
2e65d221 | 527 | } |
3d09f0a5 | 528 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); |
2e65d221 BH |
529 | |
530 | fBot.waitUntil(ControlViewSwtBotUtil.isSessionStateChanged(sessionComp, state)); | |
531 | assertEquals(state, sessionComp.getSessionState()); | |
532 | } | |
533 | ||
534 | /** | |
535 | * Test destroy session | |
2e65d221 | 536 | */ |
3d09f0a5 BH |
537 | protected void testDestroySession() { |
538 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
539 | getNodeName(), | |
2e65d221 | 540 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 541 | getSessionName()); |
2e65d221 BH |
542 | |
543 | sessionItem.select(); | |
544 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.DESTROY_MENU_ITEM); | |
545 | menuBot.click(); | |
546 | ||
547 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.DESTROY_CONFIRM_DIALOG_TITLE).activate(); | |
548 | shell.bot().button(ControlViewSwtBotUtil.CONFIRM_DIALOG_OK_BUTTON).click(); | |
f0beeb4a | 549 | WaitUtils.waitForJobs(); |
2e65d221 | 550 | |
3d09f0a5 BH |
551 | SWTBotTreeItem sessionGroupItem = SWTBotUtils.getTreeItem(fBot, fTree, |
552 | getNodeName(), ControlViewSwtBotUtil.SESSION_GROUP_NAME); | |
2e65d221 BH |
553 | |
554 | fBot.waitUntil(ConditionHelpers.isTreeChildNodeRemoved(0, sessionGroupItem)); | |
555 | assertEquals(0, sessionGroupItem.getNodes().size()); | |
556 | } | |
557 | ||
558 | /** | |
559 | * Test disconnect from node | |
2e65d221 | 560 | */ |
3d09f0a5 BH |
561 | protected void testDisconnectFromNode() { |
562 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); | |
2e65d221 BH |
563 | nodeItem.select(); |
564 | SWTBotMenu menuBot = nodeItem.contextMenu(ControlViewSwtBotUtil.DISCONNECT_MENU_ITEM); | |
565 | menuBot.click(); | |
f0beeb4a | 566 | WaitUtils.waitForJobs(); |
2e65d221 BH |
567 | |
568 | // Verify that node is connected | |
3d09f0a5 BH |
569 | fBot.waitUntil(ControlViewSwtBotUtil.isStateChanged(fNode, TargetNodeState.DISCONNECTED)); |
570 | assertEquals(TargetNodeState.DISCONNECTED, fNode.getTargetNodeState()); | |
2e65d221 BH |
571 | assertEquals(0, nodeItem.getNodes().size()); |
572 | } | |
325d8cac BH |
573 | |
574 | /** | |
575 | * Test import | |
576 | * | |
577 | * @param createExperiment | |
578 | * flag to indicate to create an experiment or not | |
579 | * @param defaultExperiment | |
580 | * flag to indicate to use default experiment or not | |
581 | */ | |
582 | protected void testImport(boolean createExperiment, boolean defaultExperiment) { | |
583 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
584 | getNodeName(), | |
585 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
586 | getSessionName()); | |
587 | sessionItem.select(); | |
588 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); | |
589 | ||
590 | String pathString = sessionComp.isSnapshotSession() ? sessionComp.getSnapshotInfo().getSnapshotPath() : sessionComp.getSessionPath(); | |
591 | IPath path = new Path(pathString); | |
592 | ||
593 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
594 | ||
595 | //get location of workspace (java.io.File) | |
596 | File workspaceDirectory = workspace.getRoot().getLocation().toFile(); | |
597 | Path workspacePath = new Path(workspaceDirectory.toString()); | |
598 | ||
599 | // Only do tests if session path is in workspace | |
600 | if (workspacePath.isPrefixOf(path)) { | |
601 | ||
602 | generateTrace(path); | |
603 | ||
604 | // Open import wizard | |
605 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); | |
606 | menuBot.click(); | |
607 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); | |
608 | ||
609 | // This will create the Remote project if needed | |
610 | closeImportWizard(shell, ControlViewSwtBotUtil.CANCEL_BUTTON); | |
611 | ||
612 | // Verify that remote project was created by import wizard | |
613 | TmfProjectElement tmfProject = verifyRemoteProject(); | |
614 | ||
615 | // Re-open import wizard | |
616 | menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); | |
617 | menuBot.click(); | |
618 | shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); | |
619 | ||
620 | // Prepare and verify experiment handling | |
621 | String experimentName = prepareAndVerifyExperimentHandling(shell.bot(), createExperiment, defaultExperiment, path); | |
622 | ||
623 | // Finish and import | |
624 | closeImportWizard(shell, ControlViewSwtBotUtil.FINISH_BUTTON); | |
625 | ||
626 | // Verify experiment folder | |
627 | verifyExperimentFolder(createExperiment, tmfProject, experimentName); | |
628 | } | |
629 | } | |
630 | ||
631 | ||
632 | private static TmfProjectElement verifyRemoteProject() { | |
633 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
634 | // verify that project was created | |
635 | assertTrue(project.exists()); | |
636 | TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true); | |
637 | return tmfProject; | |
638 | } | |
639 | ||
640 | private static void verifyExperimentFolder(boolean createExperiment, TmfProjectElement tmfProject, String experimentName) { | |
641 | TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder(); | |
642 | if (createExperiment) { | |
643 | if (experimentName != null) { | |
644 | TmfExperimentElement expElement = expFolder.getExperiment(experimentName); | |
645 | assertNotNull(expElement); | |
646 | assertEquals(1, expElement.getTraces().size()); | |
647 | } | |
648 | } else { | |
649 | assertTrue(expFolder.getExperiments().size() == 0); | |
650 | } | |
651 | } | |
652 | ||
653 | private static void generateTrace(IPath path) { | |
654 | File traceParent = path.toFile(); | |
655 | traceParent.mkdirs(); | |
4eebea10 | 656 | LttngTraceGenerator.generateLttngTrace(path.append(ControlViewSwtBotUtil.KERNEL_TRACE_NAME).toFile()); |
325d8cac BH |
657 | } |
658 | ||
659 | private static void closeImportWizard(SWTBotShell shell, String buttonName) { | |
660 | SWTBotButton button = shell.bot().button(buttonName); | |
661 | shell.bot().waitUntil(Conditions.widgetIsEnabled(button)); | |
662 | button.click(); | |
663 | fBot.waitUntil(Conditions.shellCloses(shell)); | |
f0beeb4a | 664 | WaitUtils.waitForJobs(); |
325d8cac BH |
665 | } |
666 | ||
667 | private static String prepareAndVerifyExperimentHandling(SWTBot bot, boolean createExperiment, boolean defaultExperiment, IPath path) { | |
668 | String experimentName = path.lastSegment(); | |
669 | if (createExperiment) { | |
670 | SWTBotCheckBox checkBox = bot.checkBox(); | |
671 | checkBox.click(); | |
672 | if (!defaultExperiment) { | |
673 | experimentName = verifyExperimentNameHandling(bot, experimentName); | |
674 | } | |
675 | } | |
676 | return experimentName; | |
677 | } | |
678 | ||
679 | private static @NonNull String verifyExperimentNameHandling(SWTBot bot, String aExperimentName) { | |
680 | String experimentName = aExperimentName; | |
681 | ||
682 | // experiment already exists | |
683 | checkFinishButton(bot, false); | |
684 | ||
685 | SWTBotText expText = bot.textInGroup(ControlViewSwtBotUtil.OPTION_GROUP_NAME); | |
686 | ||
687 | // Invalid experiment name (only whitespaces) | |
688 | expText.setText(String.valueOf(' ')); | |
689 | checkFinishButton(bot, false); | |
690 | ||
691 | // Invalid experiment name | |
692 | expText.setText(String.valueOf('/')); | |
693 | checkFinishButton(bot, false); | |
694 | ||
695 | // Set valid experiment name | |
696 | experimentName += '_'; | |
697 | expText.setText(experimentName); | |
698 | return experimentName; | |
699 | } | |
700 | ||
701 | private static void checkFinishButton(SWTBot bot, boolean isEnabled) { | |
702 | final SWTBotButton finishButton = bot.button(ControlViewSwtBotUtil.FINISH_BUTTON); | |
703 | assertTrue(finishButton.isEnabled() == isEnabled); | |
704 | } | |
705 | ||
2e65d221 | 706 | } |