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
,
213 trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
216 public void handleData() {
217 T
[] result
= getData();
219 T event
= (result
.length
> 0) ? result
[0] : null;
222 .println("Syntheric Event Received is null, after event: "
227 // Listen to only one variant of synthetic event to keep
229 if (event
instanceof LttngSyntheticEvent
) {
230 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
) {
235 // Validating the orders of the first 20 events
236 if (printFirst20
&& feventCount
< 20) {
237 long timevalue
= event
.getTimestamp().getValue();
238 if (timevalue
!= expectedEvents_T1
[feventCount
]) {
239 validSequence
= false;
240 System
.out
.println("Expected Event: "
241 + expectedEvents_T1
[feventCount
] + " actual: "
242 + event
.getTimestamp().getValue());
244 System
.out
.println("Synthetic Event: " + feventCount
245 + " matched expected time");
254 * possibly increased by multiple request threads
256 private synchronized void incrementCount() {
261 public void handleCompleted() {
262 // if (isCancelled() || isFailed()) {
263 // // No notification to end request handlers
265 // // notify the associated end request handlers
266 // requestCompleted();
269 System
.out
.println("handleCompleted(request:" + startIdx
+ ") Number of events processed: " + feventCount
);
280 * , > 0 and between 0 - 31
282 * , > startIdx and between 0 - 31
283 * @param printFirst20
284 * , print the first expected events vs actual events
287 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest2(
288 Class
<T
> k
, final int startIdx
, int endIdx
, final boolean printFirst20
) {
290 if (!(endIdx
> startIdx
&& startIdx
>= 0 && endIdx
<= 31)) {
291 TraceDebug
.debug("Event request indexes out of bounds");
295 int DEFAULT_CHUNK
= 1;
298 TmfTimeRange trange
= new TmfTimeRange(new LttngTimestamp(
299 requestIntervals_T1
[startIdx
]), new LttngTimestamp(
300 requestIntervals_T1
[endIdx
]));
303 validSequence
= true;
304 TmfEventRequest
<T
> request
= new TmfEventRequest
<T
>(k
,
305 trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
308 public void handleData() {
309 T
[] result
= getData();
311 T event
= (result
.length
> 0) ? result
[0] : null;
314 .println("Syntheric Event Received is null, after event: "
319 // Listen to only one variant of synthetic event to keep
321 if (event
instanceof LttngSyntheticEvent
) {
322 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
) {
327 // Validating the orders of the first 20 events
328 if (printFirst20
&& feventCount
< 20) {
329 long timevalue
= event
.getTimestamp().getValue();
330 if (timevalue
!= expectedEvents_T1
[feventCount
]) {
331 validSequence
= false;
332 System
.out
.println("Expected Event: "
333 + expectedEvents_T1
[feventCount
] + " actual: "
334 + event
.getTimestamp().getValue());
336 System
.out
.println("Synthetic Event: " + feventCount
337 + " matched expected time");
346 * possibly increased by multiple request threads
348 private synchronized void incrementCount() {
353 public void handleCompleted() {
354 // if (isCancelled() || isFailed()) {
355 // // No notification to end request handlers
357 // // notify the associated end request handlers
358 // requestCompleted();
361 System
.out
.println("handleCompleted(request:" + startIdx
+ ") Number of events processed: " + feventCount
);
371 private void fillInExpectedEvents() {
372 expectedEvents_T1
[0] = 13589759412128L;
373 expectedEvents_T1
[1] = 13589759419903L;
374 expectedEvents_T1
[2] = 13589759422785L;
375 expectedEvents_T1
[3] = 13589759425598L;
376 expectedEvents_T1
[4] = 13589759430979L;
377 expectedEvents_T1
[5] = 13589759433694L;
378 expectedEvents_T1
[6] = 13589759436212L;
379 expectedEvents_T1
[7] = 13589759438797L;
380 expectedEvents_T1
[8] = 13589759441253L;
381 expectedEvents_T1
[9] = 13589759444795L;
382 expectedEvents_T1
[10] = 13589759447800L;
383 expectedEvents_T1
[11] = 13589759450836L;
384 expectedEvents_T1
[12] = 13589759453835L;
385 expectedEvents_T1
[13] = 13589759459351L;
386 expectedEvents_T1
[14] = 13589759464411L;
387 expectedEvents_T1
[15] = 13589759467021L;
388 expectedEvents_T1
[16] = 13589759469668L;
389 expectedEvents_T1
[17] = 13589759474938L;
390 expectedEvents_T1
[18] = 13589759477536L;
391 expectedEvents_T1
[19] = 13589759480485L;
395 * Intervals for trace 1, separated %500 + last event
397 private void fillInRequestIntervals() {
398 requestIntervals_T1
[0] = 13589759412128L; /* check point expected */
399 requestIntervals_T1
[1] = 13589763490945L; /* between check points */
400 requestIntervals_T1
[2] = 13589778265041L; /* check point expected */
401 requestIntervals_T1
[3] = 13589783143445L; /* between check points */
402 requestIntervals_T1
[4] = 13589786300104L; /* check point expected */
403 requestIntervals_T1
[5] = 13589790722564L; /* between check points */
404 requestIntervals_T1
[6] = 13589796139823L; /* check point expected */
405 requestIntervals_T1
[7] = 13589800400562L; /* between check points */
406 requestIntervals_T1
[8] = 13589801594374L; /* check point expected */
407 requestIntervals_T1
[9] = 13589802750295L; /* between check points */
408 requestIntervals_T1
[10] = 13589804071157L; /* check point expected */
409 requestIntervals_T1
[11] = 13589810124488L; /* between check points */
410 requestIntervals_T1
[12] = 13589822493183L; /* check point expected */
411 requestIntervals_T1
[13] = 13589824131273L; /* between check points */
412 requestIntervals_T1
[14] = 13589825398284L; /* check point expected */
413 requestIntervals_T1
[15] = 13589826664185L; /* between check points */
414 requestIntervals_T1
[16] = 13589827811998L; /* check point expected */
415 requestIntervals_T1
[17] = 13589828915763L; /* between check points */
416 requestIntervals_T1
[18] = 13589830074220L; /* check point expected */
417 requestIntervals_T1
[19] = 13589831232050L; /* between check points */
418 requestIntervals_T1
[20] = 13589832394049L; /* check point expected */
419 requestIntervals_T1
[21] = 13589833852883L; /* between check points */
420 requestIntervals_T1
[22] = 13589839626892L; /* check point expected */
421 requestIntervals_T1
[23] = 13589849509798L; /* between check points */
422 requestIntervals_T1
[24] = 13589850728538L; /* check point expected */
423 requestIntervals_T1
[25] = 13589851889230L; /* between check points */
424 requestIntervals_T1
[26] = 13589853294800L; /* check point expected */
425 requestIntervals_T1
[27] = 13589859414998L; /* between check points */
426 requestIntervals_T1
[28] = 13589878046089L; /* check point expected */
427 requestIntervals_T1
[29] = 13589886468603L; /* between check points */
428 requestIntervals_T1
[30] = 13589902256918L; /* check point expected */
429 requestIntervals_T1
[31] = 13589906758692L; /* last event in T1 */