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
.LttngEventType
;
13 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngTimestamp
;
14 import org
.eclipse
.linuxtools
.lttng
.core
.tests
.LTTngCoreTestPlugin
;
15 import org
.eclipse
.linuxtools
.lttng
.core
.trace
.LTTngTextTrace
;
16 import org
.eclipse
.linuxtools
.lttng
.core
.trace
.LTTngTrace
;
17 import org
.eclipse
.linuxtools
.lttng
.jni
.JniEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
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 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
61 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
62 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath(), skipIndexing
);
63 testStream
= tmpStream
;
66 System
.out
.println("ERROR : Could not open " + tracepath1
);
71 testStream
.seekEvent(0);
77 private LttngEvent
prepareToTest() {
78 LttngEvent tmpEvent
= null;
81 LTTngTextTrace tmpStream
= initializeEventStream();
82 tmpEvent
= (LttngEvent
)tmpStream
.getNextEvent(new TmfContext(new TmfLocation
<Long
>(0L), 0) );
85 System
.out
.println("ERROR : Could not open " + tracepath1
);
91 public void testConstructors() {
92 LttngEvent testEvent
= null;
93 LTTngTrace testTrace
= null;
94 @SuppressWarnings("unused")
95 LttngEvent testAnotherEvent
= null;
96 LttngTimestamp testTime
= null;
97 String testSource
= null;
98 LttngEventType testType
= null;
99 LttngEventContent testContent
= null;
100 String testReference
= null;
101 JniEvent testJniEvent
= null;
102 String
[] testMarkerFields
= null;
104 // This need to work if we want to perform tests
106 // In order to test LttngEvent, we need all these constructors/functions to work.
107 // Make sure to run their unit tests first!
108 testMarkerFields
= new String
[] { "test" };
110 testTime
= new LttngTimestamp(0L);
112 testType
= new LttngEventType("test", 0L, "test", 0, testMarkerFields
);
113 testContent
= new LttngEventContent(testEvent
);
114 testReference
= "test";
116 catch( Exception e
) {
117 fail("Cannot allocate an EventStream, junit failed!");
120 // Test constructor with correct information
122 testEvent
= new LttngEvent(testTrace
, testTime
, testSource
, testType
, testContent
, testReference
, testJniEvent
);
124 catch( Exception e
) {
125 fail("Construction with correct information failed!");
128 // Test about copy constructor
129 // Passing a null to copy constructor should fail
131 testAnotherEvent
= new LttngEvent(null);
132 fail("Copy constructor with null old event should fail!");
134 catch( Exception e
) {
137 // Copy constructor used properly
138 testEvent
= prepareToTest();
140 testAnotherEvent
= new LttngEvent(testEvent
);
142 catch( Exception e
) {
143 fail("Correct utilisation of copy constructor failed!");
148 public void testGetter() {
149 LttngEvent testEvent
= prepareToTest();
151 // These will test TMF functions but since we are expecting it to work...
152 assertEquals("Timestamp not what expected!",eventTimestamp
,testEvent
.getTimestamp().getValue());
153 assertEquals("Source not what expected!",eventSource
,testEvent
.getSource());
154 assertEquals("Reference not what expected!", eventReference
, testEvent
.getReference());
156 // These should be overridden functions
157 assertEquals("Type not what expected!",eventType
,testEvent
.getType().getName());
158 assertEquals("Channel not what expected!",eventChannel
,testEvent
.getChannelName());
159 assertEquals("CpuId not what expected!",eventCpu
,testEvent
.getCpuId());
160 assertEquals("Marker not what expected!",eventMarker
,testEvent
.getMarkerName());
162 // All events should have a parent
163 assertNotNull("Trace parent for this event is null!", testEvent
.getTrace() );
166 // Depending from the Java version because of the "hashcode()" on String.
167 // We can't really test that safetly
169 //assertEquals("Content not what expected!",eventContent,testEvent.getContent().toString());
170 assertNotSame("Content is null!", null,testEvent
.getContent());
173 public void testSetter() {
174 LttngEvent testEvent
= prepareToTest();
176 LttngEventType testType
= null;
177 LttngEventContent testContent
= null;
178 JniEvent testJniEvent
= null;
180 String
[] testMarkerFields
= new String
[] { "test" };
181 testType
= new LttngEventType("test", 0L, "test", 0, testMarkerFields
);
182 testContent
= new LttngEventContent(testEvent
);
186 // This won't do anything good on a text trace
187 testEvent
.updateJniEventReference(testJniEvent
);
189 testEvent
.setContent(testContent
);
190 testEvent
.setType(testType
);
192 catch( Exception e
) {
193 fail("Setters raised an exception!");
196 assertSame("SetType failed : type not what expected!",testType
,testEvent
.getType());
197 assertSame("SetContent failed : content not what expected!",testContent
,testEvent
.getContent());
202 public void testConversion() {
203 @SuppressWarnings("unused")
204 JniEvent tmpJniEvent
= null;
205 LttngEvent testEvent
= null;
207 testEvent
= prepareToTest();
210 tmpJniEvent
= testEvent
.convertEventTmfToJni();
212 catch( Exception e
) {
213 fail("Conversion raised an exception!");
217 // This test can't work with a text trace, commented for now
218 //assertNotSame("Conversion returned a null event!",null, tmpJniEvent );
221 public void testToString() {
222 LttngEvent tmpEvent
= prepareToTest();
224 // Just make sure toString() does not return null or the java reference
225 assertNotSame("toString returned null",null, tmpEvent
.toString() );
226 assertNotSame("toString is not overridded!", tmpEvent
.getClass().getName() + '@' + Integer
.toHexString(tmpEvent
.hashCode()), tmpEvent
.toString() );