1 package org
.eclipse
.linuxtools
.lttng
.core
.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
.internal
.lttng
.core
.TraceDebug
;
11 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.control
.LttngCoreProviderFactory
;
12 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngEvent
;
13 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngSyntheticEvent
;
14 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngSyntheticEvent
.SequenceInd
;
15 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngTimestamp
;
16 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.state
.experiment
.IStateExperimentManager
;
17 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.state
.experiment
.StateManagerFactory
;
18 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.trace
.LTTngTextTrace
;
19 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.trace
.LTTngTrace
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.experiment
.TmfExperiment
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.osgi
.framework
.FrameworkUtil
;
29 @SuppressWarnings("nls")
30 public abstract class LttngTestPreparation
extends TestCase
{
31 // ========================================================================
33 // ========================================================================
34 private final static String ftracepath_T1
= "traceset/trace-15316events_nolost_newformat";
35 final static String fTextTracepath_T1
= "traceset/trace-15316events_nolost_newformat.txt";
37 private static final Long CHECK_POINT_INTERVAL
= 1000L;
39 final Long
[] expectedEvents_T1
= new Long
[20];
40 final Long
[] requestIntervals_T1
= new Long
[32];
42 static LTTngTextTrace ftextStream_T1
= null;
43 private static LTTngTrace frealStream
= null;
45 private TmfExperiment
<LttngEvent
> fTestExperiment
= null;
46 protected volatile int feventCount
= 0;
47 protected boolean validSequence
= true;
49 public LttngTestPreparation() {
54 public LttngTestPreparation(final String name
) {
59 protected void init() {
60 fillInRequestIntervals();
61 fillInExpectedEvents();
68 protected TmfExperiment
<LttngEvent
> prepareExperimentToTest() {
69 if (fTestExperiment
== null) {
70 final String expId
= "testExperiment";
71 final int nbTraces
= 1;
73 // Define traces in experiment
74 @SuppressWarnings("unchecked")
76 ITmfTrace
<LttngEvent
>[] traces
= new ITmfTrace
[nbTraces
];
77 final ITmfTrace
<LttngEvent
> trace
= prepareStreamToTest();
80 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
81 expId
, traces
, TmfTimestamp
.ZERO
, TmfExperiment
.DEFAULT_BLOCK_SIZE
, true);
83 // Set the current selected experiment as the test experiment
84 final TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
85 this, fTestExperiment
);
86 fTestExperiment
.experimentSelected(signal
);
89 return fTestExperiment
;
95 protected TmfExperiment
<LttngEvent
> prepareTextExperimentToTest() {
96 if (fTestExperiment
== null) {
97 final String expId
= "testExperiment";
98 final int nbTraces
= 1;
100 // Define traces in experiment
101 @SuppressWarnings("unchecked")
103 ITmfTrace
<LttngEvent
>[] traces
= new ITmfTrace
[nbTraces
];
104 final ITmfTrace
<LttngEvent
> trace
= prepareTextStreamToTest();
107 // create experiment and associate traces
108 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
111 // Set the current selected experiment as the test experiment
112 final TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
113 this, fTestExperiment
);
114 fTestExperiment
.experimentSelected(signal
);
118 return fTestExperiment
;
121 protected LTTngTrace
prepareStreamToTest() {
122 if (frealStream
== null)
124 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(ftracepath_T1
),
126 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
127 final LTTngTrace tmpStream
= new LTTngTrace(null, testfile
.getPath(), false);
128 frealStream
= tmpStream
;
129 } catch (final Exception e
) {
130 System
.out
.println("ERROR : Could not open " + ftracepath_T1
);
134 frealStream
.seekEvent(0L);
139 protected LTTngTextTrace
prepareTextStreamToTest() {
140 if (ftextStream_T1
== null)
142 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()),
143 new Path(fTextTracepath_T1
), null);
144 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
145 final LTTngTextTrace tmpStream
= new LTTngTextTrace(null, testfile
.getPath());
146 ftextStream_T1
= tmpStream
;
148 } catch (final Exception e
) {
149 System
.out
.println("ERROR : Could not open " + fTextTracepath_T1
);
150 ftextStream_T1
= null;
153 ftextStream_T1
.seekEvent(0);
155 return ftextStream_T1
;
158 protected IStateExperimentManager
prepareExperimentContext(
159 final boolean waitForRequest
) {
160 // Create a new Experiment manager
161 final IStateExperimentManager expManager
= StateManagerFactory
162 .getExperimentManager();
163 // Configure the interval to create check points so this can be tested
164 // with medium size files i.e. default is 50000 events
165 StateManagerFactory
.setTraceCheckPointInterval(CHECK_POINT_INTERVAL
);
167 // Lets wait for the request completion to analyse the results
168 LttngCoreProviderFactory
.getEventProvider(0)
169 .setWaitForRequest(waitForRequest
);
177 * , > 0 and between 0 - 31
179 * , > startIdx and between 0 - 31
182 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest(final Class
<T
> k
, final int startIdx
, final int endIdx
) {
183 return prepareEventRequest(k
, startIdx
, endIdx
, true);
190 * , > 0 and between 0 - 31
192 * , > startIdx and between 0 - 31
193 * @param printFirst20
194 * , print the first expected events vs actual events
197 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest(
198 final Class
<T
> k
, final int startIdx
, final int endIdx
, final boolean printFirst20
) {
200 if (!(endIdx
> startIdx
&& startIdx
>= 0 && endIdx
<= 31)) {
201 TraceDebug
.debug("Event request indexes out of bounds");
205 final int DEFAULT_CHUNK
= 1;
208 final TmfTimeRange trange
= new TmfTimeRange(new LttngTimestamp(
209 requestIntervals_T1
[startIdx
]), new LttngTimestamp(
210 requestIntervals_T1
[endIdx
]));
213 validSequence
= true;
214 final TmfEventRequest
<T
> request
= new TmfEventRequest
<T
>(k
, trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
217 public void handleData(final T event
) {
220 .println("Syntheric Event Received is null, after event: "
225 // Listen to only one variant of synthetic event to keep
227 if (event
instanceof LttngSyntheticEvent
)
228 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
)
231 // Validating the orders of the first 20 events
232 if (printFirst20
&& feventCount
< 20) {
233 final 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());
247 * possibly increased by multiple request threads
249 private synchronized void incrementCount() {
254 public void handleCompleted() {
255 // if (isCancelled() || isFailed()) {
256 // // No notification to end request handlers
258 // // notify the associated end request handlers
259 // requestCompleted();
262 // System.out.println("handleCompleted(request:" + startIdx + ") Number of events processed: " + feventCount);
273 * , > 0 and between 0 - 31
275 * , > startIdx and between 0 - 31
276 * @param printFirst20
277 * , print the first expected events vs actual events
280 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest2(
281 final Class
<T
> k
, final int startIdx
, final int endIdx
, final boolean printFirst20
) {
283 if (!(endIdx
> startIdx
&& startIdx
>= 0 && endIdx
<= 31)) {
284 TraceDebug
.debug("Event request indexes out of bounds");
288 final int DEFAULT_CHUNK
= 1;
291 final TmfTimeRange trange
= new TmfTimeRange(new LttngTimestamp(
292 requestIntervals_T1
[startIdx
]), new LttngTimestamp(
293 requestIntervals_T1
[endIdx
]));
296 validSequence
= true;
297 final TmfEventRequest
<T
> request
= new TmfEventRequest
<T
>(k
, trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
300 public void handleData(final T event
) {
303 .println("Syntheric Event Received is null, after event: "
308 // Listen to only one variant of synthetic event to keep
310 if (event
instanceof LttngSyntheticEvent
)
311 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
)
314 // Validating the orders of the first 20 events
315 if (printFirst20
&& feventCount
< 20) {
316 final long timevalue
= event
.getTimestamp().getValue();
317 if (timevalue
!= expectedEvents_T1
[feventCount
]) {
318 validSequence
= false;
319 System
.out
.println("Expected Event: "
320 + expectedEvents_T1
[feventCount
] + " actual: "
321 + event
.getTimestamp().getValue());
323 System
.out
.println("Synthetic Event: " + feventCount
324 + " matched expected time");
332 * possibly increased by multiple request threads
334 private synchronized void incrementCount() {
339 public void handleCompleted() {
340 // if (isCancelled() || isFailed()) {
341 // // No notification to end request handlers
343 // // notify the associated end request handlers
344 // requestCompleted();
347 // System.out.println("handleCompleted(request:" + startIdx + ") Number of events processed: " + feventCount);
357 private void fillInExpectedEvents() {
358 expectedEvents_T1
[0] = 13589759412128L;
359 expectedEvents_T1
[1] = 13589759419903L;
360 expectedEvents_T1
[2] = 13589759422785L;
361 expectedEvents_T1
[3] = 13589759425598L;
362 expectedEvents_T1
[4] = 13589759430979L;
363 expectedEvents_T1
[5] = 13589759433694L;
364 expectedEvents_T1
[6] = 13589759436212L;
365 expectedEvents_T1
[7] = 13589759438797L;
366 expectedEvents_T1
[8] = 13589759441253L;
367 expectedEvents_T1
[9] = 13589759444795L;
368 expectedEvents_T1
[10] = 13589759447800L;
369 expectedEvents_T1
[11] = 13589759450836L;
370 expectedEvents_T1
[12] = 13589759453835L;
371 expectedEvents_T1
[13] = 13589759459351L;
372 expectedEvents_T1
[14] = 13589759464411L;
373 expectedEvents_T1
[15] = 13589759467021L;
374 expectedEvents_T1
[16] = 13589759469668L;
375 expectedEvents_T1
[17] = 13589759474938L;
376 expectedEvents_T1
[18] = 13589759477536L;
377 expectedEvents_T1
[19] = 13589759480485L;
381 * Intervals for trace 1, separated %500 + last event
383 private void fillInRequestIntervals() {
384 requestIntervals_T1
[0] = 13589759412128L; /* check point expected */
385 requestIntervals_T1
[1] = 13589763490945L; /* between check points */
386 requestIntervals_T1
[2] = 13589778265041L; /* check point expected */
387 requestIntervals_T1
[3] = 13589783143445L; /* between check points */
388 requestIntervals_T1
[4] = 13589786300104L; /* check point expected */
389 requestIntervals_T1
[5] = 13589790722564L; /* between check points */
390 requestIntervals_T1
[6] = 13589796139823L; /* check point expected */
391 requestIntervals_T1
[7] = 13589800400562L; /* between check points */
392 requestIntervals_T1
[8] = 13589801594374L; /* check point expected */
393 requestIntervals_T1
[9] = 13589802750295L; /* between check points */
394 requestIntervals_T1
[10] = 13589804071157L; /* check point expected */
395 requestIntervals_T1
[11] = 13589810124488L; /* between check points */
396 requestIntervals_T1
[12] = 13589822493183L; /* check point expected */
397 requestIntervals_T1
[13] = 13589824131273L; /* between check points */
398 requestIntervals_T1
[14] = 13589825398284L; /* check point expected */
399 requestIntervals_T1
[15] = 13589826664185L; /* between check points */
400 requestIntervals_T1
[16] = 13589827811998L; /* check point expected */
401 requestIntervals_T1
[17] = 13589828915763L; /* between check points */
402 requestIntervals_T1
[18] = 13589830074220L; /* check point expected */
403 requestIntervals_T1
[19] = 13589831232050L; /* between check points */
404 requestIntervals_T1
[20] = 13589832394049L; /* check point expected */
405 requestIntervals_T1
[21] = 13589833852883L; /* between check points */
406 requestIntervals_T1
[22] = 13589839626892L; /* check point expected */
407 requestIntervals_T1
[23] = 13589849509798L; /* between check points */
408 requestIntervals_T1
[24] = 13589850728538L; /* check point expected */
409 requestIntervals_T1
[25] = 13589851889230L; /* between check points */
410 requestIntervals_T1
[26] = 13589853294800L; /* check point expected */
411 requestIntervals_T1
[27] = 13589859414998L; /* between check points */
412 requestIntervals_T1
[28] = 13589878046089L; /* check point expected */
413 requestIntervals_T1
[29] = 13589886468603L; /* between check points */
414 requestIntervals_T1
[30] = 13589902256918L; /* check point expected */
415 requestIntervals_T1
[31] = 13589906758692L; /* last event in T1 */