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