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
.experiment
.TmfExperiment
;
22 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequest
;
23 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
24 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
25 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
27 public abstract class LttngTestPreparation
extends TestCase
{
28 // ========================================================================
30 // ========================================================================
31 private final static String ftracepath_T1
= "traceset/trace-15316events_nolost_newformat";
32 final static String fTextTracepath_T1
= "traceset/trace-15316events_nolost_newformat.txt";
34 private static final Long CHECK_POINT_INTERVAL
= 1000L;
36 final Long
[] expectedEvents_T1
= new Long
[20];
37 final Long
[] requestIntervals_T1
= new Long
[32];
39 static LTTngTextTrace ftextStream_T1
= null;
40 private static LTTngTrace frealStream
= null;
42 private TmfExperiment
<LttngEvent
> fTestExperiment
= null;
43 protected volatile int feventCount
= 0;
44 protected boolean validSequence
= true;
46 public LttngTestPreparation() {
51 public LttngTestPreparation(String name
) {
56 protected void init() {
57 fillInRequestIntervals();
58 fillInExpectedEvents();
62 protected LTTngTextTrace
prepareTextStreamToTest() {
63 if (ftextStream_T1
== null) {
65 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin()
66 .getBundle(), new Path(fTextTracepath_T1
), null);
67 File testfile
= new File(FileLocator
.toFileURL(location
)
69 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
71 ftextStream_T1
= tmpStream
;
73 } catch (Exception e
) {
74 System
.out
.println("ERROR : Could not open " + fTextTracepath_T1
);
75 ftextStream_T1
= null;
78 ftextStream_T1
.seekEvent(0);
81 return ftextStream_T1
;
87 protected TmfExperiment
<LttngEvent
> prepareTextExperimentToTest() {
88 if (fTestExperiment
== null) {
89 String expId
= "testExperiment";
92 // Define traces in experiment
93 ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
94 ITmfTrace trace
= prepareTextStreamToTest();
97 // create experiment and associate traces
98 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
101 // Set the current selected experiment as the test experiment
102 TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
103 this, fTestExperiment
);
104 fTestExperiment
.experimentSelected(signal
);
108 return fTestExperiment
;
111 protected LTTngTrace
prepareStreamToTest() {
112 if (frealStream
== null) {
114 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin()
115 .getBundle(), new Path(ftracepath_T1
), null);
116 File testfile
= new File(FileLocator
.toFileURL(location
)
118 LTTngTrace tmpStream
= new LTTngTrace(testfile
.getPath());
119 frealStream
= tmpStream
;
120 } catch (Exception e
) {
121 System
.out
.println("ERROR : Could not open " + ftracepath_T1
);
125 frealStream
.seekEvent(0L);
134 protected TmfExperiment
<LttngEvent
> prepareExperimentToTest() {
135 if (fTestExperiment
== null) {
136 String expId
= "testExperiment";
139 // Define traces in experiment
140 ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
141 ITmfTrace trace
= prepareStreamToTest();
144 // create experiment and associate traces
145 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
147 // fTestExperiment.indexExperiment(waitForCompletion);
149 // Set the current selected experiment as the test experiment
150 TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
151 this, fTestExperiment
);
152 fTestExperiment
.experimentSelected(signal
);
155 return fTestExperiment
;
158 protected IStateExperimentManager
prepareExperimentContext(
159 boolean waitForRequest
) {
160 // Create a new Experiment manager
161 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()
169 .setWaitForRequest(waitForRequest
);
177 * , > 0 and between 0 - 31
179 * , > startIdx and between 0 - 31
182 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest(Class
<T
> k
, int startIdx
, 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 Class
<T
> k
, int startIdx
, int endIdx
, final boolean printFirst20
) {
200 if (!(endIdx
> startIdx
&& startIdx
>= 0 && endIdx
<= 31)) {
201 TraceDebug
.debug("Event request indexes out of bounds");
205 int DEFAULT_CHUNK
= 1;
208 TmfTimeRange trange
= new TmfTimeRange(new LttngTimestamp(
209 requestIntervals_T1
[startIdx
]), new LttngTimestamp(
210 requestIntervals_T1
[endIdx
]));
213 validSequence
= true;
214 TmfEventRequest
<T
> request
= new TmfEventRequest
<T
>(k
,
215 trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
218 public void handleData() {
219 T
[] result
= getData();
221 T event
= (result
.length
> 0) ? result
[0] : null;
224 .println("Syntheric Event Received is null, after event: "
229 // Listen to only one variant of synthetic event to keep
231 if (event
instanceof LttngSyntheticEvent
) {
232 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
) {
237 // Validating the orders of the first 20 events
238 if (printFirst20
&& feventCount
< 20) {
239 long timevalue
= event
.getTimestamp().getValue();
240 if (timevalue
!= expectedEvents_T1
[feventCount
]) {
241 validSequence
= false;
242 System
.out
.println("Expected Event: "
243 + expectedEvents_T1
[feventCount
] + " actual: "
244 + event
.getTimestamp().getValue());
246 System
.out
.println("Synthetic Event: " + feventCount
247 + " matched expected time");
256 * possibly increased by multiple request threads
258 private synchronized void incrementCount() {
263 public void handleCompleted() {
264 // if (isCancelled() || isFailed()) {
265 // // No notification to end request handlers
267 // // notify the associated end request handlers
268 // requestCompleted();
271 System
.out
.println("Number of events processed x: "
282 private void fillInExpectedEvents() {
283 expectedEvents_T1
[0] = 13589759412128L;
284 expectedEvents_T1
[1] = 13589759419903L;
285 expectedEvents_T1
[2] = 13589759422785L;
286 expectedEvents_T1
[3] = 13589759425598L;
287 expectedEvents_T1
[4] = 13589759430979L;
288 expectedEvents_T1
[5] = 13589759433694L;
289 expectedEvents_T1
[6] = 13589759436212L;
290 expectedEvents_T1
[7] = 13589759438797L;
291 expectedEvents_T1
[8] = 13589759441253L;
292 expectedEvents_T1
[9] = 13589759444795L;
293 expectedEvents_T1
[10] = 13589759447800L;
294 expectedEvents_T1
[11] = 13589759450836L;
295 expectedEvents_T1
[12] = 13589759453835L;
296 expectedEvents_T1
[13] = 13589759459351L;
297 expectedEvents_T1
[14] = 13589759464411L;
298 expectedEvents_T1
[15] = 13589759467021L;
299 expectedEvents_T1
[16] = 13589759469668L;
300 expectedEvents_T1
[17] = 13589759474938L;
301 expectedEvents_T1
[18] = 13589759477536L;
302 expectedEvents_T1
[19] = 13589759480485L;
306 * Intervals for trace 1, separated %500 + last event
308 private void fillInRequestIntervals() {
309 requestIntervals_T1
[0] = 13589759412128L; /* check point expected */
310 requestIntervals_T1
[1] = 13589763490945L; /* between check points */
311 requestIntervals_T1
[2] = 13589778265041L; /* check point expected */
312 requestIntervals_T1
[3] = 13589783143445L; /* between check points */
313 requestIntervals_T1
[4] = 13589786300104L; /* check point expected */
314 requestIntervals_T1
[5] = 13589790722564L; /* between check points */
315 requestIntervals_T1
[6] = 13589796139823L; /* check point expected */
316 requestIntervals_T1
[7] = 13589800400562L; /* between check points */
317 requestIntervals_T1
[8] = 13589801594374L; /* check point expected */
318 requestIntervals_T1
[9] = 13589802750295L; /* between check points */
319 requestIntervals_T1
[10] = 13589804071157L; /* check point expected */
320 requestIntervals_T1
[11] = 13589810124488L; /* between check points */
321 requestIntervals_T1
[12] = 13589822493183L; /* check point expected */
322 requestIntervals_T1
[13] = 13589824131273L; /* between check points */
323 requestIntervals_T1
[14] = 13589825398284L; /* check point expected */
324 requestIntervals_T1
[15] = 13589826664185L; /* between check points */
325 requestIntervals_T1
[16] = 13589827811998L; /* check point expected */
326 requestIntervals_T1
[17] = 13589828915763L; /* between check points */
327 requestIntervals_T1
[18] = 13589830074220L; /* check point expected */
328 requestIntervals_T1
[19] = 13589831232050L; /* between check points */
329 requestIntervals_T1
[20] = 13589832394049L; /* check point expected */
330 requestIntervals_T1
[21] = 13589833852883L; /* between check points */
331 requestIntervals_T1
[22] = 13589839626892L; /* check point expected */
332 requestIntervals_T1
[23] = 13589849509798L; /* between check points */
333 requestIntervals_T1
[24] = 13589850728538L; /* check point expected */
334 requestIntervals_T1
[25] = 13589851889230L; /* between check points */
335 requestIntervals_T1
[26] = 13589853294800L; /* check point expected */
336 requestIntervals_T1
[27] = 13589859414998L; /* between check points */
337 requestIntervals_T1
[28] = 13589878046089L; /* check point expected */
338 requestIntervals_T1
[29] = 13589886468603L; /* between check points */
339 requestIntervals_T1
[30] = 13589902256918L; /* check point expected */
340 requestIntervals_T1
[31] = 13589906758692L; /* last event in T1 */