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
.TmfContext
;
20 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfLocation
;
23 Functions tested here :
24 public LttngEvent(LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent)
25 public LttngEvent(LttngEvent oldEvent)
27 public String getChannelName()
28 public long getCpuId()
29 public String getMarkerName()
30 public LttngEventType getType()
31 public LttngEventContent getContent()
33 public void updateJniEventReference(JniEvent newJniEventReference)
34 public void setContent(LttngEventContent newContent)
35 public void setType(LttngEventType newType)
37 public JniEvent convertEventTmfToJni()
39 public String toString()
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 @SuppressWarnings("unused")
94 LttngEvent testAnotherEvent
= null;
95 LttngTimestamp testTime
= null;
96 TmfEventSource testSource
= null;
97 LttngEventType testType
= null;
98 LttngEventContent testContent
= null;
99 LttngEventReference testReference
= null;
100 JniEvent testJniEvent
= null;
101 String
[] testMarkerFields
= null;
103 // This need to work if we want to perform tests
105 // In order to test LttngEvent, we need all these constructors/functions to work.
106 // Make sure to run their unit tests first!
107 testMarkerFields
= new String
[1];
109 testTime
= new LttngTimestamp(0L);
110 testSource
= new TmfEventSource("test");
111 testType
= new LttngEventType("test", 0L, "test", testMarkerFields
);
112 testContent
= new LttngEventContent(testEvent
);
113 testReference
= new LttngEventReference("test", "test");
115 catch( Exception e
) {
116 fail("Cannot allocate an EventStream, junit failed!");
119 // Test constructor with correct information
121 testEvent
= new LttngEvent( testTime
, testSource
, testType
, testContent
, testReference
, testJniEvent
);
123 catch( Exception e
) {
124 fail("Construction with correct information failed!");
127 // Test about copy constructor
128 // Passing a null to copy constructor should fail
130 testAnotherEvent
= new LttngEvent(null);
131 fail("Copy constructor with null old event should fail!");
133 catch( Exception e
) {
136 // Copy constructor used properly
137 testEvent
= prepareToTest();
139 testAnotherEvent
= new LttngEvent(testEvent
);
141 catch( Exception e
) {
142 fail("Correct utilisation of copy constructor failed!");
147 public void testGetter() {
148 LttngEvent testEvent
= prepareToTest();
150 // These will test TMF functions but since we are expecting it to work...
151 assertEquals("Timestamp not what expected!",eventTimestamp
,testEvent
.getTimestamp().getValue());
152 assertEquals("Source not what expected!",eventSource
,testEvent
.getSource().getSourceId());
153 assertEquals("Reference not what expected!",eventReference
,((String
)testEvent
.getReference().toString()) );
155 // These should be overridden functions
156 assertEquals("Type not what expected!",eventType
,testEvent
.getType().getTypeId());
157 assertEquals("Channel not what expected!",eventChannel
,testEvent
.getChannelName());
158 assertEquals("CpuId not what expected!",eventCpu
,testEvent
.getCpuId());
159 assertEquals("Marker not what expected!",eventMarker
,testEvent
.getMarkerName());
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 LttngEvent testEvent
= prepareToTest();
172 LttngEventType testType
= null;
173 LttngEventContent testContent
= null;
174 JniEvent testJniEvent
= null;
176 String
[] testMarkerFields
= new String
[1];
177 testType
= new LttngEventType("test", 0L, "test", 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( 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( 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 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() );