| 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.service.TestRemoteSystemProxy; |
| 24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo; |
| 25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
| 26 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TargetNodeState; |
| 27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement; |
| 28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType; |
| 29 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel; |
| 30 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState; |
| 31 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventComponent; |
| 32 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.KernelProviderComponent; |
| 33 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent; |
| 34 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent; |
| 35 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent; |
| 36 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent; |
| 37 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProbeEventComponent; |
| 38 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; |
| 39 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstProviderComponent; |
| 40 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.BaseEventPropertySource; |
| 41 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.KernelProviderPropertySource; |
| 42 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TargetNodePropertySource; |
| 43 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceChannelPropertySource; |
| 44 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceDomainPropertySource; |
| 45 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceEventPropertySource; |
| 46 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceProbeEventPropertySource; |
| 47 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceSessionPropertySource; |
| 48 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.UstProviderPropertySource; |
| 49 | import org.eclipse.linuxtools.lttng2.ui.tests.Activator; |
| 50 | import org.eclipse.rse.core.model.Host; |
| 51 | import org.eclipse.rse.core.model.IHost; |
| 52 | import org.eclipse.rse.internal.core.model.SystemProfile; |
| 53 | import org.eclipse.ui.views.properties.IPropertySource; |
| 54 | import org.junit.After; |
| 55 | import org.junit.Before; |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * The class <code>TraceControlPropertiesTest</code> contains tests for the all property class</code>. |
| 60 | * |
| 61 | */ |
| 62 | @SuppressWarnings("nls") |
| 63 | public class TraceControlPropertiesTest extends TestCase { |
| 64 | |
| 65 | // ------------------------------------------------------------------------ |
| 66 | // Constants |
| 67 | // ------------------------------------------------------------------------ |
| 68 | private static final String DIRECTORY = "testfiles"; |
| 69 | private static final String TEST_STREAM = "ListInfoTest.cfg"; |
| 70 | private static final String SCEN_LIST_INFO_TEST = "ListInfoTest"; |
| 71 | |
| 72 | |
| 73 | // ------------------------------------------------------------------------ |
| 74 | // Test data |
| 75 | // ------------------------------------------------------------------------ |
| 76 | |
| 77 | // ------------------------------------------------------------------------ |
| 78 | // Static methods |
| 79 | // ------------------------------------------------------------------------ |
| 80 | |
| 81 | /** |
| 82 | * Returns test setup used when executing test case stand-alone. |
| 83 | * @return Test setup class |
| 84 | */ |
| 85 | public static Test suite() { |
| 86 | return new ModelImplTestSetup(new TestSuite(TraceControlPropertiesTest.class)); |
| 87 | } |
| 88 | |
| 89 | // ------------------------------------------------------------------------ |
| 90 | // Housekeeping |
| 91 | // ------------------------------------------------------------------------ |
| 92 | |
| 93 | /** |
| 94 | * Perform pre-test initialization. |
| 95 | * |
| 96 | * @throws Exception |
| 97 | * if the initialization fails for some reason |
| 98 | * |
| 99 | */ |
| 100 | @Override |
| 101 | @Before |
| 102 | public void setUp() throws Exception { |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Perform post-test clean-up. |
| 107 | * |
| 108 | * @throws Exception |
| 109 | * if the clean-up fails for some reason |
| 110 | * |
| 111 | */ |
| 112 | @Override |
| 113 | @After |
| 114 | public void tearDown() throws Exception { |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Run the TraceControlComponent. |
| 119 | */ |
| 120 | public void testComponentProperties() throws Exception { |
| 121 | |
| 122 | TestRemoteSystemProxy proxy = new TestRemoteSystemProxy(); |
| 123 | |
| 124 | URL location = FileLocator.find(Activator.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
| 125 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
| 126 | proxy.setTestFile(testfile.getAbsolutePath()); |
| 127 | proxy.setScenario(SCEN_LIST_INFO_TEST); |
| 128 | |
| 129 | ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot(); |
| 130 | |
| 131 | @SuppressWarnings("restriction") |
| 132 | IHost host = new Host(new SystemProfile("myProfile", true)); |
| 133 | host.setHostName("127.0.0.1"); |
| 134 | |
| 135 | TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, proxy); |
| 136 | |
| 137 | root.addChild(node); |
| 138 | node.connect(); |
| 139 | |
| 140 | TraceControlTestFacility.getInstance().waitForJobs(); |
| 141 | |
| 142 | // ------------------------------------------------------------------------ |
| 143 | // Verify Node Properties (adapter) |
| 144 | // ------------------------------------------------------------------------ |
| 145 | Object adapter = node.getAdapter(IPropertySource.class); |
| 146 | assertNotNull(adapter); |
| 147 | assertTrue(adapter instanceof TargetNodePropertySource); |
| 148 | |
| 149 | TargetNodePropertySource source = (TargetNodePropertySource)adapter; |
| 150 | |
| 151 | assertNull(source.getEditableValue()); |
| 152 | assertFalse(source.isPropertySet(TargetNodePropertySource.TARGET_NODE_NAME_PROPERTY_ID)); |
| 153 | assertNotNull(source.getPropertyDescriptors()); |
| 154 | |
| 155 | assertEquals("myNode", source.getPropertyValue(TargetNodePropertySource.TARGET_NODE_NAME_PROPERTY_ID)); |
| 156 | assertEquals("127.0.0.1", source.getPropertyValue(TargetNodePropertySource.TARGET_NODE_ADDRESS_PROPERTY_ID)); |
| 157 | assertEquals(TargetNodeState.CONNECTED.name(), source.getPropertyValue(TargetNodePropertySource.TARGET_NODE_STATE_PROPERTY_ID)); |
| 158 | assertNull(source.getPropertyValue("test")); |
| 159 | |
| 160 | adapter = node.getAdapter(IChannelInfo.class); |
| 161 | assertNull(adapter); |
| 162 | |
| 163 | ITraceControlComponent[] groups = node.getChildren(); |
| 164 | assertNotNull(groups); |
| 165 | assertEquals(2, groups.length); |
| 166 | |
| 167 | ITraceControlComponent[] providers = groups[0].getChildren(); |
| 168 | |
| 169 | assertNotNull(providers); |
| 170 | assertEquals(3, providers.length); |
| 171 | |
| 172 | // ------------------------------------------------------------------------ |
| 173 | // Verify Kernel Provider Properties (adapter) |
| 174 | // ------------------------------------------------------------------------ |
| 175 | KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0]; |
| 176 | |
| 177 | adapter = kernelProvider.getAdapter(IPropertySource.class); |
| 178 | assertNotNull(adapter); |
| 179 | assertTrue(adapter instanceof KernelProviderPropertySource); |
| 180 | |
| 181 | KernelProviderPropertySource kernelSource = (KernelProviderPropertySource)adapter; |
| 182 | assertNotNull(kernelSource.getPropertyDescriptors()); |
| 183 | |
| 184 | assertEquals("Kernel", kernelSource.getPropertyValue(KernelProviderPropertySource.KERNEL_PROVIDER_NAME_PROPERTY_ID)); |
| 185 | |
| 186 | // ------------------------------------------------------------------------ |
| 187 | // Verify UST Provider Properties (adapter) |
| 188 | // ------------------------------------------------------------------------ |
| 189 | UstProviderComponent ustProvider = (UstProviderComponent) providers[1]; |
| 190 | |
| 191 | adapter = ustProvider.getAdapter(IPropertySource.class); |
| 192 | assertNotNull(adapter); |
| 193 | assertTrue(adapter instanceof UstProviderPropertySource); |
| 194 | |
| 195 | UstProviderPropertySource ustSource = (UstProviderPropertySource)adapter; |
| 196 | assertNotNull(ustSource.getPropertyDescriptors()); |
| 197 | |
| 198 | assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", ustSource.getPropertyValue(UstProviderPropertySource.UST_PROVIDER_NAME_PROPERTY_ID)); |
| 199 | assertEquals(String.valueOf(9379), ustSource.getPropertyValue(UstProviderPropertySource.UST_PROVIDER_PID_PROPERTY_ID)); |
| 200 | |
| 201 | // ------------------------------------------------------------------------ |
| 202 | // Verify Base Event Properties (adapter) |
| 203 | // ------------------------------------------------------------------------ |
| 204 | ITraceControlComponent[] events = ustProvider.getChildren(); |
| 205 | assertNotNull(events); |
| 206 | assertEquals(2, events.length); |
| 207 | |
| 208 | BaseEventComponent baseEventInfo = (BaseEventComponent) events[0]; |
| 209 | assertNotNull(baseEventInfo); |
| 210 | |
| 211 | adapter = baseEventInfo.getAdapter(IPropertySource.class); |
| 212 | assertNotNull(adapter); |
| 213 | assertTrue(adapter instanceof BaseEventPropertySource); |
| 214 | |
| 215 | BaseEventPropertySource baseSource = (BaseEventPropertySource)adapter; |
| 216 | assertNotNull(baseSource.getPropertyDescriptors()); |
| 217 | |
| 218 | assertEquals("ust_tests_hello:tptest_sighandler", baseSource.getPropertyValue(BaseEventPropertySource.BASE_EVENT_NAME_PROPERTY_ID)); |
| 219 | assertEquals(TraceEventType.TRACEPOINT.name(), baseSource.getPropertyValue(BaseEventPropertySource.BASE_EVENT_TYPE_PROPERTY_ID)); |
| 220 | assertEquals(TraceLogLevel.TRACE_DEBUG_MODULE.name(), baseSource.getPropertyValue(BaseEventPropertySource.BASE_EVENT_LOGLEVEL_PROPERTY_ID)); |
| 221 | |
| 222 | // ------------------------------------------------------------------------ |
| 223 | // Verify Session Properties (adapter) |
| 224 | // ------------------------------------------------------------------------ |
| 225 | ITraceControlComponent[] sessions = groups[1].getChildren(); |
| 226 | assertNotNull(sessions); |
| 227 | assertEquals(2, sessions.length); |
| 228 | |
| 229 | TraceSessionComponent session = (TraceSessionComponent)sessions[1]; |
| 230 | |
| 231 | adapter = session.getAdapter(IPropertySource.class); |
| 232 | assertNotNull(adapter); |
| 233 | assertTrue(adapter instanceof TraceSessionPropertySource); |
| 234 | |
| 235 | TraceSessionPropertySource sessionSource = (TraceSessionPropertySource)adapter; |
| 236 | assertNotNull(sessionSource.getPropertyDescriptors()); |
| 237 | |
| 238 | assertEquals("mysession", sessionSource.getPropertyValue(TraceSessionPropertySource.TRACE_SESSION_NAME_PROPERTY_ID)); |
| 239 | assertEquals("/home/user/lttng-traces/mysession-20120129-084256", sessionSource.getPropertyValue(TraceSessionPropertySource.TRACE_SESSION_PATH_PROPERTY_ID)); |
| 240 | assertEquals(TraceSessionState.ACTIVE.name(), sessionSource.getPropertyValue(TraceSessionPropertySource.TRACE_SESSION_STATE_PROPERTY_ID)); |
| 241 | |
| 242 | // ------------------------------------------------------------------------ |
| 243 | // Verify Domain Provider Properties (adapter) |
| 244 | // ------------------------------------------------------------------------ |
| 245 | ITraceControlComponent[] domains = session.getChildren(); |
| 246 | assertNotNull(domains); |
| 247 | assertEquals(2, domains.length); |
| 248 | |
| 249 | TraceDomainComponent domain = (TraceDomainComponent) domains[0]; |
| 250 | adapter = domain.getAdapter(IPropertySource.class); |
| 251 | assertNotNull(adapter); |
| 252 | assertTrue(adapter instanceof TraceDomainPropertySource); |
| 253 | |
| 254 | TraceDomainPropertySource domainSource = (TraceDomainPropertySource)adapter; |
| 255 | assertNotNull(domainSource.getPropertyDescriptors()); |
| 256 | |
| 257 | assertEquals("Kernel", domainSource.getPropertyValue(TraceDomainPropertySource.TRACE_DOMAIN_NAME_PROPERTY_ID)); |
| 258 | |
| 259 | ITraceControlComponent[] channels = domains[0].getChildren(); |
| 260 | assertNotNull(channels); |
| 261 | assertEquals(2, channels.length); |
| 262 | |
| 263 | // ------------------------------------------------------------------------ |
| 264 | // Verify Channel Properties (adapter) |
| 265 | // ------------------------------------------------------------------------ |
| 266 | assertTrue(channels[0] instanceof TraceChannelComponent); |
| 267 | TraceChannelComponent channel = (TraceChannelComponent) channels[0]; |
| 268 | |
| 269 | adapter = channel.getAdapter(IPropertySource.class); |
| 270 | assertNotNull(adapter); |
| 271 | assertTrue(adapter instanceof TraceChannelPropertySource); |
| 272 | |
| 273 | TraceChannelPropertySource channelSource = (TraceChannelPropertySource)adapter; |
| 274 | assertNotNull(channelSource.getPropertyDescriptors()); |
| 275 | |
| 276 | assertEquals("channel0", channelSource.getPropertyValue(TraceChannelPropertySource.TRACE_CHANNEL_NAME_PROPERTY_ID)); |
| 277 | assertEquals(String.valueOf(4), channelSource.getPropertyValue(TraceChannelPropertySource.TRACE_CHANNEL_NO_SUBBUFFERS_PROPERTY_ID)); |
| 278 | assertEquals(TraceEnablement.ENABLED.name(), channelSource.getPropertyValue(TraceChannelPropertySource.TRACE_CHANNEL_STATE_PROPERTY_ID)); |
| 279 | assertEquals(String.valueOf(false), channelSource.getPropertyValue(TraceChannelPropertySource.TRACE_CHANNEL_OVERWRITE_MODE_PROPERTY_ID)); |
| 280 | assertEquals("splice()", channelSource.getPropertyValue(TraceChannelPropertySource.TRACE_CHANNEL_OUTPUT_TYPE_PROPERTY_ID)); |
| 281 | assertEquals(String.valueOf(200), channelSource.getPropertyValue(TraceChannelPropertySource.TRACE_CHANNEL_READ_TIMER_PROPERTY_ID)); |
| 282 | assertEquals(String.valueOf(262144), channelSource.getPropertyValue(TraceChannelPropertySource.TRACE_CHANNEL_SUBBUFFER_SIZE_PROPERTY_ID)); |
| 283 | assertEquals(String.valueOf(0), channelSource.getPropertyValue(TraceChannelPropertySource.TRACE_CHANNEL_SWITCH_TIMER_PROPERTY_ID)); |
| 284 | |
| 285 | // ------------------------------------------------------------------------ |
| 286 | // Verify Event Properties (adapter) |
| 287 | // ------------------------------------------------------------------------ |
| 288 | ITraceControlComponent[] channel0Events = channel.getChildren(); |
| 289 | assertNotNull(channel0Events); |
| 290 | assertEquals(5, channel0Events.length); |
| 291 | assertTrue(channel0Events[0] instanceof TraceEventComponent); |
| 292 | |
| 293 | TraceEventComponent event = (TraceEventComponent) channel0Events[0]; |
| 294 | |
| 295 | adapter = event.getAdapter(IPropertySource.class); |
| 296 | assertNotNull(adapter); |
| 297 | assertTrue(adapter instanceof TraceEventPropertySource); |
| 298 | |
| 299 | TraceEventPropertySource eventSource = (TraceEventPropertySource)adapter; |
| 300 | assertNotNull(eventSource.getPropertyDescriptors()); |
| 301 | |
| 302 | assertEquals("block_rq_remap", eventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_NAME_PROPERTY_ID)); |
| 303 | assertEquals(TraceLogLevel.TRACE_EMERG.name(), eventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_LOGLEVEL_PROPERTY_ID)); |
| 304 | assertEquals(TraceEventType.TRACEPOINT.name(), eventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_TYPE_PROPERTY_ID)); |
| 305 | assertEquals(TraceEnablement.ENABLED.name(), eventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_STATE_PROPERTY_ID)); |
| 306 | |
| 307 | // ------------------------------------------------------------------------ |
| 308 | // Verify Probe Event Properties (adapter) |
| 309 | // ------------------------------------------------------------------------ |
| 310 | assertTrue(channel0Events[2] instanceof TraceProbeEventComponent); |
| 311 | |
| 312 | TraceProbeEventComponent probeEvent = (TraceProbeEventComponent) channel0Events[2]; |
| 313 | |
| 314 | adapter = probeEvent.getAdapter(IPropertySource.class); |
| 315 | assertNotNull(adapter); |
| 316 | assertTrue(adapter instanceof TraceProbeEventPropertySource); |
| 317 | |
| 318 | TraceProbeEventPropertySource probeEventSource = (TraceProbeEventPropertySource)adapter; |
| 319 | assertNotNull(probeEventSource.getPropertyDescriptors()); |
| 320 | assertEquals(4, probeEventSource.getPropertyDescriptors().length); |
| 321 | |
| 322 | assertEquals("myevent2", probeEventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_NAME_PROPERTY_ID)); |
| 323 | assertEquals(TraceEventType.PROBE.name(), probeEventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_TYPE_PROPERTY_ID)); |
| 324 | assertEquals(TraceEnablement.ENABLED.name(), probeEventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_STATE_PROPERTY_ID)); |
| 325 | assertEquals("0xc0101340", probeEventSource.getPropertyValue(TraceProbeEventPropertySource.TRACE_EVENT_PROBE_ADDRESS_PROPERTY_ID)); |
| 326 | |
| 327 | assertTrue(channel0Events[3] instanceof TraceProbeEventComponent); |
| 328 | |
| 329 | probeEvent = (TraceProbeEventComponent) channel0Events[3]; |
| 330 | |
| 331 | adapter = probeEvent.getAdapter(IPropertySource.class); |
| 332 | assertNotNull(adapter); |
| 333 | assertTrue(adapter instanceof TraceProbeEventPropertySource); |
| 334 | |
| 335 | probeEventSource = (TraceProbeEventPropertySource)adapter; |
| 336 | assertNotNull(probeEventSource.getPropertyDescriptors()); |
| 337 | assertEquals(5, probeEventSource.getPropertyDescriptors().length); |
| 338 | |
| 339 | assertEquals("myevent0", probeEventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_NAME_PROPERTY_ID)); |
| 340 | assertEquals(TraceEventType.PROBE.name(), probeEventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_TYPE_PROPERTY_ID)); |
| 341 | assertEquals(TraceEnablement.ENABLED.name(), probeEventSource.getPropertyValue(TraceEventPropertySource.TRACE_EVENT_STATE_PROPERTY_ID)); |
| 342 | assertEquals("0x0", probeEventSource.getPropertyValue(TraceProbeEventPropertySource.TRACE_EVENT_PROBE_OFFSET_PROPERTY_ID)); |
| 343 | assertEquals("init_post", probeEventSource.getPropertyValue(TraceProbeEventPropertySource.TRACE_EVENT_PROBE_SYMBOL_PROPERTY_ID)); |
| 344 | |
| 345 | //------------------------------------------------------------------------- |
| 346 | // Delete node |
| 347 | //------------------------------------------------------------------------- |
| 348 | node.disconnect(); |
| 349 | node.getParent().removeChild(node); |
| 350 | } |
| 351 | } |