1 package org
.eclipse
.linuxtools
.lttng
.core
.tests
.event
;
6 import junit
.framework
.TestCase
;
8 import org
.eclipse
.core
.runtime
.FileLocator
;
9 import org
.eclipse
.core
.runtime
.Path
;
10 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngEvent
;
11 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngEventContent
;
12 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngEventType
;
13 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngTimestamp
;
14 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.trace
.LTTngTextTrace
;
15 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.trace
.LTTngTrace
;
16 import org
.eclipse
.linuxtools
.lttng
.jni
.JniEvent
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
19 import org
.osgi
.framework
.FrameworkUtil
;
22 Functions tested here :
23 public LttngEvent(LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent)
24 public LttngEvent(LttngEvent oldEvent)
26 public String getChannelName()
27 public long getCpuId()
28 public String getMarkerName()
29 public LttngEventType getType()
30 public LttngEventContent getContent()
32 public void updateJniEventReference(JniEvent newJniEventReference)
33 public void setContent(LttngEventContent newContent)
34 public void setType(LttngEventType newType)
36 public JniEvent convertEventTmfToJni()
38 public String toString()
41 @SuppressWarnings("nls")
42 public class LttngEventTest
extends TestCase
{
43 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
44 private final static boolean skipIndexing
=true;
46 private final static long eventTimestamp
= 13589759412128L;
47 private final static String eventSource
= "Kernel Core";
48 private final static String eventType
= "metadata/0/core_marker_id";
49 private final static String eventChannel
= "metadata";
50 private final static long eventCpu
= 0;
51 private final static String eventMarker
= "core_marker_id";
52 // private final static String eventContent = "alignment:0 size_t:4 int:4 name:vm_map pointer:4 event_id:0 long:4 channel:vm_state ";
53 private final static String eventReference
= eventChannel
+ "_" + eventCpu
;
56 private static LTTngTextTrace testStream
= null;
57 private LTTngTextTrace
initializeEventStream() {
58 if (testStream
== null)
60 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(tracepath1
), null);
61 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
62 final LTTngTextTrace tmpStream
= new LTTngTextTrace(null, testfile
.getPath(), skipIndexing
);
63 testStream
= tmpStream
;
65 catch (final Exception e
) {
66 System
.out
.println("ERROR : Could not open " + tracepath1
);
70 testStream
.seekEvent(0);
75 private LttngEvent
prepareToTest() {
76 LttngEvent tmpEvent
= null;
79 final LTTngTextTrace tmpStream
= initializeEventStream();
80 tmpEvent
= (LttngEvent
)tmpStream
.getNextEvent(new TmfContext(new TmfLocation
<Long
>(0L), 0) );
82 catch (final Exception e
) {
83 System
.out
.println("ERROR : Could not open " + tracepath1
);
89 public void testConstructors() {
90 LttngEvent testEvent
= null;
91 final LTTngTrace testTrace
= null;
92 LttngTimestamp testTime
= null;
93 String testSource
= null;
94 LttngEventType testType
= null;
95 LttngEventContent testContent
= null;
96 String testReference
= null;
97 final JniEvent testJniEvent
= null;
98 String
[] testMarkerFields
= null;
100 // This need to work if we want to perform tests
102 // In order to test LttngEvent, we need all these constructors/functions to work.
103 // Make sure to run their unit tests first!
104 testMarkerFields
= new String
[] { "test" };
106 testTime
= new LttngTimestamp(0L);
108 testType
= new LttngEventType("test", 0L, "test", 0, testMarkerFields
);
109 testContent
= new LttngEventContent(testEvent
);
110 testReference
= "test";
112 catch( final Exception e
) {
113 fail("Cannot allocate an EventStream, junit failed!");
116 // Test constructor with correct information
118 testEvent
= new LttngEvent(testTrace
, testTime
, testSource
, testType
, testContent
, testReference
, testJniEvent
);
120 catch( final Exception e
) {
121 fail("Construction with correct information failed!");
124 // Test about copy constructor
125 // Passing a null to copy constructor should fail
127 new LttngEvent(null);
128 fail("Copy constructor with null old event should fail!");
130 catch( final Exception e
) {
133 // Copy constructor used properly
134 testEvent
= prepareToTest();
136 new LttngEvent(testEvent
);
138 catch( final Exception e
) {
139 fail("Correct utilisation of copy constructor failed!");
144 public void testGetter() {
145 final LttngEvent testEvent
= prepareToTest();
147 // These will test TMF functions but since we are expecting it to work...
148 assertEquals("Timestamp not what expected!",eventTimestamp
,testEvent
.getTimestamp().getValue());
149 assertEquals("Source not what expected!",eventSource
,testEvent
.getSource());
150 assertEquals("Reference not what expected!", eventReference
, testEvent
.getReference());
152 // These should be overridden functions
153 assertEquals("Type not what expected!",eventType
,testEvent
.getType().getName());
154 assertEquals("Channel not what expected!",eventChannel
,testEvent
.getChannelName());
155 assertEquals("CpuId not what expected!",eventCpu
,testEvent
.getCpuId());
156 assertEquals("Marker not what expected!",eventMarker
,testEvent
.getMarkerName());
158 // All events should have a parent
159 assertNotNull("Trace parent for this event is null!", testEvent
.getTrace() );
162 // Depending from the Java version because of the "hashcode()" on String.
163 // We can't really test that safetly
165 //assertEquals("Content not what expected!",eventContent,testEvent.getContent().toString());
166 assertNotSame("Content is null!", null,testEvent
.getContent());
169 public void testSetter() {
170 final LttngEvent testEvent
= prepareToTest();
172 LttngEventType testType
= null;
173 LttngEventContent testContent
= null;
174 final JniEvent testJniEvent
= null;
176 final String
[] testMarkerFields
= new String
[] { "test" };
177 testType
= new LttngEventType("test", 0L, "test", 0, testMarkerFields
);
178 testContent
= new LttngEventContent(testEvent
);
182 // This won't do anything good on a text trace
183 testEvent
.updateJniEventReference(testJniEvent
);
185 testEvent
.setContent(testContent
);
186 testEvent
.setType(testType
);
188 catch( final Exception e
) {
189 fail("Setters raised an exception!");
192 assertSame("SetType failed : type not what expected!",testType
,testEvent
.getType());
193 assertSame("SetContent failed : content not what expected!",testContent
,testEvent
.getContent());
198 public void testConversion() {
199 @SuppressWarnings("unused")
200 JniEvent tmpJniEvent
= null;
201 LttngEvent testEvent
= null;
203 testEvent
= prepareToTest();
206 tmpJniEvent
= testEvent
.convertEventTmfToJni();
208 catch( final Exception e
) {
209 fail("Conversion raised an exception!");
213 // This test can't work with a text trace, commented for now
214 //assertNotSame("Conversion returned a null event!",null, tmpJniEvent );
217 public void testToString() {
218 final LttngEvent tmpEvent
= prepareToTest();
220 // Just make sure toString() does not return null or the java reference
221 assertNotSame("toString returned null",null, tmpEvent
.toString() );
222 assertNotSame("toString is not overridded!", tmpEvent
.getClass().getName() + '@' + Integer
.toHexString(tmpEvent
.hashCode()), tmpEvent
.toString() );