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();
65 protected TmfExperiment
<LttngEvent
> prepareExperimentToTest() {
66 if (fTestExperiment
== null) {
67 String expId
= "testExperiment";
70 // Define traces in experiment
71 ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
72 ITmfTrace trace
= prepareStreamToTest();
75 // create experiment and associate traces
76 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
78 // fTestExperiment.indexExperiment(waitForCompletion);
80 // Set the current selected experiment as the test experiment
81 TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
82 this, fTestExperiment
);
83 fTestExperiment
.experimentSelected(signal
);
86 return fTestExperiment
;
92 protected TmfExperiment
<LttngEvent
> prepareTextExperimentToTest() {
93 if (fTestExperiment
== null) {
94 String expId
= "testExperiment";
97 // Define traces in experiment
98 ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
99 ITmfTrace trace
= prepareTextStreamToTest();
102 // create experiment and associate traces
103 fTestExperiment
= new TmfExperiment
<LttngEvent
>(LttngEvent
.class,
106 // Set the current selected experiment as the test experiment
107 TmfExperimentSelectedSignal
<LttngEvent
> signal
= new TmfExperimentSelectedSignal
<LttngEvent
>(
108 this, fTestExperiment
);
109 fTestExperiment
.experimentSelected(signal
);
113 return fTestExperiment
;
116 protected LTTngTrace
prepareStreamToTest() {
117 if (frealStream
== null) {
119 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(ftracepath_T1
),
121 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
122 LTTngTrace tmpStream
= new LTTngTrace(testfile
.getPath());
123 frealStream
= tmpStream
;
124 } catch (Exception e
) {
125 System
.out
.println("ERROR : Could not open " + ftracepath_T1
);
129 frealStream
.seekEvent(0L);
135 protected LTTngTextTrace
prepareTextStreamToTest() {
136 if (ftextStream_T1
== null) {
138 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(),
139 new Path(fTextTracepath_T1
), null);
140 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
141 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath());
142 ftextStream_T1
= tmpStream
;
144 } catch (Exception e
) {
145 System
.out
.println("ERROR : Could not open " + fTextTracepath_T1
);
146 ftextStream_T1
= null;
149 ftextStream_T1
.seekEvent(0);
152 return ftextStream_T1
;
155 protected IStateExperimentManager
prepareExperimentContext(
156 boolean waitForRequest
) {
157 // Create a new Experiment manager
158 IStateExperimentManager expManager
= StateManagerFactory
159 .getExperimentManager();
160 // Configure the interval to create check points so this can be tested
161 // with medium size files i.e. default is 50000 events
162 StateManagerFactory
.setTraceCheckPointInterval(CHECK_POINT_INTERVAL
);
164 // Lets wait for the request completion to analyse the results
165 LttngCoreProviderFactory
.getEventProvider()
166 .setWaitForRequest(waitForRequest
);
174 * , > 0 and between 0 - 31
176 * , > startIdx and between 0 - 31
179 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest(Class
<T
> k
, int startIdx
, int endIdx
) {
180 return prepareEventRequest(k
, startIdx
, endIdx
, true);
187 * , > 0 and between 0 - 31
189 * , > startIdx and between 0 - 31
190 * @param printFirst20
191 * , print the first expected events vs actual events
194 protected <T
extends LttngEvent
> TmfEventRequest
<T
> prepareEventRequest(
195 Class
<T
> k
, int startIdx
, int endIdx
, final boolean printFirst20
) {
197 if (!(endIdx
> startIdx
&& startIdx
>= 0 && endIdx
<= 31)) {
198 TraceDebug
.debug("Event request indexes out of bounds");
202 int DEFAULT_CHUNK
= 1;
205 TmfTimeRange trange
= new TmfTimeRange(new LttngTimestamp(
206 requestIntervals_T1
[startIdx
]), new LttngTimestamp(
207 requestIntervals_T1
[endIdx
]));
210 validSequence
= true;
211 TmfEventRequest
<T
> request
= new TmfEventRequest
<T
>(k
,
212 trange
, TmfDataRequest
.ALL_DATA
, DEFAULT_CHUNK
) {
215 public void handleData() {
216 T
[] result
= getData();
218 T event
= (result
.length
> 0) ? result
[0] : null;
221 .println("Syntheric Event Received is null, after event: "
226 // Listen to only one variant of synthetic event to keep
228 if (event
instanceof LttngSyntheticEvent
) {
229 if (((LttngSyntheticEvent
) event
).getSynType() != SequenceInd
.BEFORE
) {
234 // Validating the orders of the first 20 events
235 if (printFirst20
&& feventCount
< 20) {
236 long timevalue
= event
.getTimestamp().getValue();
237 if (timevalue
!= expectedEvents_T1
[feventCount
]) {
238 validSequence
= false;
239 System
.out
.println("Expected Event: "
240 + expectedEvents_T1
[feventCount
] + " actual: "
241 + event
.getTimestamp().getValue());
243 System
.out
.println("Synthetic Event: " + feventCount
244 + " matched expected time");
253 * possibly increased by multiple request threads
255 private synchronized void incrementCount() {
260 public void handleCompleted() {
261 // if (isCancelled() || isFailed()) {
262 // // No notification to end request handlers
264 // // notify the associated end request handlers
265 // requestCompleted();
268 System
.out
.println("Number of events processed x: "
279 private void fillInExpectedEvents() {
280 expectedEvents_T1
[0] = 13589759412128L;
281 expectedEvents_T1
[1] = 13589759419903L;
282 expectedEvents_T1
[2] = 13589759422785L;
283 expectedEvents_T1
[3] = 13589759425598L;
284 expectedEvents_T1
[4] = 13589759430979L;
285 expectedEvents_T1
[5] = 13589759433694L;
286 expectedEvents_T1
[6] = 13589759436212L;
287 expectedEvents_T1
[7] = 13589759438797L;
288 expectedEvents_T1
[8] = 13589759441253L;
289 expectedEvents_T1
[9] = 13589759444795L;
290 expectedEvents_T1
[10] = 13589759447800L;
291 expectedEvents_T1
[11] = 13589759450836L;
292 expectedEvents_T1
[12] = 13589759453835L;
293 expectedEvents_T1
[13] = 13589759459351L;
294 expectedEvents_T1
[14] = 13589759464411L;
295 expectedEvents_T1
[15] = 13589759467021L;
296 expectedEvents_T1
[16] = 13589759469668L;
297 expectedEvents_T1
[17] = 13589759474938L;
298 expectedEvents_T1
[18] = 13589759477536L;
299 expectedEvents_T1
[19] = 13589759480485L;
303 * Intervals for trace 1, separated %500 + last event
305 private void fillInRequestIntervals() {
306 requestIntervals_T1
[0] = 13589759412128L; /* check point expected */
307 requestIntervals_T1
[1] = 13589763490945L; /* between check points */
308 requestIntervals_T1
[2] = 13589778265041L; /* check point expected */
309 requestIntervals_T1
[3] = 13589783143445L; /* between check points */
310 requestIntervals_T1
[4] = 13589786300104L; /* check point expected */
311 requestIntervals_T1
[5] = 13589790722564L; /* between check points */
312 requestIntervals_T1
[6] = 13589796139823L; /* check point expected */
313 requestIntervals_T1
[7] = 13589800400562L; /* between check points */
314 requestIntervals_T1
[8] = 13589801594374L; /* check point expected */
315 requestIntervals_T1
[9] = 13589802750295L; /* between check points */
316 requestIntervals_T1
[10] = 13589804071157L; /* check point expected */
317 requestIntervals_T1
[11] = 13589810124488L; /* between check points */
318 requestIntervals_T1
[12] = 13589822493183L; /* check point expected */
319 requestIntervals_T1
[13] = 13589824131273L; /* between check points */
320 requestIntervals_T1
[14] = 13589825398284L; /* check point expected */
321 requestIntervals_T1
[15] = 13589826664185L; /* between check points */
322 requestIntervals_T1
[16] = 13589827811998L; /* check point expected */
323 requestIntervals_T1
[17] = 13589828915763L; /* between check points */
324 requestIntervals_T1
[18] = 13589830074220L; /* check point expected */
325 requestIntervals_T1
[19] = 13589831232050L; /* between check points */
326 requestIntervals_T1
[20] = 13589832394049L; /* check point expected */
327 requestIntervals_T1
[21] = 13589833852883L; /* between check points */
328 requestIntervals_T1
[22] = 13589839626892L; /* check point expected */
329 requestIntervals_T1
[23] = 13589849509798L; /* between check points */
330 requestIntervals_T1
[24] = 13589850728538L; /* check point expected */
331 requestIntervals_T1
[25] = 13589851889230L; /* between check points */
332 requestIntervals_T1
[26] = 13589853294800L; /* check point expected */
333 requestIntervals_T1
[27] = 13589859414998L; /* between check points */
334 requestIntervals_T1
[28] = 13589878046089L; /* check point expected */
335 requestIntervals_T1
[29] = 13589886468603L; /* between check points */
336 requestIntervals_T1
[30] = 13589902256918L; /* check point expected */
337 requestIntervals_T1
[31] = 13589906758692L; /* last event in T1 */