Commit | Line | Data |
---|---|---|
a26d90be | 1 | /********************************************************************** |
2ba3d0a1 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
a26d90be BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
a26d90be | 10 | * Bernd Hufmann - Initial API and implementation |
2ba3d0a1 | 11 | * Alexandre Montplaisir - Port to JUnit4 |
a26d90be | 12 | **********************************************************************/ |
2ba3d0a1 | 13 | |
a26d90be BH |
14 | package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component; |
15 | ||
2ba3d0a1 AM |
16 | import static org.junit.Assert.assertEquals; |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.assertTrue; | |
19 | ||
a26d90be BH |
20 | import java.io.File; |
21 | import java.net.URL; | |
22 | ||
a26d90be BH |
23 | import org.eclipse.core.runtime.FileLocator; |
24 | import org.eclipse.core.runtime.Path; | |
9315aeee BH |
25 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState; |
26 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement; | |
27 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; | |
28 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; | |
29 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState; | |
a26d90be BH |
30 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub; |
31 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub; | |
32 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub; | |
33 | import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy; | |
34 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory; | |
35 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; | |
a26d90be BH |
36 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventComponent; |
37 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.KernelProviderComponent; | |
38 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent; | |
39 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent; | |
40 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent; | |
a07c7629 | 41 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProviderGroup; |
a26d90be | 42 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; |
8577ed1e | 43 | import org.eclipse.rse.core.RSECorePlugin; |
a26d90be | 44 | import org.eclipse.rse.core.model.IHost; |
8577ed1e BH |
45 | import org.eclipse.rse.core.model.ISystemProfile; |
46 | import org.eclipse.rse.core.model.ISystemRegistry; | |
a26d90be BH |
47 | import org.junit.After; |
48 | import org.junit.Before; | |
2ba3d0a1 | 49 | import org.junit.Test; |
9269df72 | 50 | import org.osgi.framework.FrameworkUtil; |
a26d90be BH |
51 | |
52 | /** | |
2ba3d0a1 AM |
53 | * The class <code>TraceControlKernelProviderTests</code> contains UST provider |
54 | * handling test cases. | |
a26d90be | 55 | */ |
2ba3d0a1 AM |
56 | @SuppressWarnings("nls") |
57 | public class TraceControlKernelProviderTests { | |
a26d90be BH |
58 | |
59 | // ------------------------------------------------------------------------ | |
60 | // Constants | |
61 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 62 | |
a26d90be BH |
63 | private static final String TEST_STREAM = "CreateTreeTest.cfg"; |
64 | private static final String SCEN_SCENARIO1_TEST = "Scenario1"; | |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // Test data | |
68 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 69 | |
a26d90be BH |
70 | private TraceControlTestFacility fFacility; |
71 | private TestRemoteSystemProxy fProxy; | |
cfdb727a AM |
72 | private String fTestFile; |
73 | ||
a26d90be BH |
74 | // ------------------------------------------------------------------------ |
75 | // Housekeeping | |
76 | // ------------------------------------------------------------------------ | |
77 | ||
78 | /** | |
79 | * Perform pre-test initialization. | |
80 | * | |
81 | * @throws Exception | |
82 | * if the initialization fails for some reason | |
a26d90be | 83 | */ |
a26d90be BH |
84 | @Before |
85 | public void setUp() throws Exception { | |
86 | fFacility = TraceControlTestFacility.getInstance(); | |
87 | fProxy = new TestRemoteSystemProxy(); | |
9269df72 | 88 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null); |
a26d90be BH |
89 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
90 | fTestFile = testfile.getAbsolutePath(); | |
91 | } | |
92 | ||
93 | /** | |
94 | * Perform post-test clean-up. | |
a26d90be | 95 | */ |
a26d90be | 96 | @After |
2ba3d0a1 | 97 | public void tearDown() { |
b957fb8c | 98 | fFacility.waitForJobs(); |
a26d90be | 99 | } |
cfdb727a | 100 | |
a26d90be BH |
101 | /** |
102 | * Run the TraceControlComponent. | |
2ba3d0a1 AM |
103 | * |
104 | * @throws Exception | |
105 | * Would fail the test | |
a26d90be | 106 | */ |
2ba3d0a1 | 107 | @Test |
a26d90be | 108 | public void testKernelProviderTree() throws Exception { |
cfdb727a | 109 | |
a26d90be BH |
110 | fProxy.setTestFile(fTestFile); |
111 | fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST); | |
cfdb727a | 112 | |
a26d90be BH |
113 | ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot(); |
114 | ||
8577ed1e BH |
115 | ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); |
116 | ISystemProfile profile = registry.createSystemProfile("myProfile", true); | |
117 | IHost host = registry.createLocalHost(profile, "myProfile", "user"); | |
cfdb727a | 118 | |
a26d90be BH |
119 | TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy); |
120 | ||
121 | root.addChild(node); | |
a26d90be BH |
122 | |
123 | fFacility.waitForJobs(); | |
124 | ||
b957fb8c BH |
125 | fFacility.executeCommand(node, "connect"); |
126 | int i = 0; | |
127 | while ((i < 20) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) { | |
128 | i++; | |
129 | fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY); | |
130 | } | |
131 | ||
a26d90be BH |
132 | // Verify that node is connected |
133 | assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState()); | |
134 | ||
a07c7629 | 135 | // Get provider and session group |
a26d90be BH |
136 | ITraceControlComponent[] groups = node.getChildren(); |
137 | assertNotNull(groups); | |
138 | assertEquals(2, groups.length); | |
139 | ||
a07c7629 BH |
140 | // Check for kernel provider |
141 | TraceProviderGroup providerGroup = (TraceProviderGroup) groups[0]; | |
142 | assertTrue(providerGroup.hasKernelProvider()); | |
143 | ||
a26d90be | 144 | // Get kernel provider |
a07c7629 | 145 | ITraceControlComponent[] providers = providerGroup.getChildren(); |
a26d90be BH |
146 | KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0]; |
147 | ||
cfdb727a | 148 | // Get kernel provider events and select 2 events |
a26d90be BH |
149 | ITraceControlComponent[] events = kernelProvider.getChildren(); |
150 | assertNotNull(events); | |
151 | assertEquals(3, events.length); | |
152 | ||
153 | BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0]; | |
154 | BaseEventComponent baseEventInfo1 = (BaseEventComponent) events[1]; | |
155 | ||
156 | // Initialize dialog implementations for command execution | |
157 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub()); | |
158 | TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub()); | |
159 | TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub()); | |
160 | ||
161 | // Initialize session handling scenario | |
162 | fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING); | |
cfdb727a | 163 | |
a26d90be BH |
164 | // ------------------------------------------------------------------------ |
165 | // Create session | |
166 | // ------------------------------------------------------------------------ | |
167 | TraceSessionComponent session = fFacility.createSession(groups[1]); | |
cfdb727a | 168 | |
a26d90be BH |
169 | // Verify that session was created |
170 | assertNotNull(session); | |
171 | assertEquals("mysession", session.getName()); | |
172 | assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session.getSessionPath()); | |
173 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
174 | ||
175 | // ------------------------------------------------------------------------ | |
176 | // Enable event on default channel on created session above | |
177 | // ------------------------------------------------------------------------ | |
178 | // Initialize scenario | |
179 | fProxy.setScenario(SCEN_SCENARIO1_TEST); | |
180 | ||
181 | ITraceControlComponent[] components = { baseEventInfo0, baseEventInfo1 }; | |
182 | ||
183 | fFacility.executeCommand(components, "assign.event"); | |
cfdb727a | 184 | |
a26d90be BH |
185 | // Verify that kernel domain was created |
186 | ITraceControlComponent[] domains = session.getChildren(); | |
187 | assertNotNull(domains); | |
188 | assertEquals(1, domains.length); | |
189 | ||
190 | assertEquals("Kernel", domains[0].getName()); | |
cfdb727a | 191 | |
a26d90be BH |
192 | // Verify that channel0 was created with default values |
193 | ITraceControlComponent[] channels = domains[0].getChildren(); | |
194 | assertNotNull(channels); | |
195 | assertEquals(1, channels.length); | |
196 | ||
197 | assertTrue(channels[0] instanceof TraceChannelComponent); | |
cfdb727a | 198 | TraceChannelComponent channel = (TraceChannelComponent) channels[0]; |
a26d90be BH |
199 | assertEquals("channel0", channel.getName()); |
200 | assertEquals(4, channel.getNumberOfSubBuffers()); | |
201 | assertEquals("splice()", channel.getOutputType()); | |
202 | assertEquals(false, channel.isOverwriteMode()); | |
203 | assertEquals(200, channel.getReadTimer()); | |
204 | assertEquals(TraceEnablement.ENABLED, channel.getState()); | |
205 | assertEquals(262144, channel.getSubBufferSize()); | |
206 | assertEquals(0, channel.getSwitchTimer()); | |
207 | ||
208 | // Verify that event components were created | |
209 | ITraceControlComponent[] channel0Events = channel.getChildren(); | |
210 | assertNotNull(channel0Events); | |
211 | assertEquals(2, channel0Events.length); | |
212 | assertTrue(channel0Events[0] instanceof TraceEventComponent); | |
213 | assertTrue(channel0Events[1] instanceof TraceEventComponent); | |
214 | ||
215 | TraceEventComponent event = (TraceEventComponent) channel0Events[0]; | |
216 | assertEquals("sched_kthread_stop_ret", event.getName()); | |
217 | assertEquals(TraceLogLevel.TRACE_EMERG, event.getLogLevel()); | |
218 | assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); | |
219 | assertEquals(TraceEnablement.ENABLED, event.getState()); | |
220 | ||
221 | TraceEventComponent event1 = (TraceEventComponent) channel0Events[1]; | |
222 | assertEquals("sched_kthread_stop", event1.getName()); | |
223 | assertEquals(TraceLogLevel.TRACE_EMERG, event1.getLogLevel()); | |
224 | assertEquals(TraceEventType.TRACEPOINT, event1.getEventType()); | |
225 | assertEquals(TraceEnablement.ENABLED, event1.getState()); | |
226 | ||
227 | // ------------------------------------------------------------------------ | |
cfdb727a | 228 | // Disable event components |
a26d90be BH |
229 | // ------------------------------------------------------------------------ |
230 | ITraceControlComponent[] selection = { event, event1 }; | |
231 | fFacility.executeCommand(selection, "disableEvent"); | |
cfdb727a | 232 | |
a26d90be BH |
233 | assertEquals(TraceEnablement.DISABLED, event.getState()); |
234 | assertEquals(TraceEnablement.DISABLED, event1.getState()); | |
235 | ||
236 | // ------------------------------------------------------------------------ | |
cfdb727a | 237 | // Enable event component |
a26d90be BH |
238 | // ------------------------------------------------------------------------ |
239 | fFacility.executeCommand(event1, "enableEvent"); | |
cfdb727a | 240 | |
a26d90be BH |
241 | // Verify event state |
242 | assertEquals(TraceEnablement.ENABLED, event1.getState()); | |
cfdb727a | 243 | |
a26d90be | 244 | // ------------------------------------------------------------------------ |
cfdb727a | 245 | // Destroy session |
a26d90be BH |
246 | // ------------------------------------------------------------------------ |
247 | // Initialize session handling scenario | |
248 | fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING); | |
cfdb727a | 249 | |
a26d90be | 250 | fFacility.destroySession(session); |
cfdb727a | 251 | |
a26d90be BH |
252 | // Verify that no more session components exist |
253 | assertEquals(0, groups[1].getChildren().length); | |
254 | ||
255 | //------------------------------------------------------------------------- | |
256 | // Disconnect node | |
257 | //------------------------------------------------------------------------- | |
258 | fFacility.executeCommand(node, "disconnect"); | |
259 | assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState()); | |
cfdb727a | 260 | |
a26d90be BH |
261 | //------------------------------------------------------------------------- |
262 | // Delete node | |
263 | //------------------------------------------------------------------------- | |
264 | fFacility.executeCommand(node, "delete"); | |
265 | assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length); | |
266 | ||
267 | } | |
268 | } |