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
.junit
.Test
;
27 import org
.junit
.runner
.RunWith
;
30 * Test for the Control view in Trace Compass. This will test the enabling
31 * of specific kernel event(s) by name.
35 @RunWith(SWTBotJunit4ClassRunner
.class)
36 public class ControlViewSpecificEventTest
extends ControlViewTest
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
41 private static final String TEST_STREAM
= "CreateSessionTestLTTng2_8.cfg";
43 private static final String CREATE_SESSION_SPECIFIC_KERNEL_EVENT_SCENARIO_NAME
= "CreateSessionSpecificKernelEvent";
45 private static final String SESSION_NAME
= "mysession";
48 * Get the test stream file name to use for the test suite
50 * @return the name of the test stream file
53 protected String
getTestStream() {
58 * Get the session name
60 * @return the session name for this test
63 protected String
getSessionName() {
69 public void testTraceSessionTree() {
71 // Initialize scenario
72 fProxy
.setTestFile(fTestFile
);
73 fProxy
.setScenario(INIT_SCENARIO_NAME
);
77 // Creating a session by specifying an event scenario
78 fProxy
.setScenario(CREATE_SESSION_SPECIFIC_KERNEL_EVENT_SCENARIO_NAME
);
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);
92 // Start, stop tracing then destroy the session and diconnect
93 testStartStopTracing(TraceSessionState
.ACTIVE
);
94 testStartStopTracing(TraceSessionState
.INACTIVE
);
96 testDisconnectFromNode();
100 * Test for enabling an event type by specifying its name
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
111 private void testEnableSpecificKernelEvent(List
<String
> events
, boolean selectInTree
, boolean useNameField
) {
112 SWTBotTreeItem sessionItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
114 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
117 sessionItem
.select();
118 SWTBotMenu menuBot
= sessionItem
.contextMenu(ControlViewSwtBotUtil
.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM
);
121 SWTBotShell shell
= fBot
.shell(ControlViewSwtBotUtil
.ENABLE_EVENT_DIALOG_TITLE
).activate();
123 // Select specific event radio button in the Specific event group
124 shell
.bot().radioInGroup(ControlViewSwtBotUtil
.GROUP_SELECT_NAME
, ControlViewSwtBotUtil
.TRACEPOINTS_GROUP_NAME
).click();
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
);
134 tracepointsTree
.expandNode(ControlViewSwtBotUtil
.ALL_TREE_NODE
);
136 SWTBotTreeItem treeItem
= SWTBotUtils
.getTreeItem(fBot
, tracepointsTree
, ControlViewSwtBotUtil
.ALL_TREE_NODE
, event
);
141 // Enters the event type in the text field Event type in the Specific event group
143 SWTBotText specificEventText
= shell
.bot().textInGroup(ControlViewSwtBotUtil
.SPECIFIC_EVENT_GROUP_NAME
);
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
151 specificEventText
.setText(buffer
.toString());
154 // Click Ok to quit the dialog window
155 shell
.bot().button(ControlViewSwtBotUtil
.DIALOG_OK_BUTTON
).click();
156 SWTBotUtils
.waitForJobs();
158 // Wait until the child of Sessions is activated
159 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(ControlViewSwtBotUtil
.KERNEL_DOMAIN_NAME
, sessionItem
));
161 // Assert that the new channel name is channel0 (which is the default name)
162 SWTBotTreeItem channelItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
164 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
166 ControlViewSwtBotUtil
.KERNEL_DOMAIN_NAME
,
167 ControlViewSwtBotUtil
.DEFAULT_CHANNEL_NAME
);
168 assertEquals(ControlViewSwtBotUtil
.DEFAULT_CHANNEL_NAME
, channelItem
.getText());
170 channelItem
.expand();
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
;
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
,
182 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
184 ControlViewSwtBotUtil
.KERNEL_DOMAIN_NAME
,
185 ControlViewSwtBotUtil
.DEFAULT_CHANNEL_NAME
,
187 assertEquals(eventName
, eventItem
.getText());