2010-01-19 Francois Chouinard <fchouinard@gmail.com>
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / trace / LTTngTextTraceTest.java
CommitLineData
03c71d1e
ASL
1package org.eclipse.linuxtools.lttng.tests.trace;
2
03c71d1e 3import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
5fbe0b84 4import org.eclipse.linuxtools.tmf.event.TmfEvent;
03c71d1e 5import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
86de1b08 6import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
5fbe0b84 7import junit.framework.TestCase;
03c71d1e
ASL
8
9/*
10 Functions tested here :
5fbe0b84
FC
11 public LTTngTextTrace(String path) throws Exception
12
13 public TmfTraceContext seekLocation(Object location)
14 public TmfTraceContext seekEvent(TmfTimestamp timestamp)
15 public TmfTraceContext seekEvent(long position)
03c71d1e 16
5fbe0b84 17 public TmfEvent getNextEvent(TmfTraceContext context)
03c71d1e 18
5fbe0b84 19 public Object getCurrentLocation()
03c71d1e 20
5fbe0b84 21 public LttngEvent parseEvent(TmfTraceContext context)
03c71d1e
ASL
22 */
23
24public class LTTngTextTraceTest extends TestCase {
25
26 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
27 private final static String wrongTracePath="/somewhere/that/does/not/exist";
28
03c71d1e
ASL
29 private final static boolean skipIndexing=true;
30
86de1b08
ASL
31 private final static long firstEventTimestamp = 13589759412127L;
32 private final static long secondEventTimestamp = 13589759419902L;
33 private final static Long locationAfterFirstEvent = 245L;
03c71d1e 34
86de1b08 35 private final static String tracename = "traceset/trace_15316events_nolost_newformat";
03c71d1e
ASL
36
37 private final static long indexToSeekFirst = 0;
38 private final static Long locationToSeekFirst = 0L;
86de1b08 39 private final static long contextValueAfterFirstEvent = 13589759412127L;
03c71d1e
ASL
40 private final static String firstEventReference = tracename + "/metadata_0";
41
42
43 private final static long timestampToSeekTest1 = 13589826657302L;
44 private final static Long indexToSeekTest1 = 7497L;
86de1b08 45 private final static long locationToSeekTest1 = 1682942;
03c71d1e
ASL
46 private final static long contextValueAfterSeekTest1 = 13589826657302L;
47 private final static String seek1EventReference = tracename + "/vm_state_0";
48
86de1b08 49 private final static long timestampToSeekLast = 13589906758691L;
03c71d1e 50 private final static Long indexToSeekLast = 15315L;
86de1b08
ASL
51 private final static long locationToSeekLast = 3410544;
52 private final static long contextValueAfterSeekLast = 13589906758691L;
03c71d1e 53 private final static String seekLastEventReference = tracename + "/kernel_0";
5fbe0b84
FC
54
55 private LTTngTextTrace prepareStreamToTest() {
56 LTTngTextTrace tmpStream = null;
03c71d1e 57
5fbe0b84
FC
58 // This trace should be valid
59 try {
60 tmpStream = new LTTngTextTrace(tracepath1);
61 }
62 catch (Exception e) {
63 System.out.println("ERROR : Could not open " + tracepath1);
03c71d1e 64 }
03c71d1e 65
5fbe0b84
FC
66 return tmpStream;
67 }
68
69 public void testTraceConstructors() {
03c71d1e
ASL
70 @SuppressWarnings("unused")
71 LTTngTextTrace testStream1 = null;
72
73 // Default constructor
74 // Test constructor with argument on a wrong tracepath, skipping indexing
75 try {
76 testStream1 = new LTTngTextTrace(wrongTracePath, skipIndexing);
77 fail("Construction with wrong tracepath should fail!");
78 }
79 catch( Exception e) {
80 }
81
82 // Test constructor with argument on a correct tracepath, skipping indexing
83 try {
5fbe0b84 84 testStream1 = new LTTngTextTrace(tracepath1, skipIndexing);
03c71d1e
ASL
85 }
86 catch( Exception e) {
87 fail("Construction with correct tracepath failed!");
88 }
89 }
90
91 public void testGetNextEvent() {
92 TmfEvent tmpEvent = null;
93 LTTngTextTrace testStream1 = prepareStreamToTest();
94
86de1b08 95 TmfTraceContext tmpContext = new TmfTraceContext(null, null, 0);
03c71d1e
ASL
96 // We should be at the beginning of the trace, so we will just read the first event now
97 tmpEvent = testStream1.getNextEvent(tmpContext );
98 assertNotSame("tmpEvent is null after first getNextEvent()",null,tmpEvent );
99 assertEquals("tmpEvent has wrong timestamp after first getNextEvent()",firstEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
100
101 // Read the next event as well
102 tmpEvent = testStream1.getNextEvent( tmpContext);
103 assertNotSame("tmpEvent is null after second getNextEvent()",null,tmpEvent );
104 assertEquals("tmpEvent has wrong timestamp after second getNextEvent()",secondEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
105 }
106
107 public void testParseEvent() {
108 TmfEvent tmpEvent = null;
109 LTTngTextTrace testStream1 = prepareStreamToTest();
110
86de1b08 111 TmfTraceContext tmpContext = new TmfTraceContext(null, null, 0);
03c71d1e
ASL
112 // We should be at the beginning of the trace, so we will just parse the first event now
113 tmpEvent = testStream1.parseEvent(tmpContext );
114 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent );
115 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
116
117 // Use parseEvent again. Should be the same event
118 tmpEvent = testStream1.parseEvent(tmpContext );
119 assertNotSame("tmpEvent is null after first parseEvent()",null,tmpEvent );
120 assertEquals("tmpEvent has wrong timestamp after first parseEvent()",firstEventTimestamp,(long)tmpEvent.getTimestamp().getValue() );
121 }
122
123 public void testSeekEventTimestamp() {
124 TmfEvent tmpEvent = null;
86de1b08 125 TmfTraceContext tmpContext = new TmfTraceContext(null, null, 0);
03c71d1e
ASL
126 LTTngTextTrace testStream1 = prepareStreamToTest();
127
128 // We should be at the beginning of the trace, we will seek at a certain timestamp
86de1b08 129 tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekTest1));
03c71d1e
ASL
130 tmpEvent = testStream1.getNextEvent(tmpContext);
131 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
86de1b08 132 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpContext.getTimestamp()).getValue() );
03c71d1e
ASL
133 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
134 assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) );
135
136 // Seek to the last timestamp
86de1b08 137 tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast));
03c71d1e
ASL
138 tmpEvent = testStream1.getNextEvent(tmpContext);
139 assertNotSame("tmpContext is null after seekEvent() to last",null,tmpContext );
86de1b08 140 assertEquals("tmpContext has wrong timestamp after seekEvent() to last",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpContext.getTimestamp()).getValue() );
03c71d1e
ASL
141 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
142 assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) );
143
144 // Seek to the first timestamp (startTime)
86de1b08 145 tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp));
03c71d1e
ASL
146 tmpEvent = testStream1.getNextEvent(tmpContext);
147 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent );
148 assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
149 assertNotSame("tmpContext is null after seekEvent() to first",null,tmpContext );
86de1b08 150 assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpContext.getTimestamp()).getValue() );
03c71d1e
ASL
151 }
152
153 public void testSeekEventIndex() {
154 TmfEvent tmpEvent = null;
86de1b08 155 TmfTraceContext tmpContext = new TmfTraceContext(null, null, 0);
03c71d1e
ASL
156 LTTngTextTrace testStream1 = prepareStreamToTest();
157
158 // We should be at the beginning of the trace, we will seek at a certain timestamp
159 tmpContext = testStream1.seekEvent(indexToSeekTest1);
160 tmpEvent = testStream1.getNextEvent(tmpContext);
161 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
86de1b08 162 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpContext.getTimestamp()).getValue() );
03c71d1e
ASL
163 assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
164 assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) );
165
166 // Seek to the last timestamp
167 tmpContext = testStream1.seekEvent(indexToSeekLast);
168 tmpEvent = testStream1.getNextEvent(tmpContext);
169 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
86de1b08 170 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpContext.getTimestamp()).getValue() );
03c71d1e
ASL
171 assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
172 assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) );
173
174 // Seek to the first timestamp (startTime)
175 tmpContext = testStream1.seekEvent(indexToSeekFirst);
176 tmpEvent = testStream1.getNextEvent(tmpContext);
177 assertNotSame("tmpContext is null after first seekEvent()",null,tmpContext );
86de1b08 178 assertEquals("tmpContext has wrong timestamp after first seekEvent()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpContext.getTimestamp()).getValue() );
03c71d1e
ASL
179 assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent );
180 assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
181 }
182
183 public void testSeekLocation() {
184 TmfEvent tmpEvent = null;
86de1b08 185 TmfTraceContext tmpContext = new TmfTraceContext(null, null, 0);
03c71d1e
ASL
186 LTTngTextTrace testStream1 = prepareStreamToTest();
187
188 // We should be at the beginning of the trace, we will seek at a certain timestamp
86de1b08 189 tmpContext = testStream1.seekLocation(locationToSeekTest1);
03c71d1e
ASL
190 tmpEvent = testStream1.getNextEvent(tmpContext);
191 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
86de1b08 192 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpContext.getTimestamp()).getValue() );
03c71d1e
ASL
193 assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent );
194 assertTrue("tmpEvent has wrong reference after first seekLocation()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) );
195
196 // Seek to the last timestamp
86de1b08 197 tmpContext = testStream1.seekLocation(locationToSeekLast);
03c71d1e
ASL
198 tmpEvent = testStream1.getNextEvent(tmpContext);
199 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
86de1b08 200 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpContext.getTimestamp()).getValue() );
03c71d1e
ASL
201 assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent );
202 assertTrue("tmpEvent has wrong reference after seekLocation() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) );
203
204 // Seek to the first timestamp (startTime)
86de1b08 205 tmpContext = testStream1.seekLocation(locationToSeekFirst);
03c71d1e
ASL
206 tmpEvent = testStream1.getNextEvent(tmpContext);
207 assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
86de1b08 208 assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpContext.getTimestamp()).getValue() );
03c71d1e
ASL
209 assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent );
210 assertTrue("tmpEvent has wrong reference after seekLocation() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
211 }
212
03c71d1e
ASL
213 public void testGetter() {
214 TmfEvent tmpEvent = null;
215 LTTngTextTrace testStream1 = prepareStreamToTest();
86de1b08 216
03c71d1e 217 // Move to the first event to have something to play with
86de1b08 218 tmpEvent = testStream1.parseEvent( new TmfTraceContext(null, null, 0));
03c71d1e
ASL
219
220 // Test current event
221 assertNotSame("tmpEvent is null after first event",null,tmpEvent );
222 assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
223 assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() );
86de1b08
ASL
224 assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent,(Long)testStream1.getCurrentLocation() );
225
03c71d1e
ASL
226 }
227
228 public void testToString() {
229 LTTngTextTrace testStream1 = prepareStreamToTest();
230
231 // Move to the first event to have something to play with
86de1b08 232 testStream1.parseEvent( new TmfTraceContext(null, null, 0) );
03c71d1e
ASL
233
234 // Just make sure toString() does not return null or the java reference
235 assertNotSame("toString returned null",null, testStream1.toString() );
236 assertNotSame("toString is not overridded!", testStream1.getClass().getName() + '@' + Integer.toHexString(testStream1.hashCode()), testStream1.toString() );
237 }
238
239}
This page took 0.034991 seconds and 5 git commands to generate.