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
.lttng
.core
.event
.LttngEvent
;
11 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngEventContent
;
12 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngEventReference
;
13 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngEventType
;
14 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngTimestamp
;
15 import org
.eclipse
.linuxtools
.lttng
.core
.tests
.LTTngCoreTestPlugin
;
16 import org
.eclipse
.linuxtools
.lttng
.core
.trace
.LTTngTextTrace
;
17 import org
.eclipse
.linuxtools
.lttng
.core
.trace
.LTTngTrace
;
18 import org
.eclipse
.linuxtools
.lttng
.jni
.JniEvent
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventSource
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
24 Functions tested here :
25 public LttngEvent(LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent)
26 public LttngEvent(LttngEvent oldEvent)
28 public String getChannelName()
29 public long getCpuId()
30 public String getMarkerName()
31 public LttngEventType getType()
32 public LttngEventContent getContent()
34 public void updateJniEventReference(JniEvent newJniEventReference)
35 public void setContent(LttngEventContent newContent)
36 public void setType(LttngEventType newType)
38 public JniEvent convertEventTmfToJni()
40 public String toString()
43 @SuppressWarnings("nls")
44 public class LttngEventTest
extends TestCase
{
45 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
46 private final static boolean skipIndexing
=true;
48 private final static long eventTimestamp
= 13589759412128L;
49 private final static String eventSource
= "Kernel Core";
50 private final static String eventType
= "metadata/0/core_marker_id";
51 private final static String eventChannel
= "metadata";
52 private final static long eventCpu
= 0;
53 private final static String eventMarker
= "core_marker_id";
54 // 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 ";
55 private final static String eventReference
= eventChannel
+ "_" + eventCpu
;
58 private static LTTngTextTrace testStream
= null;
59 private LTTngTextTrace
initializeEventStream() {
60 if (testStream
== null) {
62 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
63 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
64 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath(), skipIndexing
);
65 testStream
= tmpStream
;
68 System
.out
.println("ERROR : Could not open " + tracepath1
);
73 testStream
.seekEvent(0);
79 private LttngEvent
prepareToTest() {
80 LttngEvent tmpEvent
= null;
83 LTTngTextTrace tmpStream
= initializeEventStream();
84 tmpEvent
= (LttngEvent
)tmpStream
.getNextEvent(new TmfContext(new TmfLocation
<Long
>(0L), 0) );
87 System
.out
.println("ERROR : Could not open " + tracepath1
);
93 public void testConstructors() {
94 LttngEvent testEvent
= null;
95 LTTngTrace testTrace
= null;
96 @SuppressWarnings("unused")
97 LttngEvent testAnotherEvent
= null;
98 LttngTimestamp testTime
= null;
99 TmfEventSource testSource
= null;
100 LttngEventType testType
= null;
101 LttngEventContent testContent
= null;
102 LttngEventReference testReference
= null;
103 JniEvent testJniEvent
= null;
104 String
[] testMarkerFields
= null;
106 // This need to work if we want to perform tests
108 // In order to test LttngEvent, we need all these constructors/functions to work.
109 // Make sure to run their unit tests first!
110 testMarkerFields
= new String
[1];
112 testTime
= new LttngTimestamp(0L);
113 testSource
= new TmfEventSource("test");
114 testType
= new LttngEventType("test", 0L, "test", 0, testMarkerFields
);
115 testContent
= new LttngEventContent(testEvent
);
116 testReference
= new LttngEventReference("test", "test");
118 catch( Exception e
) {
119 fail("Cannot allocate an EventStream, junit failed!");
122 // Test constructor with correct information
124 testEvent
= new LttngEvent(testTrace
, testTime
, testSource
, testType
, testContent
, testReference
, testJniEvent
);
126 catch( Exception e
) {
127 fail("Construction with correct information failed!");
130 // Test about copy constructor
131 // Passing a null to copy constructor should fail
133 testAnotherEvent
= new LttngEvent(null);
134 fail("Copy constructor with null old event should fail!");
136 catch( Exception e
) {
139 // Copy constructor used properly
140 testEvent
= prepareToTest();
142 testAnotherEvent
= new LttngEvent(testEvent
);
144 catch( Exception e
) {
145 fail("Correct utilisation of copy constructor failed!");
150 public void testGetter() {
151 LttngEvent testEvent
= prepareToTest();
153 // These will test TMF functions but since we are expecting it to work...
154 assertEquals("Timestamp not what expected!",eventTimestamp
,testEvent
.getTimestamp().getValue());
155 assertEquals("Source not what expected!",eventSource
,testEvent
.getSource().getSourceId());
156 assertEquals("Reference not what expected!",eventReference
,((String
)testEvent
.getReference().toString()) );
158 // These should be overridden functions
159 assertEquals("Type not what expected!",eventType
,testEvent
.getType().getTypeId());
160 assertEquals("Channel not what expected!",eventChannel
,testEvent
.getChannelName());
161 assertEquals("CpuId not what expected!",eventCpu
,testEvent
.getCpuId());
162 assertEquals("Marker not what expected!",eventMarker
,testEvent
.getMarkerName());
164 // All events should have a parent
165 assertNotNull("Trace parent for this event is null!", testEvent
.getParentTrace() );
168 // Depending from the Java version because of the "hashcode()" on String.
169 // We can't really test that safetly
171 //assertEquals("Content not what expected!",eventContent,testEvent.getContent().toString());
172 assertNotSame("Content is null!", null,testEvent
.getContent());
175 public void testSetter() {
176 LttngEvent testEvent
= prepareToTest();
178 LttngEventType testType
= null;
179 LttngEventContent testContent
= null;
180 JniEvent testJniEvent
= null;
182 String
[] testMarkerFields
= new String
[1];
183 testType
= new LttngEventType("test", 0L, "test", 0, testMarkerFields
);
184 testContent
= new LttngEventContent(testEvent
);
188 // This won't do anything good on a text trace
189 testEvent
.updateJniEventReference(testJniEvent
);
191 testEvent
.setContent(testContent
);
192 testEvent
.setType(testType
);
194 catch( Exception e
) {
195 fail("Setters raised an exception!");
198 assertSame("SetType failed : type not what expected!",testType
,testEvent
.getType());
199 assertSame("SetContent failed : content not what expected!",testContent
,testEvent
.getContent());
204 public void testConversion() {
205 @SuppressWarnings("unused")
206 JniEvent tmpJniEvent
= null;
207 LttngEvent testEvent
= null;
209 testEvent
= prepareToTest();
212 tmpJniEvent
= testEvent
.convertEventTmfToJni();
214 catch( Exception e
) {
215 fail("Conversion raised an exception!");
219 // This test can't work with a text trace, commented for now
220 //assertNotSame("Conversion returned a null event!",null, tmpJniEvent );
223 public void testToString() {
224 LttngEvent tmpEvent
= prepareToTest();
226 // Just make sure toString() does not return null or the java reference
227 assertNotSame("toString returned null",null, tmpEvent
.toString() );
228 assertNotSame("toString is not overridded!", tmpEvent
.getClass().getName() + '@' + Integer
.toHexString(tmpEvent
.hashCode()), tmpEvent
.toString() );