1 package org
.eclipse
.linuxtools
.lttng
.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
.event
.LttngEvent
;
11 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventContent
;
12 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventReference
;
13 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventType
;
14 import org
.eclipse
.linuxtools
.lttng
.event
.LttngTimestamp
;
15 import org
.eclipse
.linuxtools
.lttng
.jni
.JniEvent
;
16 import org
.eclipse
.linuxtools
.lttng
.tests
.LTTngCoreTestPlugin
;
17 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTextTrace
;
18 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
19 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceContext
;
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 public class LttngEventTest
extends TestCase
{
42 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
43 private final static boolean skipIndexing
=true;
45 private final static long eventTimestamp
= 13589759412127L;
46 private final static String eventSource
= "Kernel Core";
47 private final static String eventType
= "metadata/0/core_marker_id";
48 private final static String eventChannel
= "metadata";
49 private final static long eventCpu
= 0;
50 private final static String eventMarker
= "core_marker_id";
51 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 ";
52 private final static String eventReference
= eventChannel
+ "_" + eventCpu
;
55 private static LTTngTextTrace testStream
= null;
56 private LTTngTextTrace
initializeEventStream() {
57 if (testStream
== null) {
59 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
60 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
61 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath(), skipIndexing
);
62 testStream
= tmpStream
;
65 System
.out
.println("ERROR : Could not open " + tracepath1
);
70 testStream
.seekEvent(0);
76 private LttngEvent
prepareToTest() {
77 LttngEvent tmpEvent
= null;
80 LTTngTextTrace tmpStream
= initializeEventStream();
81 tmpEvent
= (LttngEvent
)tmpStream
.getNextEvent(new TmfTraceContext(0, new LttngTimestamp(0L), 0) );
84 System
.out
.println("ERROR : Could not open " + tracepath1
);
90 public void testConstructors() {
91 LttngEvent testEvent
= null;
92 @SuppressWarnings("unused")
93 LttngEvent testAnotherEvent
= null;
94 LttngTimestamp testTime
= null;
95 TmfEventSource testSource
= null;
96 LttngEventType testType
= null;
97 LttngEventContent testContent
= null;
98 LttngEventReference testReference
= null;
99 JniEvent testJniEvent
= null;
100 String
[] testMarkerFields
= null;
102 // This need to work if we want to perform tests
104 // In order to test LttngEvent, we need all these constructors/functions to work.
105 // Make sure to run their unit tests first!
106 testMarkerFields
= new String
[1];
108 testTime
= new LttngTimestamp(0L);
109 testSource
= new TmfEventSource("test");
110 testType
= new LttngEventType("test", 0L, "test", testMarkerFields
);
111 testContent
= new LttngEventContent(testEvent
);
112 testReference
= new LttngEventReference("test", "test");
114 catch( Exception e
) {
115 fail("Cannot allocate an EventStream, junit failed!");
118 // Test constructor with correct information
120 testEvent
= new LttngEvent( testTime
, testSource
, testType
, testContent
, testReference
, testJniEvent
);
122 catch( Exception e
) {
123 fail("Construction with correct information failed!");
126 // Test about copy constructor
127 // Passing a null to copy constructor should fail
129 testAnotherEvent
= new LttngEvent(null);
130 fail("Copy constructor with null old event should fail!");
132 catch( Exception e
) {
135 // Copy constructor used properly
136 testEvent
= prepareToTest();
138 testAnotherEvent
= new LttngEvent(testEvent
);
140 catch( Exception e
) {
141 fail("Correct utilisation of copy constructor failed!");
146 public void testGetter() {
147 LttngEvent testEvent
= prepareToTest();
149 // These will test TMF functions but since we are expecting it to work...
150 assertEquals("Timestamp not what expected!",eventTimestamp
,testEvent
.getTimestamp().getValue());
151 assertEquals("Source not what expected!",eventSource
,testEvent
.getSource().getSourceId());
152 assertEquals("Reference not what expected!",eventReference
,((String
)testEvent
.getReference().toString()) );
154 // These should be overridden functions
155 assertEquals("Type not what expected!",eventType
,testEvent
.getType().getTypeId());
156 assertEquals("Channel not what expected!",eventChannel
,testEvent
.getChannelName());
157 assertEquals("CpuId not what expected!",eventCpu
,testEvent
.getCpuId());
158 assertEquals("Marker not what expected!",eventMarker
,testEvent
.getMarkerName());
161 // Depending from the Java version because of the "hashcode()" on String.
162 // We can't really test that safetly
164 //assertEquals("Content not what expected!",eventContent,testEvent.getContent().toString());
165 assertNotSame("Content is null!", null,testEvent
.getContent());
168 public void testSetter() {
169 LttngEvent testEvent
= prepareToTest();
171 LttngEventType testType
= null;
172 LttngEventContent testContent
= null;
173 JniEvent testJniEvent
= null;
175 String
[] testMarkerFields
= new String
[1];
176 testType
= new LttngEventType("test", 0L, "test", testMarkerFields
);
177 testContent
= new LttngEventContent(testEvent
);
181 // This won't do anything good on a text trace
182 testEvent
.updateJniEventReference(testJniEvent
);
184 testEvent
.setContent(testContent
);
185 testEvent
.setType(testType
);
187 catch( Exception e
) {
188 fail("Setters raised an exception!");
191 assertSame("SetType failed : type not what expected!",testType
,testEvent
.getType());
192 assertSame("SetContent failed : content not what expected!",testContent
,testEvent
.getContent());
197 public void testConversion() {
198 @SuppressWarnings("unused")
199 JniEvent tmpJniEvent
= null;
200 LttngEvent testEvent
= null;
202 testEvent
= prepareToTest();
205 tmpJniEvent
= testEvent
.convertEventTmfToJni();
207 catch( Exception e
) {
208 fail("Conversion raised an exception!");
212 // This test can't work with a text trace, commented for now
213 //assertNotSame("Conversion returned a null event!",null, tmpJniEvent );
216 public void testToString() {
217 LttngEvent tmpEvent
= prepareToTest();
219 // Just make sure toString() does not return null or the java reference
220 assertNotSame("toString returned null",null, tmpEvent
.toString() );
221 assertNotSame("toString is not overridded!", tmpEvent
.getClass().getName() + '@' + Integer
.toHexString(tmpEvent
.hashCode()), tmpEvent
.toString() );