Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7ce28057bf0087680b215981e5adbf6ac717ce0c (plain) (blame)
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
package org.eclipse.linuxtools.lttng.core.tests.trace;

import java.io.File;
import java.net.URL;

import junit.framework.TestCase;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTextTrace;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
import org.osgi.framework.FrameworkUtil;

/*
 Functions tested here :
 public LTTngTextTrace(String path) throws Exception
 public LTTngTextTrace(String path, boolean skipIndexing) throws Exception

 public TmfTraceContext seekLocation(Object location) {
 public TmfTraceContext seekEvent(TmfTimestamp timestamp) {
 public TmfTraceContext seekEvent(long position) {

 public TmfEvent getNextEvent(TmfTraceContext context) {
 public Object getCurrentLocation() {

 public LttngEvent parseEvent(TmfTraceContext context) {

 public int getCpuNumber() {
 */

@SuppressWarnings("nls")
public class LTTngTextTraceTest extends TestCase {

    private final static String tracepath1 = "traceset/trace-15316events_nolost_newformat.txt";
    private final static String wrongTracePath = "/somewhere/that/does/not/exist";

    private final static int traceCpuNumber = 1;

    private final static boolean skipIndexing = true;

    private final static long firstEventTimestamp = 13589759412128L;
    private final static long secondEventTimestamp = 13589759419903L;
    private final static Long locationAfterFirstEvent = 311L;

    private final static String tracename = "traceset/trace-15316events_nolost_newformat";

    private final static long indexToSeekFirst = 0;
    private final static Long locationToSeekFirst = 0L;
    private final static long contextValueAfterFirstEvent = 13589759412128L;
    private final static String firstEventReference = tracename + "/metadata_0";

    private final static long timestampToSeekTest1 = 13589826657302L;
    private final static Long indexToSeekTest1 = 7497L;
    private final static long locationToSeekTest1 = 2177044;
    private final static long contextValueAfterSeekTest1 = 13589826657302L;
    private final static String seek1EventReference = tracename + "/vm_state_0";

    private final static long timestampToSeekLast = 13589906758692L;
    private final static Long indexToSeekLast = 15315L;
    private final static long locationToSeekLast = 4420634;
    private final static long contextValueAfterSeekLast = 13589906758692L;
    private final static String seekLastEventReference = tracename + "/kernel_0";

    private static LTTngTextTrace testStream = null;

    private synchronized LTTngTextTrace prepareStreamToTest() {
        if (testStream == null) {
            try {
                URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(tracepath1), null);
                File testfile = new File(FileLocator.toFileURL(location).toURI());
                LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getName(), testfile.getPath());
                testStream = tmpStream;
            } catch (Exception e) {
                System.out.println("ERROR : Could not open " + tracepath1);
                testStream = null;
            }
        } else {
            testStream.seekEvent(0);
        }

        return testStream;
    }

    public void testTraceConstructorFailure() {
        // Default constructor
        // Test constructor with argument on a wrong tracepath, skipping
        // indexing
        try {
            LTTngTextTrace testStream = new LTTngTextTrace("wrong", wrongTracePath, skipIndexing);
            fail("Construction with wrong tracepath should fail!");
            testStream.dispose();
        } catch (Exception e) {
        }
    }
/*
    public void testTraceConstructor() {
        // Test constructor with argument on a correct tracepath, skipping
        // indexing
        try {
            URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
            File testfile = new File(FileLocator.toFileURL(location).toURI());
            LTTngTextTrace testStream = new LTTngTextTrace(testfile.getPath(), skipIndexing);
            testStream.dispose();
        } catch (Exception e) {
            fail("Construction with correct tracepath failed!");
        }
    }
*/
    public void testGetNextEvent() {
        ITmfEvent tmpEvent = null;
        LTTngTextTrace testStream1 = prepareStreamToTest();

        TmfContext tmpContext = new TmfContext(null, 0);
        // We should be at the beginning of the trace, so we will just read the
        // first event now
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpEvent is null after first getNextEvent()", null, tmpEvent);
        assertEquals("tmpEvent has wrong timestamp after first getNextEvent()", firstEventTimestamp, tmpEvent.getTimestamp().getValue());

        // Read the next event as well
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpEvent is null after second getNextEvent()", null, tmpEvent);
        assertEquals("tmpEvent has wrong timestamp after second getNextEvent()", secondEventTimestamp, tmpEvent.getTimestamp().getValue());
    }

    public void testParseEvent() {
        ITmfEvent tmpEvent = null;
        LTTngTextTrace testStream1 = prepareStreamToTest();

        TmfContext tmpContext = new TmfContext(null, 0);
        // We should be at the beginning of the trace, so we will just parse the
        // first event now
        tmpEvent = testStream1.parseEvent(tmpContext);
        assertNotSame("tmpEvent is null after first parseEvent()", null, tmpEvent);
        assertEquals("tmpEvent has wrong timestamp after first parseEvent()", firstEventTimestamp, tmpEvent.getTimestamp().getValue());

        // Use parseEvent again. Should be the same event
        tmpEvent = testStream1.parseEvent(tmpContext);
        assertNotSame("tmpEvent is null after first parseEvent()", null, tmpEvent);
        assertEquals("tmpEvent has wrong timestamp after first parseEvent()", firstEventTimestamp, tmpEvent.getTimestamp().getValue());
    }

    public void testSeekEventTimestamp() {
        ITmfEvent tmpEvent = null;
        ITmfContext tmpContext = new TmfContext(null, 0);
        LTTngTextTrace testStream1 = prepareStreamToTest();

        // We should be at the beginning of the trace, we will seek at a certain
        // timestamp
        tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekTest1, (byte) -9, 0));
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext);
        assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekTest1, tmpEvent.getTimestamp().getValue());
        assertNotSame("tmpEvent is null after first seekEvent()", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference.contains((String) tmpEvent.getReference()));

        // Seek to the last timestamp
        tmpContext = testStream1.seekEvent(new TmfTimestamp(timestampToSeekLast, (byte) -9, 0));
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpContext is null after seekEvent() to last", null, tmpContext);
        assertEquals("tmpContext has wrong timestamp after seekEvent() to last", contextValueAfterSeekLast, tmpEvent.getTimestamp().getValue());
        assertNotSame("tmpEvent is null after seekEvent() to last ", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference.contains((String) tmpEvent.getReference()));

        // Seek to the first timestamp (startTime)
        tmpContext = testStream1.seekEvent(new TmfTimestamp(firstEventTimestamp, (byte) -9, 0));
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpEvent is null after seekEvent() to start ", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains((String) tmpEvent.getReference()));
        assertNotSame("tmpContext is null after seekEvent() to first", null, tmpContext);
        assertEquals("tmpContext has wrong timestamp after seekEvent() to first", contextValueAfterFirstEvent, tmpEvent.getTimestamp().getValue());
    }

    public void testSeekEventIndex() {
        ITmfEvent tmpEvent = null;
        ITmfContext tmpContext = new TmfContext(null, 0);
        LTTngTextTrace testStream1 = prepareStreamToTest();

        // We should be at the beginning of the trace, we will seek at a certain
        // timestamp
        tmpContext = testStream1.seekEvent(indexToSeekTest1);
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext);
        assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekTest1, tmpEvent.getTimestamp().getValue());
        assertNotSame("tmpEvent is null after first seekEvent()", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after first seekEvent()", seek1EventReference.contains((String) tmpEvent.getReference()));

        // Seek to the last timestamp
        tmpContext = testStream1.seekEvent(indexToSeekLast);
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext);
        assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterSeekLast, tmpEvent.getTimestamp().getValue());
        assertNotSame("tmpEvent is null after seekEvent() to last ", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after seekEvent() to last", seekLastEventReference.contains((String) tmpEvent.getReference()));

        // Seek to the first timestamp (startTime)
        tmpContext = testStream1.seekEvent(indexToSeekFirst);
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpContext is null after first seekEvent()", null, tmpContext);
        assertEquals("tmpContext has wrong timestamp after first seekEvent()", contextValueAfterFirstEvent, tmpEvent.getTimestamp().getValue());
        assertNotSame("tmpEvent is null after seekEvent() to start ", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after seekEvent() to start", firstEventReference.contains((String) tmpEvent.getReference()));
    }

    public void testSeekLocation() {
        ITmfEvent tmpEvent = null;
        TmfContext tmpContext = new TmfContext(null, 0);
        LTTngTextTrace testStream1 = prepareStreamToTest();

        // We should be at the beginning of the trace, we will seek at a certain
        // timestamp
        tmpContext = testStream1.seekLocation(new TmfLocation<Long>(locationToSeekTest1));
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpContext is null after first seekLocation()", null, tmpContext);
        assertEquals("tmpContext has wrong timestamp after first seekLocation()", contextValueAfterSeekTest1, tmpEvent.getTimestamp().getValue());
        assertNotSame("tmpEvent is null after first seekLocation()", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after first seekLocation()", seek1EventReference.contains((String) tmpEvent.getReference()));

        // Seek to the last timestamp
        tmpContext = testStream1.seekLocation(new TmfLocation<Long>(locationToSeekLast));
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpContext is null after first seekLocation()", null, tmpContext);
        assertEquals("tmpContext has wrong timestamp after first seekLocation()", contextValueAfterSeekLast, tmpEvent.getTimestamp().getValue());
        assertNotSame("tmpEvent is null after seekLocation() to last ", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after seekLocation() to last", seekLastEventReference.contains((String) tmpEvent.getReference()));

        // Seek to the first timestamp (startTime)
        tmpContext = testStream1.seekLocation(new TmfLocation<Long>(locationToSeekFirst));
        tmpEvent = testStream1.getNextEvent(tmpContext);
        assertNotSame("tmpContext is null after first seekLocation()", null, tmpContext);
        assertEquals("tmpContext has wrong timestamp after first seekLocation()", contextValueAfterFirstEvent, tmpEvent.getTimestamp().getValue());
        assertNotSame("tmpEvent is null after seekLocation() to start ", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after seekLocation() to start", firstEventReference.contains((String) tmpEvent.getReference()));
    }

    @SuppressWarnings("unchecked")
    public void testGetter() {
        ITmfEvent tmpEvent = null;
        LTTngTextTrace testStream1 = prepareStreamToTest();
        TmfContext tmpContext = new TmfContext(null, 0);

        // Move to the first event to have something to play with
        tmpEvent = testStream1.parseEvent(tmpContext);

        // Test current event
        assertNotSame("tmpEvent is null after first event", null, tmpEvent);
        assertTrue("tmpEvent has wrong reference after first event", firstEventReference.contains((String) tmpEvent.getReference()));
        assertNotSame("tmpContext is null after first seekEvent()", null, testStream1.getCurrentLocation());
        assertEquals("tmpContext has wrong timestamp after first seekEvent()", locationAfterFirstEvent, ((TmfLocation<Long>) testStream1.getCurrentLocation()).getLocation());
        // Test CPU number of the trace
        assertSame("getCpuNumber() return wrong number of cpu", traceCpuNumber, testStream1.getCpuNumber());
    }

    public void testToString() {
        LTTngTextTrace testStream1 = prepareStreamToTest();

        // Move to the first event to have something to play with
        testStream1.parseEvent(new TmfContext(null, 0));

        // Just make sure toString() does not return null or the java reference
        assertNotSame("toString returned null", null, testStream1.toString());
        assertNotSame("toString is not overridded!", testStream1.getClass().getName() + '@' + Integer.toHexString(testStream1.hashCode()), testStream1.toString());
    }

}

Back to the top