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