1 package org
.eclipse
.linuxtools
.lttng
.event
;
3 import org
.eclipse
.linuxtools
.lttng
.jni
.JniEvent
;
4 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTrace
;
5 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
6 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceContext
;
7 import junit
.framework
.TestCase
;
10 Functions tested here :
11 public LttngEvent(LttngTimestamp timestamp, LttngEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent)
12 public LttngEvent(LttngEvent oldEvent)
13 public String getChannelName()
14 public long getCpuId()
15 public String getMarkerName()
16 public JniEvent convertEventTmfToJni()
17 public String toString()
21 public class LttngEventTest
extends TestCase
{
22 private final static boolean skipIndexing
=true;
23 private final static boolean waitForCompletion
=true;
24 private final static String tracepath1
="traceset/trace-618339events-1293lost-1cpu";
26 private final static long eventTimestamp
= 952088954601L;
27 private final static String eventSource
= "Kernel Core";
28 private final static String eventType
= "metadata/0/core_marker_id";
29 private final static String eventChannel
= "metadata";
30 private final static long eventCpu
= 0 ;
31 private final static String eventMarker
= "core_marker_id";
32 private final static String eventContent
= "alignment:0 int:4 size_t:4 name:vm_map event_id:0 pointer:4 long:4 channel:vm_state ";
33 private final static String eventReference
= tracepath1
;
35 private LttngEvent
prepareToTest() {
36 LttngEvent tmpEvent
= null;
38 // This trace should be valid
40 LTTngTrace tmpStream
= new LTTngTrace(tracepath1
, waitForCompletion
, skipIndexing
);
41 tmpEvent
= (LttngEvent
)tmpStream
.parseEvent(new TmfTraceContext(null, null, 0) );
44 System
.out
.println("ERROR : Could not open " + tracepath1
);
50 public void testConstructors() {
52 LTTngTrace testStream1
= null;
53 LttngEvent testEvent
= null;
54 @SuppressWarnings("unused")
55 LttngEvent testAnotherEvent
= null;
56 LttngTimestamp testTime
= null;
57 TmfEventSource testSource
= null;
58 LttngEventType testType
= null;
59 LttngEventContent testContent
= null;
60 LttngEventReference testReference
= null;
61 JniEvent testJniEvent
= null;
62 String
[] testMarkerFields
= null;
64 // This need to work if we want to perform tests
66 // In order to test LttngEvent, we need all these constructors/functions to work.
67 // Make sure to run their unit tests first!
68 testMarkerFields
= new String
[1];
69 testStream1
= new LTTngTrace(tracepath1
, waitForCompletion
, skipIndexing
);
71 testTime
= new LttngTimestamp(0L);
72 testSource
= new TmfEventSource("test");
73 testType
= new LttngEventType("test", 0L, "test", testMarkerFields
);
74 testContent
= new LttngEventContent(testEvent
);
75 testReference
= new LttngEventReference("test", "test");
76 testJniEvent
= testStream1
.getCurrentJniTrace().findNextEvent();
79 fail("Cannot allocate an EventStream, junit failed!");
84 // Test with null timestamp
86 testEvent
= new LttngEvent( null, testSource
, testType
, testContent
, testReference
, testJniEvent
);
87 fail("Construction with null timestamp should fail!");
92 // Test with null source
94 testEvent
= new LttngEvent( testTime
, null, testType
, testContent
, testReference
, testJniEvent
);
95 fail("Construction with null source should fail!");
100 // Test with null type
102 testEvent
= new LttngEvent( testTime
, testSource
, null, testContent
, testReference
, testJniEvent
);
103 fail("Construction with null type should fail!");
105 catch( Exception e
) {
108 // Test with null content
110 testEvent
= new LttngEvent( testTime
, testSource
, testType
, null, testReference
, testJniEvent
);
111 fail("Construction with null content should fail!");
113 catch( Exception e
) {
116 // Test with null reference
118 testEvent
= new LttngEvent( testTime
, testSource
, testType
, testContent
, null, testJniEvent
);
119 fail("Construction with null reference should fail!");
121 catch( Exception e
) {
124 // Test with null jni Event
126 testEvent
= new LttngEvent( testTime
, testSource
, testType
, testContent
, testReference
, null);
127 fail("Construction with null jniEvent should fail!");
129 catch( Exception e
) {
132 // Finally, test constructor with correct information
134 testEvent
= new LttngEvent( testTime
, testSource
, testType
, testContent
, testReference
, testJniEvent
);
136 catch( Exception e
) {
137 fail("Construction with correct information failed!");
140 // Test about copy constructor
142 // Pass a null to copy constructor
144 testAnotherEvent
= new LttngEvent(null);
145 fail("Copy constructor with null old event should fail!");
147 catch( Exception e
) {
150 // Copy constructor used properly
151 testEvent
= prepareToTest();
153 testAnotherEvent
= new LttngEvent(testEvent
);
155 catch( Exception e
) {
156 fail("Correct utilisation of copy constructor failed!");
161 public void testGetter() {
162 LttngEvent testEvent
= prepareToTest();
164 // Some of these will test TMF functions but since we are expecting it to work...
165 assertEquals("Timestamp not what expected!",eventTimestamp
,testEvent
.getTimestamp().getValue());
166 assertEquals("Source not what expected!",eventSource
,testEvent
.getSource().getSourceId());
167 assertEquals("Type not what expected!",eventType
,testEvent
.getType().getTypeId());
168 assertEquals("Channel not what expected!",eventChannel
,testEvent
.getChannelName());
169 assertEquals("CpuId not what expected!",eventCpu
,testEvent
.getCpuId());
170 assertEquals("Marker not what expected!",eventMarker
,testEvent
.getMarkerName());
171 assertEquals("Content not what expected!",eventContent
,testEvent
.getContent().getContent());
172 assertTrue("Reference not what expected!",((String
)testEvent
.getReference().getReference()).contains(eventReference
) );
175 public void testConversion() {
176 JniEvent tmpJniEvent
= null;
177 LttngEvent testEvent
= null;
180 // Copy constructor used properly
181 testEvent
= prepareToTest();
183 tmpJniEvent
= testEvent
.convertEventTmfToJni();
185 catch( Exception e
) {
186 fail("Conversion raised an exception!");
189 assertNotSame("Conversion returned a null event!",null, tmpJniEvent
);
193 public void testToString() {
194 LttngEvent tmpEvent
= prepareToTest();
196 // Just make sure toString() does not return null or the java reference
197 assertNotSame("toString returned null",null, tmpEvent
.toString() );
198 assertNotSame("toString is not overridded!", tmpEvent
.getClass().getName() + '@' + Integer
.toHexString(tmpEvent
.hashCode()), tmpEvent
.toString() );