1 package org
.eclipse
.linuxtools
.lttng
.tests
;
6 import junit
.framework
.TestCase
;
8 import org
.eclipse
.core
.runtime
.FileLocator
;
9 import org
.eclipse
.core
.runtime
.Path
;
10 import org
.eclipse
.linuxtools
.lttng
.TraceDebug
;
11 import org
.eclipse
.linuxtools
.lttng
.control
.LttngCoreProviderFactory
;
12 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
13 import org
.eclipse
.linuxtools
.lttng
.event
.LttngSyntheticEvent
;
14 import org
.eclipse
.linuxtools
.lttng
.event
.LttngSyntheticEvent
.SequenceInd
;
15 import org
.eclipse
.linuxtools
.lttng
.event
.LttngTimestamp
;
16 import org
.eclipse
.linuxtools
.lttng
.state
.experiment
.IStateExperimentManager
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.experiment
.StateManagerFactory
;
18 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTextTrace
;
19 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTrace
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
23 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequest
;
24 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
25 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
26 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
28 @SuppressWarnings("nls")
29 public abstract class LttngTestPreparation
extends TestCase
{
30 // ========================================================================
32 // ========================================================================
33 private final static String ftracepath_T1
= "traceset/trace-15316events_nolost_newformat";
34 final static String fTextTracepath_T1
= "traceset/trace-15316events_nolost_newformat.txt";
36 private static final Long CHECK_POINT_INTERVAL
= 1000L;
38 final Long
[] expectedEvents_T1
= new Long
[20];
39 final Long
[] requestIntervals_T1
= new Long
[32];
41 static LTTngTextTrace ftextStream_T1
= null;
42 private static LTTngTrace frealStream
= null;
44 private TmfExperiment
<LttngEvent
> fTestExperiment
= null;
45 protected volatile int feventCount
= 0;
46 protected boolean validSequence
= true;
48 public LttngTestPreparation() {
53 public LttngTestPreparation(String name
) {
58 protected void init() {
59 fillInRequestIntervals();
60 fillInExpectedEvents();
67 protected TmfExperiment
<LttngEvent
> prepareExperimentToTest() {
68 if (fTestExperiment
== null) {
69 String expId
= "testExperiment";
72 // Define traces in experiment
73 ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
74 ITmfTrace trace
= prepareStreamToTest();
77 // create experiment and associate traces
78 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
79 expId
, traces
, TmfTimestamp
.Zero
, TmfExperiment
.DEFAULT_BLOCK_SIZE
, true);
80 // fTestExperiment.indexExperiment(waitForCompletion);
82 // Set the current selected experiment as the test experiment
83 TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
84 this, fTestExperiment
);
85 fTestExperiment
.experimentSelected(signal
);
88 return fTestExperiment
;
94 protected TmfExperiment
<LttngEvent
> prepareTextExperimentToTest() {
95 if (fTestExperiment
== null) {
96 String expId
= "testExperiment";
99 // Define traces in experiment
100 ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
101 ITmfTrace trace
= prepareTextStreamToTest();
104 // create experiment and associate traces
105 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
108 // Set the current selected experiment as the test experiment
109 TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
110 this, fTestExperiment
);
111 fTestExperiment
.experimentSelected(signal
);
115 return fTestExperiment
;
118 protected LTTngTrace
prepareStreamToTest() {
119 if (frealStream
== null) {
121 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(ftracepath_T1
),
123 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
124 LTTngTrace tmpStream
= new LTTngTrace(testfile
.getPath());
125 frealStream
= tmpStream
;
126 } catch (Exception e
) {
127 System
.out
.println("ERROR : Could not open " + ftracepath_T1
);
131 frealStream
.seekEvent(0L);
137 protected LTTngTextTrace
prepareTextStreamToTest() {
138 if (ftextStream_T1
== null) {
140 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(),
141 new Path(fTextTracepath_T1
), null);
142 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
143 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath());
144 ftextStream_T1
= tmpStream
;
146 } catch (Exception e
) {
147 System
.out
.println("ERROR : Could not open " + fTextTracepath_T1
);
148 ftextStream_T1
= null;
151 ftextStream_T1
.seekEvent(0);
154 return ftextStream_T1
;
157 protected IStateExperimentManager
prepareExperimentContext(
158 boolean waitForRequest
) {
159 // Create a new Experiment manager
160 IStateExperimentManager expManager
= StateManagerFactory
161 .getExperimentManager();
162 // Configure the interval to create check points so this can be tested
163 // with medium size files i.e. default is 50000 events
164 StateManagerFactory
.setTraceCheckPointInterval(CHECK_POINT_INTERVAL
);
166 // Lets wait for the request completion to analyse the results
167 LttngCoreProviderFactory
.getEventProvider(0)
168 .setWaitForRequest(waitForRequest
);
176 * , > 0 and between 0 - 31
178 * , > startIdx and between 0 - 31
181 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest(Class
<T
> k
, int startIdx
, int endIdx
) {
182 return prepareEventRequest(k
, startIdx
, endIdx
, true);
189 * , > 0 and between 0 - 31
191 * , > startIdx and between 0 - 31
192 * @param printFirst20
193 * , print the first expected events vs actual events
196 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest(
197 Class
<T
> k
, final int startIdx
, int endIdx
, final boolean printFirst20
) {
199 if (!(endIdx
> startIdx
&& startIdx
>= 0 && endIdx
<= 31)) {
200 TraceDebug
.debug("Event request indexes out of bounds");
204 int DEFAULT_CHUNK
= 1;
207 TmfTimeRange trange
= new TmfTimeRange(new LttngTimestamp(
208 requestIntervals_T1
[startIdx
]), new LttngTimestamp(
209 requestIntervals_T1
[endIdx
]));
212 validSequence
= true;
213 TmfEventRequest
<T
> request
= new TmfEventRequest
<T
>(k
, trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
216 public void handleData(T event
) {
219 .println("Syntheric Event Received is null, after event: "
224 // Listen to only one variant of synthetic event to keep
226 if (event
instanceof LttngSyntheticEvent
) {
227 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
) {
232 // Validating the orders of the first 20 events
233 if (printFirst20
&& feventCount
< 20) {
234 long timevalue
= event
.getTimestamp().getValue();
235 if (timevalue
!= expectedEvents_T1
[feventCount
]) {
236 validSequence
= false;
237 System
.out
.println("Expected Event: "
238 + expectedEvents_T1
[feventCount
] + " actual: "
239 + event
.getTimestamp().getValue());
241 System
.out
.println("Synthetic Event: " + feventCount
242 + " matched expected time");
251 * possibly increased by multiple request threads
253 private synchronized void incrementCount() {
258 public void handleCompleted() {
259 // if (isCancelled() || isFailed()) {
260 // // No notification to end request handlers
262 // // notify the associated end request handlers
263 // requestCompleted();
266 System
.out
.println("handleCompleted(request:" + startIdx
+ ") Number of events processed: " + feventCount
);
277 * , > 0 and between 0 - 31
279 * , > startIdx and between 0 - 31
280 * @param printFirst20
281 * , print the first expected events vs actual events
284 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest2(
285 Class
<T
> k
, final int startIdx
, int endIdx
, final boolean printFirst20
) {
287 if (!(endIdx
> startIdx
&& startIdx
>= 0 && endIdx
<= 31)) {
288 TraceDebug
.debug("Event request indexes out of bounds");
292 int DEFAULT_CHUNK
= 1;
295 TmfTimeRange trange
= new TmfTimeRange(new LttngTimestamp(
296 requestIntervals_T1
[startIdx
]), new LttngTimestamp(
297 requestIntervals_T1
[endIdx
]));
300 validSequence
= true;
301 TmfEventRequest
<T
> request
= new TmfEventRequest
<T
>(k
, trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
304 public void handleData(T event
) {
307 .println("Syntheric Event Received is null, after event: "
312 // Listen to only one variant of synthetic event to keep
314 if (event
instanceof LttngSyntheticEvent
) {
315 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
) {
320 // Validating the orders of the first 20 events
321 if (printFirst20
&& feventCount
< 20) {
322 long timevalue
= event
.getTimestamp().getValue();
323 if (timevalue
!= expectedEvents_T1
[feventCount
]) {
324 validSequence
= false;
325 System
.out
.println("Expected Event: "
326 + expectedEvents_T1
[feventCount
] + " actual: "
327 + event
.getTimestamp().getValue());
329 System
.out
.println("Synthetic Event: " + feventCount
330 + " matched expected time");
339 * possibly increased by multiple request threads
341 private synchronized void incrementCount() {
346 public void handleCompleted() {
347 // if (isCancelled() || isFailed()) {
348 // // No notification to end request handlers
350 // // notify the associated end request handlers
351 // requestCompleted();
354 System
.out
.println("handleCompleted(request:" + startIdx
+ ") Number of events processed: " + feventCount
);
364 private void fillInExpectedEvents() {
365 expectedEvents_T1
[0] = 13589759412128L;
366 expectedEvents_T1
[1] = 13589759419903L;
367 expectedEvents_T1
[2] = 13589759422785L;
368 expectedEvents_T1
[3] = 13589759425598L;
369 expectedEvents_T1
[4] = 13589759430979L;
370 expectedEvents_T1
[5] = 13589759433694L;
371 expectedEvents_T1
[6] = 13589759436212L;
372 expectedEvents_T1
[7] = 13589759438797L;
373 expectedEvents_T1
[8] = 13589759441253L;
374 expectedEvents_T1
[9] = 13589759444795L;
375 expectedEvents_T1
[10] = 13589759447800L;
376 expectedEvents_T1
[11] = 13589759450836L;
377 expectedEvents_T1
[12] = 13589759453835L;
378 expectedEvents_T1
[13] = 13589759459351L;
379 expectedEvents_T1
[14] = 13589759464411L;
380 expectedEvents_T1
[15] = 13589759467021L;
381 expectedEvents_T1
[16] = 13589759469668L;
382 expectedEvents_T1
[17] = 13589759474938L;
383 expectedEvents_T1
[18] = 13589759477536L;
384 expectedEvents_T1
[19] = 13589759480485L;
388 * Intervals for trace 1, separated %500 + last event
390 private void fillInRequestIntervals() {
391 requestIntervals_T1
[0] = 13589759412128L; /* check point expected */
392 requestIntervals_T1
[1] = 13589763490945L; /* between check points */
393 requestIntervals_T1
[2] = 13589778265041L; /* check point expected */
394 requestIntervals_T1
[3] = 13589783143445L; /* between check points */
395 requestIntervals_T1
[4] = 13589786300104L; /* check point expected */
396 requestIntervals_T1
[5] = 13589790722564L; /* between check points */
397 requestIntervals_T1
[6] = 13589796139823L; /* check point expected */
398 requestIntervals_T1
[7] = 13589800400562L; /* between check points */
399 requestIntervals_T1
[8] = 13589801594374L; /* check point expected */
400 requestIntervals_T1
[9] = 13589802750295L; /* between check points */
401 requestIntervals_T1
[10] = 13589804071157L; /* check point expected */
402 requestIntervals_T1
[11] = 13589810124488L; /* between check points */
403 requestIntervals_T1
[12] = 13589822493183L; /* check point expected */
404 requestIntervals_T1
[13] = 13589824131273L; /* between check points */
405 requestIntervals_T1
[14] = 13589825398284L; /* check point expected */
406 requestIntervals_T1
[15] = 13589826664185L; /* between check points */
407 requestIntervals_T1
[16] = 13589827811998L; /* check point expected */
408 requestIntervals_T1
[17] = 13589828915763L; /* between check points */
409 requestIntervals_T1
[18] = 13589830074220L; /* check point expected */
410 requestIntervals_T1
[19] = 13589831232050L; /* between check points */
411 requestIntervals_T1
[20] = 13589832394049L; /* check point expected */
412 requestIntervals_T1
[21] = 13589833852883L; /* between check points */
413 requestIntervals_T1
[22] = 13589839626892L; /* check point expected */
414 requestIntervals_T1
[23] = 13589849509798L; /* between check points */
415 requestIntervals_T1
[24] = 13589850728538L; /* check point expected */
416 requestIntervals_T1
[25] = 13589851889230L; /* between check points */
417 requestIntervals_T1
[26] = 13589853294800L; /* check point expected */
418 requestIntervals_T1
[27] = 13589859414998L; /* between check points */
419 requestIntervals_T1
[28] = 13589878046089L; /* check point expected */
420 requestIntervals_T1
[29] = 13589886468603L; /* between check points */
421 requestIntervals_T1
[30] = 13589902256918L; /* check point expected */
422 requestIntervals_T1
[31] = 13589906758692L; /* last event in T1 */