1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
/*******************************************************************************
* Copyright (c) 2012, 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Matthew Khouzam - Initial generation with CodePro tools
* Alexandre Montplaisir - Clean up, consolidate redundant tests
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The class <code>CtfTmfTraceTest</code> contains tests for the class
* <code>{@link CtfTmfTrace}</code>.
*
* @author ematkho
* @version 1.0
*/
public class CtfTmfTraceTest {
private static final int TRACE_INDEX = 0;
private static final String PATH = CtfTmfTestTraces.getTestTracePath(TRACE_INDEX);
private CtfTmfTrace fixture;
/**
* Perform pre-test initialization.
*
* @throws TmfTraceException
* If the test trace is not found
*/
@Before
public void setUp() throws TmfTraceException {
assumeTrue(CtfTmfTestTraces.tracesExist());
fixture = new CtfTmfTrace();
fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class);
}
/**
* Perform post-test clean-up.
*/
@After
public void tearDown() {
if (fixture != null) {
fixture.dispose();
}
}
/**
* Run the CtfTmfTrace() constructor test.
*/
@Test
public void testCtfTmfTrace() {
CtfTmfTrace result = new CtfTmfTrace();
assertNotNull(result);
assertNull(result.getEventType());
assertEquals(1000, result.getCacheSize());
assertEquals(0L, result.getNbEvents());
assertEquals(0L, result.getStreamingInterval());
assertNull(result.getResource());
assertEquals(1000, result.getQueueSize());
assertNull(result.getType());
}
/**
* Test the parseEvent() method
*/
@Test
public void testParseEvent() {
ITmfContext ctx = fixture.seekEvent(0);
fixture.getNext(ctx);
CtfTmfEvent event = fixture.parseEvent(ctx);
assertNotNull(event);
}
/**
* Run the void broadcast(TmfSignal) method test.
*/
@Test
public void testBroadcast() {
TmfSignal signal = new TmfEndSynchSignal(1);
fixture.broadcast(signal);
}
/**
* Run the void dispose() method test.
*/
@Test
public void testDispose() {
CtfTmfTrace emptyFixture = new CtfTmfTrace();
emptyFixture.dispose();
}
/**
* Run the int getCacheSize() method test.
*/
@Test
public void testGetCacheSize() {
CtfTmfTrace emptyFixture = new CtfTmfTrace();
int result = emptyFixture.getCacheSize();
assertEquals(1000, result);
}
/**
* Run the ITmfLocation<Comparable> getCurrentLocation() method test.
*/
@Test
public void testGetCurrentLocation() {
CtfLocation result = (CtfLocation) fixture.getCurrentLocation();
assertNull(result);
}
/**
* Test the seekEvent() method with a null location.
*/
@Test
public void testSeekEventLoc_null() {
CtfLocation loc = null;
fixture.seekEvent(loc);
assertNotNull(fixture);
}
/**
* Test the seekEvent() method with a location from a timestamp.
*/
@Test
public void testSeekEventLoc_timetamp(){
CtfLocation loc = new CtfLocation(new CtfTmfTimestamp(0L));
fixture.seekEvent(loc);
assertNotNull(fixture);
}
/**
* Run the ITmfTimestamp getEndTime() method test.
*/
@Test
public void testGetEndTime() {
ITmfTimestamp result = fixture.getEndTime();
assertNotNull(result);
}
/**
* Run the String getEnvironment method test.
*/
@Test
public void testGetEnvValue() {
String key = "tracer_name";
String result = fixture.getTraceProperties().get(key);
assertEquals("\"lttng-modules\"",result);
}
/**
* Run the Class<CtfTmfEvent> getEventType() method test.
*/
@Test
public void testGetEventType() {
Class<ITmfEvent> result = fixture.getEventType();
assertNotNull(result);
}
/**
* Run the double getLocationRatio(ITmfLocation<?>) method test.
*/
@Test
public void testGetLocationRatio() {
final CtfLocationInfo location2 = new CtfLocationInfo(1, 0);
CtfLocation location = new CtfLocation(location2);
double result = fixture.getLocationRatio(location);
assertEquals(Double.NEGATIVE_INFINITY, result, 0.1);
}
/**
* Run the String getName() method test.
*/
@Test
public void testGetName() {
String result = fixture.getName();
assertNotNull(result);
}
/**
* Run the int getNbEnvVars() method test.
*/
@Test
public void testGetNbEnvVars() {
int result = fixture.getTraceProperties().size();
assertEquals(8, result);
}
/**
* Run the long getNbEvents() method test.
*/
@Test
public void testGetNbEvents() {
long result = fixture.getNbEvents();
assertEquals(1L, result);
}
/**
* Run the CtfTmfEvent getNext(ITmfContext) method test.
*/
@Test
public void testGetNext() {
ITmfContext context = fixture.seekEvent(0);
CtfTmfEvent result = fixture.getNext(context);
assertNotNull(result);
}
/**
* Run the String getPath() method test.
*/
@Test
public void testGetPath() {
String result = fixture.getPath();
assertNotNull(result);
}
/**
* Run the IResource getResource() method test.
*/
@Test
public void testGetResource() {
IResource result = fixture.getResource();
assertNull(result);
}
/**
* Run the ITmfTimestamp getStartTime() method test.
*/
@Test
public void testGetStartTime() {
ITmfTimestamp result = fixture.getStartTime();
assertNotNull(result);
}
/**
* Run the long getStreamingInterval() method test.
*/
@Test
public void testGetStreamingInterval() {
long result = fixture.getStreamingInterval();
assertEquals(0L, result);
}
/**
* Run the TmfTimeRange getTimeRange() method test.
*/
@Test
public void testGetTimeRange() {
TmfTimeRange result = fixture.getTimeRange();
assertNotNull(result);
}
/**
* Run the CtfTmfEvent readNextEvent(ITmfContext) method test.
*/
@Test
public void testReadNextEvent() {
ITmfContext context = fixture.seekEvent(0);
CtfTmfEvent result = fixture.getNext(context);
assertNotNull(result);
}
/**
* Run the ITmfContext seekEvent(double) method test.
*/
@Test
public void testSeekEvent_ratio() {
double ratio = 0.99;
ITmfContext result = fixture.seekEvent(ratio);
assertNotNull(result);
}
/**
* Run the ITmfContext seekEvent(long) method test.
*/
@Test
public void testSeekEvent_rank() {
long rank = 1L;
ITmfContext result = fixture.seekEvent(rank);
assertNotNull(result);
}
/**
* Run the ITmfContext seekEvent(ITmfTimestamp) method test.
*/
@Test
public void testSeekEvent_timestamp() {
ITmfTimestamp timestamp = new TmfTimestamp();
ITmfContext result = fixture.seekEvent(timestamp);
assertNotNull(result);
}
/**
* Run the ITmfContext seekEvent(ITmfLocation<?>) method test.
*/
@Test
public void testSeekEvent_location() {
final CtfLocationInfo location2 = new CtfLocationInfo(1L, 0L);
CtfLocation ctfLocation = new CtfLocation(location2);
ITmfContext result = fixture.seekEvent(ctfLocation);
assertNotNull(result);
}
/**
* Run the boolean validate(IProject,String) method test.
*/
@Test
public void testValidate() {
IProject project = null;
String path = PATH;
IStatus result = fixture.validate(project, path);
assertTrue(result.isOK());
}
/**
* Run the boolean hasEvent(final String) method test
*/
@Test
public void testEventLookup() {
assertTrue(fixture.hasEvent("sched_switch"));
assertFalse(fixture.hasEvent("Sched_switch"));
String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
assertTrue(fixture.hasAllEvents(events));
assertTrue(fixture.hasAtLeastOneOfEvents(events));
String[] names = { "inexistent", "sched_switch", "SomeThing" };
assertTrue(fixture.hasAtLeastOneOfEvents(names));
assertFalse(fixture.hasAllEvents(names));
}
}
|