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