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