1 package org
.eclipse
.linuxtools
.lttng
.tests
.event
;
3 import junit
.framework
.TestCase
;
5 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
6 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventContent
;
7 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventReference
;
8 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventType
;
9 import org
.eclipse
.linuxtools
.lttng
.event
.LttngTimestamp
;
10 import org
.eclipse
.linuxtools
.lttng
.jni
.JniEvent
;
11 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTextTrace
;
12 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
13 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceContext
;
16 Functions tested here :
17 public LttngEvent(LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent)
18 public LttngEvent(LttngEvent oldEvent)
20 public String getChannelName()
21 public long getCpuId()
22 public String getMarkerName()
23 public LttngEventType getType()
24 public LttngEventContent getContent()
26 public void updateJniEventReference(JniEvent newJniEventReference)
27 public void setContent(LttngEventContent newContent)
28 public void setType(LttngEventType newType)
30 public JniEvent convertEventTmfToJni()
32 public String toString()
35 public class LttngEventTest
extends TestCase
{
36 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
37 private final static boolean skipIndexing
=true;
39 private final static long eventTimestamp
= 13589759412127L;
40 private final static String eventSource
= "Kernel Core";
41 private final static String eventType
= "metadata/0/core_marker_id";
42 private final static String eventChannel
= "metadata";
43 private final static long eventCpu
= 0;
44 private final static String eventMarker
= "core_marker_id";
45 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 ";
46 private final static String eventReference
= eventChannel
+ "_" + eventCpu
;
49 private LttngEvent
prepareToTest() {
50 LttngEvent tmpEvent
= null;
53 LTTngTextTrace tmpStream
= new LTTngTextTrace(tracepath1
, skipIndexing
);
54 tmpEvent
= (LttngEvent
)tmpStream
.getNextEvent(new TmfTraceContext(0, new LttngTimestamp(0L), 0) );
57 System
.out
.println("ERROR : Could not open " + tracepath1
);
63 public void testConstructors() {
64 LttngEvent testEvent
= null;
65 @SuppressWarnings("unused")
66 LttngEvent testAnotherEvent
= null;
67 LttngTimestamp testTime
= null;
68 TmfEventSource testSource
= null;
69 LttngEventType testType
= null;
70 LttngEventContent testContent
= null;
71 LttngEventReference testReference
= null;
72 JniEvent testJniEvent
= null;
73 String
[] testMarkerFields
= null;
75 // This need to work if we want to perform tests
77 // In order to test LttngEvent, we need all these constructors/functions to work.
78 // Make sure to run their unit tests first!
79 testMarkerFields
= new String
[1];
81 testTime
= new LttngTimestamp(0L);
82 testSource
= new TmfEventSource("test");
83 testType
= new LttngEventType("test", 0L, "test", testMarkerFields
);
84 testContent
= new LttngEventContent(testEvent
);
85 testReference
= new LttngEventReference("test", "test");
88 fail("Cannot allocate an EventStream, junit failed!");
91 // Test constructor with correct information
93 testEvent
= new LttngEvent( testTime
, testSource
, testType
, testContent
, testReference
, testJniEvent
);
96 fail("Construction with correct information failed!");
99 // Test about copy constructor
100 // Passing a null to copy constructor should fail
102 testAnotherEvent
= new LttngEvent(null);
103 fail("Copy constructor with null old event should fail!");
105 catch( Exception e
) {
108 // Copy constructor used properly
109 testEvent
= prepareToTest();
111 testAnotherEvent
= new LttngEvent(testEvent
);
113 catch( Exception e
) {
114 fail("Correct utilisation of copy constructor failed!");
119 public void testGetter() {
120 LttngEvent testEvent
= prepareToTest();
122 // These will test TMF functions but since we are expecting it to work...
123 assertEquals("Timestamp not what expected!",eventTimestamp
,testEvent
.getTimestamp().getValue());
124 assertEquals("Source not what expected!",eventSource
,testEvent
.getSource().getSourceId());
125 assertEquals("Reference not what expected!",eventReference
,((String
)testEvent
.getReference().toString()) );
127 // These should be overridden functions
128 assertEquals("Type not what expected!",eventType
,testEvent
.getType().getTypeId());
129 assertEquals("Channel not what expected!",eventChannel
,testEvent
.getChannelName());
130 assertEquals("CpuId not what expected!",eventCpu
,testEvent
.getCpuId());
131 assertEquals("Marker not what expected!",eventMarker
,testEvent
.getMarkerName());
132 assertEquals("Content not what expected!",eventContent
,testEvent
.getContent().toString());
135 public void testSetter() {
136 LttngEvent testEvent
= prepareToTest();
138 LttngEventType testType
= null;
139 LttngEventContent testContent
= null;
140 JniEvent testJniEvent
= null;
142 String
[] testMarkerFields
= new String
[1];
143 testType
= new LttngEventType("test", 0L, "test", testMarkerFields
);
144 testContent
= new LttngEventContent(testEvent
);
148 // This won't do anything good on a text trace
149 testEvent
.updateJniEventReference(testJniEvent
);
151 testEvent
.setContent(testContent
);
152 testEvent
.setType(testType
);
154 catch( Exception e
) {
155 fail("Setters raised an exception!");
158 assertSame("SetType failed : type not what expected!",testType
,testEvent
.getType());
159 assertSame("SetContent failed : content not what expected!",testContent
,testEvent
.getContent());
164 public void testConversion() {
165 @SuppressWarnings("unused")
166 JniEvent tmpJniEvent
= null;
167 LttngEvent testEvent
= null;
169 testEvent
= prepareToTest();
172 tmpJniEvent
= testEvent
.convertEventTmfToJni();
174 catch( Exception e
) {
175 fail("Conversion raised an exception!");
179 // This test can't work with a text trace, commented for now
180 //assertNotSame("Conversion returned a null event!",null, tmpJniEvent );
183 public void testToString() {
184 LttngEvent tmpEvent
= prepareToTest();
186 // Just make sure toString() does not return null or the java reference
187 assertNotSame("toString returned null",null, tmpEvent
.toString() );
188 assertNotSame("toString is not overridded!", tmpEvent
.getClass().getName() + '@' + Integer
.toHexString(tmpEvent
.hashCode()), tmpEvent
.toString() );