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