tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / swtbot / tests / ControlViewSpecificEventTest.java
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
14 import java.util.Arrays;
15 import java.util.List;
16
17 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
18 import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
19 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
20 import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
21 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
22 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
23 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
24 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
25 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
26 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29
30 /**
31 * Test for the Control view in Trace Compass. This will test the enabling
32 * of specific kernel event(s) by name.
33 *
34 * @author Bruno Roy
35 */
36 @RunWith(SWTBotJunit4ClassRunner.class)
37 public class ControlViewSpecificEventTest extends ControlViewTest {
38
39 // ------------------------------------------------------------------------
40 // Constants
41 // ------------------------------------------------------------------------
42 private static final String TEST_STREAM = "CreateSessionTestLTTng2_8.cfg";
43
44 private static final String CREATE_SESSION_SPECIFIC_KERNEL_EVENT_SCENARIO_NAME = "CreateSessionSpecificKernelEvent";
45
46 private static final String SESSION_NAME = "mysession";
47
48 /**
49 * Get the test stream file name to use for the test suite
50 *
51 * @return the name of the test stream file
52 */
53 @Override
54 protected String getTestStream() {
55 return TEST_STREAM;
56 }
57
58 /**
59 * Get the session name
60 *
61 * @return the session name for this test
62 */
63 @Override
64 protected String getSessionName() {
65 return SESSION_NAME;
66 }
67
68 @Override
69 @Test
70 public void testTraceSessionTree() {
71
72 // Initialize scenario
73 fProxy.setTestFile(fTestFile);
74 fProxy.setScenario(INIT_SCENARIO_NAME);
75
76 testConnectToNode();
77
78 // Creating a session by specifying an event scenario
79 fProxy.setScenario(CREATE_SESSION_SPECIFIC_KERNEL_EVENT_SCENARIO_NAME);
80 // Create a session
81 testCreateSession();
82 // Enable an event by specifying the event type
83 testEnableSpecificKernelEvent(Arrays.asList(ControlViewSwtBotUtil.SCHED_SWITCH_EVENT_NAME), false, true);
84 // Enable multiple events by specifying the event type
85 testEnableSpecificKernelEvent(Arrays.asList(ControlViewSwtBotUtil.SCHED_WAKEUP_EVENT_NAME, ControlViewSwtBotUtil.SCHED_PROCESSWAIT_EVENT_NAME), false, true);
86 // Enable an event by specifying the event type and selection in tree (duplication of name)
87 testEnableSpecificKernelEvent(Arrays.asList(ControlViewSwtBotUtil.SCHED_PROCESSFORK_EVENT_NAME), true, true);
88 // Enable an event using the tree only
89 testEnableSpecificKernelEvent(Arrays.asList(ControlViewSwtBotUtil.SCHED_PROCESSEXEC_EVENT_NAME), true, false);
90 // Enable all events using tree. It will ignore what is written in the specific event text box.
91 testEnableSpecificKernelEvent(Arrays.asList(ControlViewSwtBotUtil.ALL_TREE_NODE), true, true);
92
93 // Start, stop tracing then destroy the session and diconnect
94 testStartStopTracing(TraceSessionState.ACTIVE);
95 testStartStopTracing(TraceSessionState.INACTIVE);
96 testDestroySession();
97 testDisconnectFromNode();
98 }
99
100 /**
101 * Test for enabling an event type by specifying its name
102 *
103 * @param events
104 * event names to enable
105 * @param selectInTree
106 * select event names also in tree
107 * Note: using All as name then all tree node is selected
108 * @param useNameField
109 * use event name field
110 *
111 */
112 private void testEnableSpecificKernelEvent(List<String> events, boolean selectInTree, boolean useNameField) {
113 SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree,
114 getNodeName(),
115 ControlViewSwtBotUtil.SESSION_GROUP_NAME,
116 getSessionName());
117
118 sessionItem.select();
119 SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM);
120 menuBot.click();
121
122 SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate();
123
124 // Select specific event radio button in the Specific event group
125 shell.bot().radioInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.TRACEPOINTS_GROUP_NAME).click();
126
127 if (selectInTree) {
128 SWTBotTree tracepointsTree = shell.bot().tree();
129 for (String event : events) {
130 if (event.equals(ControlViewSwtBotUtil.ALL_TREE_NODE)) {
131 SWTBotTreeItem treeItem = tracepointsTree.getTreeItem(ControlViewSwtBotUtil.ALL_TREE_NODE);
132 treeItem.check();
133 break;
134 }
135 tracepointsTree.expandNode(ControlViewSwtBotUtil.ALL_TREE_NODE);
136 // select specific
137 SWTBotTreeItem treeItem = SWTBotUtils.getTreeItem(fBot, tracepointsTree, ControlViewSwtBotUtil.ALL_TREE_NODE, event);
138 treeItem.check();
139 }
140 }
141
142 // Enters the event type in the text field Event type in the Specific event group
143 if (useNameField) {
144 SWTBotText specificEventText = shell.bot().textInGroup(ControlViewSwtBotUtil.SPECIFIC_EVENT_GROUP_NAME);
145 String suffix = "";
146 StringBuffer buffer = new StringBuffer();
147 for (String event : events) {
148 buffer.append(suffix).append(event);
149 // append comma and space to test removal of space
150 suffix = ", ";
151 }
152 specificEventText.setText(buffer.toString());
153 }
154
155 // Click Ok to quit the dialog window
156 shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click();
157 WaitUtils.waitForJobs();
158
159 // Wait until the child of Sessions is activated
160 fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, sessionItem));
161
162 // Assert that the new channel name is channel0 (which is the default name)
163 SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree,
164 getNodeName(),
165 ControlViewSwtBotUtil.SESSION_GROUP_NAME,
166 getSessionName(),
167 ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME,
168 ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME);
169 assertEquals(ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, channelItem.getText());
170
171 channelItem.expand();
172
173 for (String event : events) {
174 // Wait until the child of Sessions is activated
175 String eventName = event;
176 if (event.equals(ControlViewSwtBotUtil.ALL_TREE_NODE)) {
177 eventName = ControlViewSwtBotUtil.ALL_EVENTS_NAME;
178 }
179 fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(eventName, channelItem));
180 // Assert that the event type in the channel node are correct
181 SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree,
182 getNodeName(),
183 ControlViewSwtBotUtil.SESSION_GROUP_NAME,
184 getSessionName(),
185 ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME,
186 ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME,
187 eventName);
188 assertEquals(eventName, eventItem.getText());
189 }
190
191 }
192 }
This page took 0.049275 seconds and 5 git commands to generate.