Change type of event source from TmfEventSource to String
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core.tests / src / org / eclipse / linuxtools / lttng / core / tests / event / LttngEventTest.java
1 package org.eclipse.linuxtools.lttng.core.tests.event;
2
3 import java.io.File;
4 import java.net.URL;
5
6 import junit.framework.TestCase;
7
8 import org.eclipse.core.runtime.FileLocator;
9 import org.eclipse.core.runtime.Path;
10 import org.eclipse.linuxtools.lttng.core.event.LttngEvent;
11 import org.eclipse.linuxtools.lttng.core.event.LttngEventContent;
12 import org.eclipse.linuxtools.lttng.core.event.LttngEventReference;
13 import org.eclipse.linuxtools.lttng.core.event.LttngEventType;
14 import org.eclipse.linuxtools.lttng.core.event.LttngTimestamp;
15 import org.eclipse.linuxtools.lttng.core.tests.LTTngCoreTestPlugin;
16 import org.eclipse.linuxtools.lttng.core.trace.LTTngTextTrace;
17 import org.eclipse.linuxtools.lttng.core.trace.LTTngTrace;
18 import org.eclipse.linuxtools.lttng.jni.JniEvent;
19 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
20 import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
21
22 /*
23 Functions tested here :
24 public LttngEvent(LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent)
25 public LttngEvent(LttngEvent oldEvent)
26
27 public String getChannelName()
28 public long getCpuId()
29 public String getMarkerName()
30 public LttngEventType getType()
31 public LttngEventContent getContent()
32
33 public void updateJniEventReference(JniEvent newJniEventReference)
34 public void setContent(LttngEventContent newContent)
35 public void setType(LttngEventType newType)
36
37 public JniEvent convertEventTmfToJni()
38
39 public String toString()
40 */
41
42 @SuppressWarnings("nls")
43 public class LttngEventTest extends TestCase {
44 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
45 private final static boolean skipIndexing=true;
46
47 private final static long eventTimestamp = 13589759412128L;
48 private final static String eventSource = "Kernel Core";
49 private final static String eventType = "metadata/0/core_marker_id";
50 private final static String eventChannel = "metadata";
51 private final static long eventCpu = 0;
52 private final static String eventMarker = "core_marker_id";
53 // 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 ";
54 private final static String eventReference = eventChannel + "_" + eventCpu;
55
56
57 private static LTTngTextTrace testStream = null;
58 private LTTngTextTrace initializeEventStream() {
59 if (testStream == null) {
60 try {
61 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
62 File testfile = new File(FileLocator.toFileURL(location).toURI());
63 LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath(), skipIndexing);
64 testStream = tmpStream;
65 }
66 catch (Exception e) {
67 System.out.println("ERROR : Could not open " + tracepath1);
68 testStream = null;
69 }
70 }
71 else {
72 testStream.seekEvent(0);
73 }
74
75 return testStream;
76 }
77
78 private LttngEvent prepareToTest() {
79 LttngEvent tmpEvent = null;
80
81 try {
82 LTTngTextTrace tmpStream = initializeEventStream();
83 tmpEvent = (LttngEvent)tmpStream.getNextEvent(new TmfContext(new TmfLocation<Long>(0L), 0) );
84 }
85 catch (Exception e) {
86 System.out.println("ERROR : Could not open " + tracepath1);
87 }
88
89 return tmpEvent;
90 }
91
92 public void testConstructors() {
93 LttngEvent testEvent = null;
94 LTTngTrace testTrace = null;
95 @SuppressWarnings("unused")
96 LttngEvent testAnotherEvent = null;
97 LttngTimestamp testTime = null;
98 String testSource = null;
99 LttngEventType testType = null;
100 LttngEventContent testContent = null;
101 LttngEventReference testReference = null;
102 JniEvent testJniEvent = null;
103 String[] testMarkerFields = null;
104
105 // This need to work if we want to perform tests
106 try {
107 // In order to test LttngEvent, we need all these constructors/functions to work.
108 // Make sure to run their unit tests first!
109 testMarkerFields = new String[1];
110 testEvent = null;
111 testTime = new LttngTimestamp(0L);
112 testSource = "test";
113 testType = new LttngEventType("test", 0L, "test", 0, testMarkerFields);
114 testContent = new LttngEventContent(testEvent);
115 testReference = new LttngEventReference("test", "test");
116 }
117 catch( Exception e) {
118 fail("Cannot allocate an EventStream, junit failed!");
119 }
120
121 // Test constructor with correct information
122 try {
123 testEvent = new LttngEvent(testTrace, testTime, testSource, testType, testContent, testReference, testJniEvent);
124 }
125 catch( Exception e) {
126 fail("Construction with correct information failed!");
127 }
128
129 // Test about copy constructor
130 // Passing a null to copy constructor should fail
131 try {
132 testAnotherEvent = new LttngEvent(null);
133 fail("Copy constructor with null old event should fail!");
134 }
135 catch( Exception e) {
136 }
137
138 // Copy constructor used properly
139 testEvent = prepareToTest();
140 try {
141 testAnotherEvent = new LttngEvent(testEvent);
142 }
143 catch( Exception e) {
144 fail("Correct utilisation of copy constructor failed!");
145 }
146
147 }
148
149 public void testGetter() {
150 LttngEvent testEvent = prepareToTest();
151
152 // These will test TMF functions but since we are expecting it to work...
153 assertEquals("Timestamp not what expected!",eventTimestamp,testEvent.getTimestamp().getValue());
154 assertEquals("Source not what expected!",eventSource,testEvent.getSource());
155 assertEquals("Reference not what expected!",eventReference,((String)testEvent.getReference().toString()) );
156
157 // These should be overridden functions
158 assertEquals("Type not what expected!",eventType,testEvent.getType().getTypeId());
159 assertEquals("Channel not what expected!",eventChannel,testEvent.getChannelName());
160 assertEquals("CpuId not what expected!",eventCpu,testEvent.getCpuId());
161 assertEquals("Marker not what expected!",eventMarker,testEvent.getMarkerName());
162
163 // All events should have a parent
164 assertNotNull("Trace parent for this event is null!", testEvent.getTrace() );
165
166 // *** FIXME ***
167 // Depending from the Java version because of the "hashcode()" on String.
168 // We can't really test that safetly
169 //
170 //assertEquals("Content not what expected!",eventContent,testEvent.getContent().toString());
171 assertNotSame("Content is null!", null,testEvent.getContent());
172 }
173
174 public void testSetter() {
175 LttngEvent testEvent = prepareToTest();
176
177 LttngEventType testType = null;
178 LttngEventContent testContent = null;
179 JniEvent testJniEvent = null;
180
181 String[] testMarkerFields = new String[1];
182 testType = new LttngEventType("test", 0L, "test", 0, testMarkerFields);
183 testContent = new LttngEventContent(testEvent);
184
185 try {
186 // *** FIXME ***
187 // This won't do anything good on a text trace
188 testEvent.updateJniEventReference(testJniEvent);
189
190 testEvent.setContent(testContent);
191 testEvent.setType(testType);
192 }
193 catch( Exception e) {
194 fail("Setters raised an exception!");
195 }
196
197 assertSame("SetType failed : type not what expected!",testType,testEvent.getType());
198 assertSame("SetContent failed : content not what expected!",testContent,testEvent.getContent());
199
200 }
201
202
203 public void testConversion() {
204 @SuppressWarnings("unused")
205 JniEvent tmpJniEvent = null;
206 LttngEvent testEvent = null;
207
208 testEvent = prepareToTest();
209
210 try {
211 tmpJniEvent = testEvent.convertEventTmfToJni();
212 }
213 catch( Exception e) {
214 fail("Conversion raised an exception!");
215 }
216
217 // *** FIXME ***
218 // This test can't work with a text trace, commented for now
219 //assertNotSame("Conversion returned a null event!",null, tmpJniEvent );
220 }
221
222 public void testToString() {
223 LttngEvent tmpEvent = prepareToTest();
224
225 // Just make sure toString() does not return null or the java reference
226 assertNotSame("toString returned null",null, tmpEvent.toString() );
227 assertNotSame("toString is not overridded!", tmpEvent.getClass().getName() + '@' + Integer.toHexString(tmpEvent.hashCode()), tmpEvent.toString() );
228 }
229
230 }
This page took 0.03926 seconds and 6 git commands to generate.