Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1f555636b56d3abf7d495cc9d799cc0e68bf7c4f (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
package org.eclipse.linuxtools.lttng.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.lttng.event.LttngLocation;
import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin;
import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.trace.TmfContext;

/*
 Functions tested here :
 	public LTTngTrace(String path) throws Exception
    public LTTngTrace(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 LTTngTraceTest extends TestCase {
	
    private final static String tracepath1="traceset/trace-15316events_nolost_newformat";
    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 = 13589759412128L;
    
    private final static String tracename = "traceset/trace-15316events_nolost_newformat";
    
    private final static long	indexToSeekFirst = 0;
    private final static Long   locationToSeekFirst = 13589759412128L;
    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 = 13589826657302L;
    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 = 13589906758692L;
    private final static long   contextValueAfterSeekLast = 13589906758692L;
    private final static String seekLastEventReference = tracename + "/kernel_0"; 

    private static LTTngTrace testStream = null;
    private LTTngTrace prepareStreamToTest() {
		if (testStream == null) {
			try {
				URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
				File testfile = new File(FileLocator.toFileURL(location).toURI());
				LTTngTrace tmpStream = new LTTngTrace(testfile.getPath(), false);
				testStream = tmpStream;
			} 
			catch (Exception e) {
				System.out.println("ERROR : Could not open " + tracepath1);
				testStream = null;
			}
		}
		else {
			testStream.seekEvent(0L);
		}
		
		
		return testStream;
	}

    public void testTraceConstructors() {
		@SuppressWarnings("unused")
		LTTngTrace testStream1 = null;
        
		// Default constructor
		// Test constructor with argument on a wrong tracepath, skipping indexing
        try {
        		testStream1 = new LTTngTrace(wrongTracePath, skipIndexing);
                fail("Construction with wrong tracepath should fail!");
        }
        catch( Exception e) { 
        }
        
        // 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());
            testStream1 = new LTTngTrace(testfile.getPath(), skipIndexing);
        }
        catch( Exception e) {
                fail("Construction with correct tracepath failed!");
        }
        System.out.println("Test completed");
	}
	
	public void testGetNextEvent() {
		TmfEvent tmpEvent = null;
		LTTngTrace 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,(long)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,(long)tmpEvent.getTimestamp().getValue() );
	}
	
	public void testParseEvent() {
		TmfEvent tmpEvent = null;
		LTTngTrace 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,(long)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,(long)tmpEvent.getTimestamp().getValue() );
	}
	
	public void testSeekEventTimestamp() {
		TmfEvent tmpEvent = null;
		TmfContext tmpContext = new TmfContext(null, 0);
		LTTngTrace 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,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
		assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
		assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) );
		
		// 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,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
		assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
		assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) );
		
		// 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",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
		assertNotSame("tmpContext is null after seekEvent() to first",null,tmpContext );
		assertEquals("tmpContext has wrong timestamp after seekEvent() to first",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
	}
	
	public void testSeekEventIndex() {
		TmfEvent tmpEvent = null;
		TmfContext tmpContext = new TmfContext(null, 0);
		LTTngTrace 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,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
		assertNotSame("tmpEvent is null after first seekEvent()",null,tmpEvent );
		assertTrue("tmpEvent has wrong reference after first seekEvent()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) );
		
		// 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,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
		assertNotSame("tmpEvent is null after seekEvent() to last ",null,tmpEvent );
		assertTrue("tmpEvent has wrong reference after seekEvent() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) );
		
		// 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,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
		assertNotSame("tmpEvent is null after seekEvent() to start ",null,tmpEvent );
		assertTrue("tmpEvent has wrong reference after seekEvent() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
	}
	
	public void testSeekLocation() {
		TmfEvent tmpEvent = null;
		TmfContext tmpContext = new TmfContext(null, 0);
		LTTngTrace testStream1 = prepareStreamToTest();
		
		// We should be at the beginning of the trace, we will seek at a certain timestamp
		tmpContext = testStream1.seekLocation(new LttngLocation(locationToSeekTest1));
		tmpEvent = testStream1.getNextEvent(tmpContext);
		assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
		assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekTest1,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
		assertNotSame("tmpEvent is null after first seekLocation()",null,tmpEvent );
		assertTrue("tmpEvent has wrong reference after first seekLocation()", ((String)tmpEvent.getReference().getReference()).contains(seek1EventReference) );
		
		// Seek to the last timestamp
		tmpContext = testStream1.seekLocation(new LttngLocation(locationToSeekLast));
		tmpEvent = testStream1.getNextEvent(tmpContext);
		assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
		assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterSeekLast,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
		assertNotSame("tmpEvent is null after seekLocation() to last ",null,tmpEvent );
		assertTrue("tmpEvent has wrong reference after seekLocation() to last",((String)tmpEvent.getReference().getReference()).contains(seekLastEventReference) );
		
		// Seek to the first timestamp (startTime)
		tmpContext = testStream1.seekLocation(new LttngLocation(locationToSeekFirst));
		tmpEvent = testStream1.getNextEvent(tmpContext);
		assertNotSame("tmpContext is null after first seekLocation()",null,tmpContext );
		assertEquals("tmpContext has wrong timestamp after first seekLocation()",contextValueAfterFirstEvent,(long)((TmfTimestamp)tmpEvent.getTimestamp()).getValue() );
		assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent );
		assertTrue("tmpEvent has wrong reference after seekLocation() to start",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
	}
	
	public void testGetter() {
    	TmfEvent tmpEvent = null;
    	LTTngTrace testStream1 = prepareStreamToTest();
		
		// Move to the first event to have something to play with
		tmpEvent = testStream1.parseEvent( new TmfContext(null, 0));
		
		// Test current event
		assertNotSame("tmpEvent is null after first event",null,tmpEvent );
		assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
		assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() );
		assertTrue("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent.equals( ((LttngLocation)testStream1.getCurrentLocation()).getOperationTimeValue()) );
		
		// Test CPU number of the trace
		assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() );
    }
    
	public void testToString() {
		LTTngTrace 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