| 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.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; |
| 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.EnableChannelDialogStub; |
| 31 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub; |
| 32 | import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy; |
| 33 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory; |
| 34 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
| 35 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventComponent; |
| 36 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.KernelProviderComponent; |
| 37 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent; |
| 38 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent; |
| 39 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent; |
| 40 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; |
| 41 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstProviderComponent; |
| 42 | import org.eclipse.rse.core.RSECorePlugin; |
| 43 | import org.eclipse.rse.core.model.IHost; |
| 44 | import org.eclipse.rse.core.model.ISystemProfile; |
| 45 | import org.eclipse.rse.core.model.ISystemRegistry; |
| 46 | import org.junit.After; |
| 47 | import org.junit.Before; |
| 48 | import org.osgi.framework.FrameworkUtil; |
| 49 | |
| 50 | /** |
| 51 | * The class <code>TraceControlUstProviderTests</code> contains UST provider handling |
| 52 | * test cases. |
| 53 | */ |
| 54 | @SuppressWarnings("nls") |
| 55 | public class TraceControlUstProviderTests extends TestCase { |
| 56 | |
| 57 | // ------------------------------------------------------------------------ |
| 58 | // Constants |
| 59 | // ------------------------------------------------------------------------ |
| 60 | private static final String TEST_STREAM = "CreateTreeTest.cfg"; |
| 61 | private static final String SCEN_SCENARIO2_TEST = "Scenario2"; |
| 62 | |
| 63 | // ------------------------------------------------------------------------ |
| 64 | // Test data |
| 65 | // ------------------------------------------------------------------------ |
| 66 | private TraceControlTestFacility fFacility; |
| 67 | private TestRemoteSystemProxy fProxy; |
| 68 | private String fTestFile; |
| 69 | |
| 70 | // ------------------------------------------------------------------------ |
| 71 | // Static methods |
| 72 | // ------------------------------------------------------------------------ |
| 73 | |
| 74 | /** |
| 75 | * Returns test setup used when executing test case stand-alone. |
| 76 | * @return Test setup class |
| 77 | */ |
| 78 | public static Test suite() { |
| 79 | return new ModelImplTestSetup(new TestSuite(TraceControlUstProviderTests.class)); |
| 80 | } |
| 81 | |
| 82 | // ------------------------------------------------------------------------ |
| 83 | // Housekeeping |
| 84 | // ------------------------------------------------------------------------ |
| 85 | |
| 86 | /** |
| 87 | * Perform pre-test initialization. |
| 88 | * |
| 89 | * @throws Exception |
| 90 | * if the initialization fails for some reason |
| 91 | * |
| 92 | */ |
| 93 | @Override |
| 94 | @Before |
| 95 | public void setUp() throws Exception { |
| 96 | fFacility = TraceControlTestFacility.getInstance(); |
| 97 | fProxy = new TestRemoteSystemProxy(); |
| 98 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null); |
| 99 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
| 100 | fTestFile = testfile.getAbsolutePath(); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Perform post-test clean-up. |
| 105 | * |
| 106 | * @throws Exception |
| 107 | * if the clean-up fails for some reason |
| 108 | * |
| 109 | */ |
| 110 | @Override |
| 111 | @After |
| 112 | public void tearDown() throws Exception { |
| 113 | fFacility.waitForJobs(); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Run the TraceControlComponent. |
| 118 | * |
| 119 | * @throws Exception |
| 120 | * This will fail the test |
| 121 | */ |
| 122 | public void testUstProviderTree() throws Exception { |
| 123 | |
| 124 | fProxy.setTestFile(fTestFile); |
| 125 | fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST); |
| 126 | |
| 127 | ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot(); |
| 128 | |
| 129 | ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); |
| 130 | ISystemProfile profile = registry.createSystemProfile("myProfile", true); |
| 131 | IHost host = registry.createLocalHost(profile, "myProfile", "user"); |
| 132 | |
| 133 | TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy); |
| 134 | root.addChild(node); |
| 135 | |
| 136 | fFacility.waitForJobs(); |
| 137 | |
| 138 | fFacility.executeCommand(node, "connect"); |
| 139 | |
| 140 | int i = 0; |
| 141 | while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) { |
| 142 | i++; |
| 143 | fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY); |
| 144 | } |
| 145 | |
| 146 | // Verify that node is connected |
| 147 | assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState()); |
| 148 | |
| 149 | // Get provider groups |
| 150 | ITraceControlComponent[] groups = node.getChildren(); |
| 151 | assertNotNull(groups); |
| 152 | assertEquals(2, groups.length); |
| 153 | |
| 154 | // Get kernel provider |
| 155 | ITraceControlComponent[] providers = groups[0].getChildren(); |
| 156 | KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0]; |
| 157 | |
| 158 | // Get kernel provider events and select 2 events |
| 159 | ITraceControlComponent[] events = kernelProvider.getChildren(); |
| 160 | assertNotNull(events); |
| 161 | assertEquals(3, events.length); |
| 162 | |
| 163 | BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0]; |
| 164 | BaseEventComponent baseEventInfo1 = (BaseEventComponent) events[1]; |
| 165 | |
| 166 | // Initialize dialog implementations for command execution |
| 167 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub()); |
| 168 | TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub()); |
| 169 | TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub()); |
| 170 | |
| 171 | // ------------------------------------------------------------------------ |
| 172 | // Create session |
| 173 | // ------------------------------------------------------------------------ |
| 174 | // Initialize session handling scenario |
| 175 | fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH); |
| 176 | |
| 177 | CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub(); |
| 178 | sessionDialogStub.setSessionPath("/home/user/temp"); |
| 179 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub); |
| 180 | |
| 181 | TraceSessionComponent session = fFacility.createSession(groups[1]); |
| 182 | |
| 183 | // Verify that session was created |
| 184 | assertNotNull(session); |
| 185 | assertEquals("mysession", session.getName()); |
| 186 | assertEquals("/home/user/temp", session.getSessionPath()); |
| 187 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); |
| 188 | |
| 189 | // ------------------------------------------------------------------------ |
| 190 | // Enable Channel on UST global domain |
| 191 | // ------------------------------------------------------------------------ |
| 192 | fProxy.setScenario(SCEN_SCENARIO2_TEST); |
| 193 | EnableChannelDialogStub channelDialogStub = new EnableChannelDialogStub(); |
| 194 | channelDialogStub.setIsKernel(false); |
| 195 | channelDialogStub.getChannelInfo().setOverwriteMode(false); |
| 196 | channelDialogStub.getChannelInfo().setSwitchTimer(200); |
| 197 | channelDialogStub.getChannelInfo().setReadTimer(100); |
| 198 | channelDialogStub.getChannelInfo().setNumberOfSubBuffers(2); |
| 199 | TraceControlDialogFactory.getInstance().setEnableChannelDialog(channelDialogStub); |
| 200 | |
| 201 | fFacility.executeCommand(session, "enableChannelOnSession"); |
| 202 | |
| 203 | // Verify that UST domain was created |
| 204 | ITraceControlComponent[] domains = session.getChildren(); |
| 205 | assertNotNull(domains); |
| 206 | assertEquals(1, domains.length); |
| 207 | |
| 208 | assertEquals("UST global", domains[0].getName()); |
| 209 | |
| 210 | // Verify that channel was created with correct data |
| 211 | ITraceControlComponent[]channels = domains[0].getChildren(); |
| 212 | assertNotNull(channels); |
| 213 | assertEquals(1, channels.length); |
| 214 | |
| 215 | assertTrue(channels[0] instanceof TraceChannelComponent); |
| 216 | TraceChannelComponent channel = (TraceChannelComponent) channels[0]; |
| 217 | assertEquals("mychannel", channel.getName()); |
| 218 | assertEquals(2, channel.getNumberOfSubBuffers()); |
| 219 | assertEquals("mmap()", channel.getOutputType()); |
| 220 | assertEquals(false, channel.isOverwriteMode()); |
| 221 | assertEquals(100, channel.getReadTimer()); |
| 222 | assertEquals(TraceEnablement.ENABLED, channel.getState()); |
| 223 | assertEquals(16384, channel.getSubBufferSize()); |
| 224 | assertEquals(200, channel.getSwitchTimer()); |
| 225 | |
| 226 | // ------------------------------------------------------------------------ |
| 227 | // Enable event on default channel on created session above |
| 228 | // ------------------------------------------------------------------------ |
| 229 | // Get first UST provider |
| 230 | UstProviderComponent ustProvider = (UstProviderComponent) providers[1]; |
| 231 | assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider.getName()); |
| 232 | assertEquals(9379, ustProvider.getPid()); |
| 233 | |
| 234 | // Get events |
| 235 | events = ustProvider.getChildren(); |
| 236 | assertNotNull(events); |
| 237 | assertEquals(2, events.length); |
| 238 | |
| 239 | baseEventInfo0 = (BaseEventComponent) events[0]; |
| 240 | baseEventInfo1 = (BaseEventComponent) events[1]; |
| 241 | |
| 242 | ITraceControlComponent[] ustSelection = { baseEventInfo0, baseEventInfo1 }; |
| 243 | |
| 244 | fFacility.executeCommand(ustSelection, "assign.event"); |
| 245 | |
| 246 | // verify that events were created under the channel |
| 247 | // Note that domain and channel has to be re-read because the tree is re-created |
| 248 | |
| 249 | domains = session.getChildren(); |
| 250 | |
| 251 | // Verify that channel was created with correct data |
| 252 | channels = domains[0].getChildren(); |
| 253 | |
| 254 | ITraceControlComponent[] ustEvents = channels[0].getChildren(); |
| 255 | assertEquals(2, ustEvents.length); |
| 256 | |
| 257 | TraceEventComponent event = (TraceEventComponent) ustEvents[0]; |
| 258 | assertEquals("ust_tests_hello:tptest_sighandler", event.getName()); |
| 259 | assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel()); |
| 260 | assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); |
| 261 | assertEquals(TraceEnablement.ENABLED, event.getState()); |
| 262 | |
| 263 | event = (TraceEventComponent) ustEvents[1]; |
| 264 | assertEquals("ust_tests_hello:tptest", ustEvents[1].getName()); |
| 265 | assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel()); |
| 266 | assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); |
| 267 | assertEquals(TraceEnablement.ENABLED, event.getState()); |
| 268 | |
| 269 | // ------------------------------------------------------------------------ |
| 270 | // Disable event components |
| 271 | // ------------------------------------------------------------------------ |
| 272 | fFacility.executeCommand(event, "disableEvent"); |
| 273 | |
| 274 | assertEquals(TraceEnablement.DISABLED, event.getState()); |
| 275 | |
| 276 | // ------------------------------------------------------------------------ |
| 277 | // Enable event component |
| 278 | // ------------------------------------------------------------------------ |
| 279 | fFacility.executeCommand(event, "enableEvent"); |
| 280 | |
| 281 | // Verify event state |
| 282 | assertEquals(TraceEnablement.ENABLED, event.getState()); |
| 283 | |
| 284 | // ------------------------------------------------------------------------ |
| 285 | // Destroy session |
| 286 | // ------------------------------------------------------------------------ |
| 287 | |
| 288 | // Initialize session handling scenario |
| 289 | fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING); |
| 290 | |
| 291 | fFacility.destroySession(session); |
| 292 | |
| 293 | // Verify that no more session components exist |
| 294 | assertEquals(0, groups[1].getChildren().length); |
| 295 | |
| 296 | //------------------------------------------------------------------------- |
| 297 | // Disconnect node |
| 298 | //------------------------------------------------------------------------- |
| 299 | fFacility.executeCommand(node, "disconnect"); |
| 300 | assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState()); |
| 301 | |
| 302 | //------------------------------------------------------------------------- |
| 303 | // Delete node |
| 304 | //------------------------------------------------------------------------- |
| 305 | fFacility.executeCommand(node, "delete"); |
| 306 | assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length); |
| 307 | } |
| 308 | } |