Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / event / LttngEventTest.java
1 package org.eclipse.linuxtools.lttng.event;
2
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;
8
9 /*
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()
18
19 */
20
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";
25
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;
34
35 private LttngEvent prepareToTest() {
36 LttngEvent tmpEvent = null;
37
38 // This trace should be valid
39 try {
40 LTTngTrace tmpStream = new LTTngTrace(tracepath1, waitForCompletion, skipIndexing);
41 tmpEvent = (LttngEvent)tmpStream.parseEvent(new TmfTraceContext(null, null, 0) );
42 }
43 catch (Exception e) {
44 System.out.println("ERROR : Could not open " + tracepath1);
45 }
46
47 return tmpEvent;
48 }
49
50 public void testConstructors() {
51
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;
63
64 // This need to work if we want to perform tests
65 try {
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);
70 testEvent = null;
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();
77 }
78 catch( Exception e) {
79 fail("Cannot allocate an EventStream, junit failed!");
80 }
81
82
83
84 // Test with null timestamp
85 try {
86 testEvent = new LttngEvent( null, testSource, testType, testContent, testReference, testJniEvent );
87 fail("Construction with null timestamp should fail!");
88 }
89 catch( Exception e) {
90 }
91
92 // Test with null source
93 try {
94 testEvent = new LttngEvent( testTime, null, testType, testContent, testReference, testJniEvent );
95 fail("Construction with null source should fail!");
96 }
97 catch( Exception e) {
98 }
99
100 // Test with null type
101 try {
102 testEvent = new LttngEvent( testTime, testSource, null, testContent, testReference, testJniEvent );
103 fail("Construction with null type should fail!");
104 }
105 catch( Exception e) {
106 }
107
108 // Test with null content
109 try {
110 testEvent = new LttngEvent( testTime, testSource, testType, null, testReference, testJniEvent );
111 fail("Construction with null content should fail!");
112 }
113 catch( Exception e) {
114 }
115
116 // Test with null reference
117 try {
118 testEvent = new LttngEvent( testTime, testSource, testType, testContent, null, testJniEvent );
119 fail("Construction with null reference should fail!");
120 }
121 catch( Exception e) {
122 }
123
124 // Test with null jni Event
125 try {
126 testEvent = new LttngEvent( testTime, testSource, testType, testContent, testReference, null);
127 fail("Construction with null jniEvent should fail!");
128 }
129 catch( Exception e) {
130 }
131
132 // Finally, test constructor with correct information
133 try {
134 testEvent = new LttngEvent( testTime, testSource, testType, testContent, testReference, testJniEvent);
135 }
136 catch( Exception e) {
137 fail("Construction with correct information failed!");
138 }
139
140 // Test about copy constructor
141
142 // Pass a null to copy constructor
143 try {
144 testAnotherEvent = new LttngEvent(null);
145 fail("Copy constructor with null old event should fail!");
146 }
147 catch( Exception e) {
148 }
149
150 // Copy constructor used properly
151 testEvent = prepareToTest();
152 try {
153 testAnotherEvent = new LttngEvent(testEvent);
154 }
155 catch( Exception e) {
156 fail("Correct utilisation of copy constructor failed!");
157 }
158
159 }
160
161 public void testGetter() {
162 LttngEvent testEvent = prepareToTest();
163
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) );
173 }
174
175 public void testConversion() {
176 JniEvent tmpJniEvent = null;
177 LttngEvent testEvent = null;
178
179
180 // Copy constructor used properly
181 testEvent = prepareToTest();
182 try {
183 tmpJniEvent = testEvent.convertEventTmfToJni();
184 }
185 catch( Exception e) {
186 fail("Conversion raised an exception!");
187 }
188
189 assertNotSame("Conversion returned a null event!",null, tmpJniEvent );
190
191 }
192
193 public void testToString() {
194 LttngEvent tmpEvent = prepareToTest();
195
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() );
199 }
200
201 }
This page took 0.036928 seconds and 5 git commands to generate.