1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.swtbot
.tests
;
12 import static org
.junit
.Assert
.assertEquals
;
14 import java
.util
.Arrays
;
15 import java
.util
.List
;
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
;
31 * Test for the Control view in Trace Compass. This will test the enabling
32 * of specific kernel event(s) by name.
36 @RunWith(SWTBotJunit4ClassRunner
.class)
37 public class ControlViewSpecificEventTest
extends ControlViewTest
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
42 private static final String TEST_STREAM
= "CreateSessionTestLTTng2_8.cfg";
44 private static final String CREATE_SESSION_SPECIFIC_KERNEL_EVENT_SCENARIO_NAME
= "CreateSessionSpecificKernelEvent";
46 private static final String SESSION_NAME
= "mysession";
49 * Get the test stream file name to use for the test suite
51 * @return the name of the test stream file
54 protected String
getTestStream() {
59 * Get the session name
61 * @return the session name for this test
64 protected String
getSessionName() {
70 public void testTraceSessionTree() {
72 // Initialize scenario
73 fProxy
.setTestFile(fTestFile
);
74 fProxy
.setScenario(INIT_SCENARIO_NAME
);
78 // Creating a session by specifying an event scenario
79 fProxy
.setScenario(CREATE_SESSION_SPECIFIC_KERNEL_EVENT_SCENARIO_NAME
);
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);
93 // Start, stop tracing then destroy the session and diconnect
94 testStartStopTracing(TraceSessionState
.ACTIVE
);
95 testStartStopTracing(TraceSessionState
.INACTIVE
);
97 testDisconnectFromNode();
101 * Test for enabling an event type by specifying its name
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
112 private void testEnableSpecificKernelEvent(List
<String
> events
, boolean selectInTree
, boolean useNameField
) {
113 SWTBotTreeItem sessionItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
115 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
118 sessionItem
.select();
119 SWTBotMenu menuBot
= sessionItem
.contextMenu(ControlViewSwtBotUtil
.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM
);
122 SWTBotShell shell
= fBot
.shell(ControlViewSwtBotUtil
.ENABLE_EVENT_DIALOG_TITLE
).activate();
124 // Select specific event radio button in the Specific event group
125 shell
.bot().radioInGroup(ControlViewSwtBotUtil
.GROUP_SELECT_NAME
, ControlViewSwtBotUtil
.TRACEPOINTS_GROUP_NAME
).click();
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
);
135 tracepointsTree
.expandNode(ControlViewSwtBotUtil
.ALL_TREE_NODE
);
137 SWTBotTreeItem treeItem
= SWTBotUtils
.getTreeItem(fBot
, tracepointsTree
, ControlViewSwtBotUtil
.ALL_TREE_NODE
, event
);
142 // Enters the event type in the text field Event type in the Specific event group
144 SWTBotText specificEventText
= shell
.bot().textInGroup(ControlViewSwtBotUtil
.SPECIFIC_EVENT_GROUP_NAME
);
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
152 specificEventText
.setText(buffer
.toString());
155 // Click Ok to quit the dialog window
156 shell
.bot().button(ControlViewSwtBotUtil
.DIALOG_OK_BUTTON
).click();
157 WaitUtils
.waitForJobs();
159 // Wait until the child of Sessions is activated
160 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(ControlViewSwtBotUtil
.KERNEL_DOMAIN_NAME
, sessionItem
));
162 // Assert that the new channel name is channel0 (which is the default name)
163 SWTBotTreeItem channelItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
165 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
167 ControlViewSwtBotUtil
.KERNEL_DOMAIN_NAME
,
168 ControlViewSwtBotUtil
.DEFAULT_CHANNEL_NAME
);
169 assertEquals(ControlViewSwtBotUtil
.DEFAULT_CHANNEL_NAME
, channelItem
.getText());
171 channelItem
.expand();
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
;
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
,
183 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
185 ControlViewSwtBotUtil
.KERNEL_DOMAIN_NAME
,
186 ControlViewSwtBotUtil
.DEFAULT_CHANNEL_NAME
,
188 assertEquals(eventName
, eventItem
.getText());