1 package org
.eclipse
.linuxtools
.lttng
;
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
.control
.LttngCoreProviderFactory
;
11 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
12 import org
.eclipse
.linuxtools
.lttng
.event
.LttngSyntheticEvent
;
13 import org
.eclipse
.linuxtools
.lttng
.event
.LttngSyntheticEvent
.SequenceInd
;
14 import org
.eclipse
.linuxtools
.lttng
.event
.LttngTimestamp
;
15 import org
.eclipse
.linuxtools
.lttng
.state
.experiment
.IStateExperimentManager
;
16 import org
.eclipse
.linuxtools
.lttng
.state
.experiment
.StateManagerFactory
;
17 import org
.eclipse
.linuxtools
.lttng
.tests
.LTTngCoreTestPlugin
;
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 public abstract class LttngTestPreparation
extends TestCase
{
29 // ========================================================================
31 // ========================================================================
32 private final static String ftracepath_T1
= "traceset/trace-15316events_nolost_newformat";
33 final static String fTextTracepath_T1
= "traceset/trace-15316events_nolost_newformat.txt";
35 private static final Long CHECK_POINT_INTERVAL
= 1000L;
37 final Long
[] expectedEvents_T1
= new Long
[20];
38 final Long
[] requestIntervals_T1
= new Long
[32];
40 static LTTngTextTrace ftextStream_T1
= null;
41 private static LTTngTrace frealStream
= null;
43 private TmfExperiment
<LttngEvent
> fTestExperiment
= null;
44 protected volatile int feventCount
= 0;
45 protected boolean validSequence
= true;
47 public LttngTestPreparation() {
52 public LttngTestPreparation(String name
) {
57 protected void init() {
58 fillInRequestIntervals();
59 fillInExpectedEvents();
66 protected TmfExperiment
<LttngEvent
> prepareExperimentToTest() {
67 if (fTestExperiment
== null) {
68 String expId
= "testExperiment";
71 // Define traces in experiment
72 ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
73 ITmfTrace trace
= prepareStreamToTest();
76 // create experiment and associate traces
77 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
78 expId
, traces
, TmfTimestamp
.Zero
, TmfExperiment
.DEFAULT_BLOCK_SIZE
, true);
79 // fTestExperiment.indexExperiment(waitForCompletion);
81 // Set the current selected experiment as the test experiment
82 TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
83 this, fTestExperiment
);
84 fTestExperiment
.experimentSelected(signal
);
87 return fTestExperiment
;
93 protected TmfExperiment
<LttngEvent
> prepareTextExperimentToTest() {
94 if (fTestExperiment
== null) {
95 String expId
= "testExperiment";
98 // Define traces in experiment
99 ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
100 ITmfTrace trace
= prepareTextStreamToTest();
103 // create experiment and associate traces
104 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
107 // Set the current selected experiment as the test experiment
108 TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
109 this, fTestExperiment
);
110 fTestExperiment
.experimentSelected(signal
);
114 return fTestExperiment
;
117 protected LTTngTrace
prepareStreamToTest() {
118 if (frealStream
== null) {
120 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(ftracepath_T1
),
122 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
123 LTTngTrace tmpStream
= new LTTngTrace(testfile
.getPath());
124 frealStream
= tmpStream
;
125 } catch (Exception e
) {
126 System
.out
.println("ERROR : Could not open " + ftracepath_T1
);
130 frealStream
.seekEvent(0L);
136 protected LTTngTextTrace
prepareTextStreamToTest() {
137 if (ftextStream_T1
== null) {
139 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(),
140 new Path(fTextTracepath_T1
), null);
141 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
142 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath());
143 ftextStream_T1
= tmpStream
;
145 } catch (Exception e
) {
146 System
.out
.println("ERROR : Could not open " + fTextTracepath_T1
);
147 ftextStream_T1
= null;
150 ftextStream_T1
.seekEvent(0);
153 return ftextStream_T1
;
156 protected IStateExperimentManager
prepareExperimentContext(
157 boolean waitForRequest
) {
158 // Create a new Experiment manager
159 IStateExperimentManager expManager
= StateManagerFactory
160 .getExperimentManager();
161 // Configure the interval to create check points so this can be tested
162 // with medium size files i.e. default is 50000 events
163 StateManagerFactory
.setTraceCheckPointInterval(CHECK_POINT_INTERVAL
);
165 // Lets wait for the request completion to analyse the results
166 LttngCoreProviderFactory
.getEventProvider()
167 .setWaitForRequest(waitForRequest
);
175 * , > 0 and between 0 - 31
177 * , > startIdx and between 0 - 31
180 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest(Class
<T
> k
, int startIdx
, int endIdx
) {
181 return prepareEventRequest(k
, startIdx
, endIdx
, true);
188 * , > 0 and between 0 - 31
190 * , > startIdx and between 0 - 31
191 * @param printFirst20
192 * , print the first expected events vs actual events
195 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest(
196 Class
<T
> k
, final int startIdx
, int endIdx
, final boolean printFirst20
) {
198 if (!(endIdx
> startIdx
&& startIdx
>= 0 && endIdx
<= 31)) {
199 TraceDebug
.debug("Event request indexes out of bounds");
203 int DEFAULT_CHUNK
= 1;
206 TmfTimeRange trange
= new TmfTimeRange(new LttngTimestamp(
207 requestIntervals_T1
[startIdx
]), new LttngTimestamp(
208 requestIntervals_T1
[endIdx
]));
211 validSequence
= true;
212 TmfEventRequest
<T
> request
= new TmfEventRequest
<T
>(k
, trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
215 public void handleData(T event
) {
218 .println("Syntheric Event Received is null, after event: "
223 // Listen to only one variant of synthetic event to keep
225 if (event
instanceof LttngSyntheticEvent
) {
226 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
) {
231 // Validating the orders of the first 20 events
232 if (printFirst20
&& feventCount
< 20) {
233 long timevalue
= event
.getTimestamp().getValue();
234 if (timevalue
!= expectedEvents_T1
[feventCount
]) {
235 validSequence
= false;
236 System
.out
.println("Expected Event: "
237 + expectedEvents_T1
[feventCount
] + " actual: "
238 + event
.getTimestamp().getValue());
240 System
.out
.println("Synthetic Event: " + feventCount
241 + " matched expected time");
250 * possibly increased by multiple request threads
252 private synchronized void incrementCount() {
257 public void handleCompleted() {
258 // if (isCancelled() || isFailed()) {
259 // // No notification to end request handlers
261 // // notify the associated end request handlers
262 // requestCompleted();
265 System
.out
.println("handleCompleted(request:" + startIdx
+ ") Number of events processed: " + feventCount
);
276 * , > 0 and between 0 - 31
278 * , > startIdx and between 0 - 31
279 * @param printFirst20
280 * , print the first expected events vs actual events
283 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest2(
284 Class
<T
> k
, final int startIdx
, int endIdx
, final boolean printFirst20
) {
286 if (!(endIdx
> startIdx
&& startIdx
>= 0 && endIdx
<= 31)) {
287 TraceDebug
.debug("Event request indexes out of bounds");
291 int DEFAULT_CHUNK
= 1;
294 TmfTimeRange trange
= new TmfTimeRange(new LttngTimestamp(
295 requestIntervals_T1
[startIdx
]), new LttngTimestamp(
296 requestIntervals_T1
[endIdx
]));
299 validSequence
= true;
300 TmfEventRequest
<T
> request
= new TmfEventRequest
<T
>(k
, trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
303 public void handleData(T event
) {
306 .println("Syntheric Event Received is null, after event: "
311 // Listen to only one variant of synthetic event to keep
313 if (event
instanceof LttngSyntheticEvent
) {
314 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
) {
319 // Validating the orders of the first 20 events
320 if (printFirst20
&& feventCount
< 20) {
321 long timevalue
= event
.getTimestamp().getValue();
322 if (timevalue
!= expectedEvents_T1
[feventCount
]) {
323 validSequence
= false;
324 System
.out
.println("Expected Event: "
325 + expectedEvents_T1
[feventCount
] + " actual: "
326 + event
.getTimestamp().getValue());
328 System
.out
.println("Synthetic Event: " + feventCount
329 + " matched expected time");
338 * possibly increased by multiple request threads
340 private synchronized void incrementCount() {
345 public void handleCompleted() {
346 // if (isCancelled() || isFailed()) {
347 // // No notification to end request handlers
349 // // notify the associated end request handlers
350 // requestCompleted();
353 System
.out
.println("handleCompleted(request:" + startIdx
+ ") Number of events processed: " + feventCount
);
363 private void fillInExpectedEvents() {
364 expectedEvents_T1
[0] = 13589759412128L;
365 expectedEvents_T1
[1] = 13589759419903L;
366 expectedEvents_T1
[2] = 13589759422785L;
367 expectedEvents_T1
[3] = 13589759425598L;
368 expectedEvents_T1
[4] = 13589759430979L;
369 expectedEvents_T1
[5] = 13589759433694L;
370 expectedEvents_T1
[6] = 13589759436212L;
371 expectedEvents_T1
[7] = 13589759438797L;
372 expectedEvents_T1
[8] = 13589759441253L;
373 expectedEvents_T1
[9] = 13589759444795L;
374 expectedEvents_T1
[10] = 13589759447800L;
375 expectedEvents_T1
[11] = 13589759450836L;
376 expectedEvents_T1
[12] = 13589759453835L;
377 expectedEvents_T1
[13] = 13589759459351L;
378 expectedEvents_T1
[14] = 13589759464411L;
379 expectedEvents_T1
[15] = 13589759467021L;
380 expectedEvents_T1
[16] = 13589759469668L;
381 expectedEvents_T1
[17] = 13589759474938L;
382 expectedEvents_T1
[18] = 13589759477536L;
383 expectedEvents_T1
[19] = 13589759480485L;
387 * Intervals for trace 1, separated %500 + last event
389 private void fillInRequestIntervals() {
390 requestIntervals_T1
[0] = 13589759412128L; /* check point expected */
391 requestIntervals_T1
[1] = 13589763490945L; /* between check points */
392 requestIntervals_T1
[2] = 13589778265041L; /* check point expected */
393 requestIntervals_T1
[3] = 13589783143445L; /* between check points */
394 requestIntervals_T1
[4] = 13589786300104L; /* check point expected */
395 requestIntervals_T1
[5] = 13589790722564L; /* between check points */
396 requestIntervals_T1
[6] = 13589796139823L; /* check point expected */
397 requestIntervals_T1
[7] = 13589800400562L; /* between check points */
398 requestIntervals_T1
[8] = 13589801594374L; /* check point expected */
399 requestIntervals_T1
[9] = 13589802750295L; /* between check points */
400 requestIntervals_T1
[10] = 13589804071157L; /* check point expected */
401 requestIntervals_T1
[11] = 13589810124488L; /* between check points */
402 requestIntervals_T1
[12] = 13589822493183L; /* check point expected */
403 requestIntervals_T1
[13] = 13589824131273L; /* between check points */
404 requestIntervals_T1
[14] = 13589825398284L; /* check point expected */
405 requestIntervals_T1
[15] = 13589826664185L; /* between check points */
406 requestIntervals_T1
[16] = 13589827811998L; /* check point expected */
407 requestIntervals_T1
[17] = 13589828915763L; /* between check points */
408 requestIntervals_T1
[18] = 13589830074220L; /* check point expected */
409 requestIntervals_T1
[19] = 13589831232050L; /* between check points */
410 requestIntervals_T1
[20] = 13589832394049L; /* check point expected */
411 requestIntervals_T1
[21] = 13589833852883L; /* between check points */
412 requestIntervals_T1
[22] = 13589839626892L; /* check point expected */
413 requestIntervals_T1
[23] = 13589849509798L; /* between check points */
414 requestIntervals_T1
[24] = 13589850728538L; /* check point expected */
415 requestIntervals_T1
[25] = 13589851889230L; /* between check points */
416 requestIntervals_T1
[26] = 13589853294800L; /* check point expected */
417 requestIntervals_T1
[27] = 13589859414998L; /* between check points */
418 requestIntervals_T1
[28] = 13589878046089L; /* check point expected */
419 requestIntervals_T1
[29] = 13589886468603L; /* between check points */
420 requestIntervals_T1
[30] = 13589902256918L; /* check point expected */
421 requestIntervals_T1
[31] = 13589906758692L; /* last event in T1 */