1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.trace
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertFalse
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertNull
;
18 import static org
.junit
.Assert
.assertTrue
;
20 import java
.nio
.ByteBuffer
;
21 import java
.nio
.ByteOrder
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.event
.io
.BitBuffer
;
25 import org
.eclipse
.tracecompass
.ctf
.core
.event
.scope
.ILexicalScope
;
26 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.Encoding
;
27 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.EnumDeclaration
;
28 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.FloatDeclaration
;
29 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.IDeclaration
;
30 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.IntegerDeclaration
;
31 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StringDeclaration
;
32 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StructDeclaration
;
33 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StructDefinition
;
34 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.ICTFPacketDescriptor
;
35 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.trace
.StreamInputPacketIndexEntry
;
36 import org
.junit
.Before
;
37 import org
.junit
.Test
;
40 * The class <code>StreamInputPacketIndexEntryTest</code> contains tests for the
41 * class <code>{@link StreamInputPacketIndexEntry}</code>.
44 * @version $Revision: 1.0 $
46 public class CTFStreamInputPacketIndexEntryTest
{
48 private ICTFPacketDescriptor fixture
;
51 * Perform pre-test initialization.
55 fixture
= new StreamInputPacketIndexEntry(1L, 1L);
59 * Run the StreamInputPacketIndexEntry(long) constructor test.
62 public void testStreamInputPacketIndexEntry_1() {
63 String expectedResult
= "StreamInputPacketIndexEntry [offsetBits=1, " +
64 "timestampBegin=" + Long
.MIN_VALUE
+
65 ", timestampEnd=" + Long
.MAX_VALUE
+
68 assertNotNull(fixture
);
69 assertEquals(expectedResult
, fixture
.toString());
70 assertEquals(1, fixture
.getOffsetBits());
71 assertEquals(0, fixture
.getOffsetBytes());
75 * Test the constructor
77 * @throws CTFException
81 public void testStreamInputPacketIndexEntryConstructor1() throws CTFException
{
82 StructDeclaration sd
= new StructDeclaration(8);
83 sd
.addField("timestamp_begin", IntegerDeclaration
.INT_32B_DECL
);
84 sd
.addField("timestamp_end", IntegerDeclaration
.INT_32B_DECL
);
85 sd
.addField("load_factor", new FloatDeclaration(24, 8, ByteOrder
.nativeOrder(), 8));
86 sd
.addField("target", StringDeclaration
.getStringDeclaration(Encoding
.ASCII
));
87 sd
.addField("Enum", new EnumDeclaration(IntegerDeclaration
.INT_8_DECL
));
88 @SuppressWarnings("null")
89 BitBuffer bb
= new BitBuffer(ByteBuffer
.allocate(128));
90 bb
.getByteBuffer().putInt(100);
91 bb
.getByteBuffer().putInt(200);
92 bb
.getByteBuffer().putFloat((float) .75);
93 bb
.getByteBuffer().put(("Test").getBytes());
94 bb
.getByteBuffer().put((byte) 0);
95 bb
.getByteBuffer().put((byte) 0);
96 StructDefinition sdef
= sd
.createDefinition(null, ILexicalScope
.PACKET_HEADER
, bb
);
97 ICTFPacketDescriptor sipie
= new StreamInputPacketIndexEntry(0, sdef
, 128, 0);
98 assertNull(sipie
.getTarget());
99 assertEquals(100, sipie
.getTimestampBegin());
100 assertEquals(200, sipie
.getTimestampEnd());
104 * Test the constructor
106 * @throws CTFException
110 public void testStreamInputPacketIndexEntryConstructor2() throws CTFException
{
111 StructDeclaration sd
= new StructDeclaration(8);
112 sd
.addField("timestamp_begin", IntegerDeclaration
.INT_32B_DECL
);
113 sd
.addField("timestamp_end", IntegerDeclaration
.INT_32B_DECL
);
114 sd
.addField("content_size", IntegerDeclaration
.INT_32B_DECL
);
115 sd
.addField("target", StringDeclaration
.getStringDeclaration(Encoding
.ASCII
));
116 sd
.addField("Enum", new EnumDeclaration(IntegerDeclaration
.INT_8_DECL
));
117 @SuppressWarnings("null")
118 BitBuffer bb
= new BitBuffer(ByteBuffer
.allocate(128));
119 bb
.getByteBuffer().putInt(100);
120 bb
.getByteBuffer().putInt(200);
121 bb
.getByteBuffer().putInt(128);
122 bb
.getByteBuffer().put(("Test").getBytes());
123 bb
.getByteBuffer().put((byte) 0);
124 bb
.getByteBuffer().put((byte) 0);
125 StructDefinition sdef
= sd
.createDefinition(null, ILexicalScope
.PACKET_HEADER
, bb
);
126 ICTFPacketDescriptor sipie
= new StreamInputPacketIndexEntry(0, sdef
, 128, 0);
127 assertNull(sipie
.getTarget());
128 assertEquals(100, sipie
.getTimestampBegin());
129 assertEquals(200, sipie
.getTimestampEnd());
133 * Test the constructor
135 * @throws CTFException
139 public void testStreamInputPacketIndexEntryConstructor3() throws CTFException
{
140 StructDeclaration sd
= new StructDeclaration(8);
141 sd
.addField("timestamp_begin", IntegerDeclaration
.INT_32B_DECL
);
142 sd
.addField("timestamp_end", IntegerDeclaration
.INT_32B_DECL
);
143 sd
.addField("packet_size", IntegerDeclaration
.INT_32B_DECL
);
144 sd
.addField("target", StringDeclaration
.getStringDeclaration(Encoding
.ASCII
));
145 sd
.addField("Enum", new EnumDeclaration(IntegerDeclaration
.INT_8_DECL
));
146 sd
.addField("intruder", new StructDeclaration(8));
147 @SuppressWarnings("null")
148 BitBuffer bb
= new BitBuffer(ByteBuffer
.allocate(128));
149 bb
.getByteBuffer().putInt(100);
150 bb
.getByteBuffer().putInt(200);
151 bb
.getByteBuffer().putInt(128);
152 bb
.getByteBuffer().put(("Test").getBytes());
153 bb
.getByteBuffer().put((byte) 0);
154 bb
.getByteBuffer().put((byte) 0);
155 StructDefinition sdef
= sd
.createDefinition(null, ILexicalScope
.PACKET_HEADER
, bb
);
156 ICTFPacketDescriptor sipie
= new StreamInputPacketIndexEntry(0, sdef
, 128, 0);
157 assertNull(sipie
.getTarget());
158 assertEquals(100, sipie
.getTimestampBegin());
159 assertEquals(200, sipie
.getTimestampEnd());
160 assertTrue(sipie
.includes(150));
161 assertFalse(sipie
.includes(10));
162 assertFalse(sipie
.includes(250));
166 * Test the constructor
168 * @throws CTFException
172 public void testStreamInputPacketIndexEntryConstructor4() throws CTFException
{
173 StructDeclaration sd
= new StructDeclaration(8);
174 sd
.addField("content_size", IntegerDeclaration
.INT_32B_DECL
);
175 sd
.addField("target", StringDeclaration
.getStringDeclaration(Encoding
.ASCII
));
176 sd
.addField("Enum", new EnumDeclaration(IntegerDeclaration
.INT_8_DECL
));
177 @SuppressWarnings("null")
178 BitBuffer bb
= new BitBuffer(ByteBuffer
.allocate(128));
179 bb
.getByteBuffer().putInt(0);
180 bb
.getByteBuffer().put(("Test").getBytes());
181 bb
.getByteBuffer().put((byte) 0);
182 bb
.getByteBuffer().put((byte) 0);
183 StructDefinition sdef
= sd
.createDefinition(null, ILexicalScope
.PACKET_HEADER
, bb
);
184 ICTFPacketDescriptor sipie
= new StreamInputPacketIndexEntry(0, sdef
, 128, 0);
185 assertNull(sipie
.getTarget());
186 assertEquals(Long
.MIN_VALUE
, sipie
.getTimestampBegin());
187 assertEquals(Long
.MAX_VALUE
, sipie
.getTimestampEnd());
191 * Test the constructor
193 * @throws CTFException
197 public void testStreamInputPacketIndexEntryConstructor5() throws CTFException
{
198 StructDeclaration sd
= new StructDeclaration(8);
199 sd
.addField("timestamp_end", IntegerDeclaration
.INT_32B_DECL
);
200 sd
.addField("content_size", IntegerDeclaration
.INT_32B_DECL
);
201 sd
.addField("device", StringDeclaration
.getStringDeclaration(Encoding
.ASCII
));
202 sd
.addField("Enum", new EnumDeclaration(IntegerDeclaration
.INT_8_DECL
));
203 @SuppressWarnings("null")
204 BitBuffer bb
= new BitBuffer(ByteBuffer
.allocate(128));
205 bb
.getByteBuffer().putInt(-1);
206 bb
.getByteBuffer().putInt(0);
207 bb
.getByteBuffer().put(("Test66").getBytes());
208 bb
.getByteBuffer().put((byte) 0);
209 bb
.getByteBuffer().put((byte) 0);
210 StructDefinition sdef
= sd
.createDefinition(null, ILexicalScope
.PACKET_HEADER
, bb
);
211 ICTFPacketDescriptor sipie
= new StreamInputPacketIndexEntry(0, sdef
, 128, 0);
212 assertEquals(Long
.MIN_VALUE
, sipie
.getTimestampBegin());
213 assertEquals(Long
.MAX_VALUE
, sipie
.getTimestampEnd());
214 assertEquals("Test66", sipie
.getTarget());
215 assertEquals(66, sipie
.getTargetId());
219 * Test the constructor
221 * @throws CTFException
225 public void testStreamInputPacketIndexEntryConstructor6() throws CTFException
{
226 StructDeclaration sd
= new StructDeclaration(8);
227 sd
.addField("timestamp_end", IntegerDeclaration
.INT_32B_DECL
);
228 sd
.addField("content_size", IntegerDeclaration
.INT_32B_DECL
);
229 sd
.addField("cpu_id", IntegerDeclaration
.INT_32B_DECL
);
230 sd
.addField("events_discarded", IntegerDeclaration
.INT_32B_DECL
);
231 @SuppressWarnings("null")
232 BitBuffer bb
= new BitBuffer(ByteBuffer
.allocate(128));
233 bb
.getByteBuffer().putInt(-1);
234 bb
.getByteBuffer().putInt(0);
235 bb
.getByteBuffer().putInt(66);
236 bb
.getByteBuffer().putInt(300);
237 StructDefinition sdef
= sd
.createDefinition(null, ILexicalScope
.PACKET_HEADER
, bb
);
238 ICTFPacketDescriptor sipie
= new StreamInputPacketIndexEntry(0, sdef
, 128, 100);
239 assertEquals(Long
.MIN_VALUE
, sipie
.getTimestampBegin());
240 assertEquals(Long
.MAX_VALUE
, sipie
.getTimestampEnd());
241 assertEquals("CPU66", sipie
.getTarget());
242 assertEquals(66, sipie
.getTargetId());
243 assertEquals(200, sipie
.getLostEvents());
244 assertEquals(0, sipie
.getOffsetBits());
245 assertEquals(1024, sipie
.getPacketSizeBits());
249 * Test the constructor
251 * @throws CTFException
255 public void testStreamInputPacketIndexEntryConstructor7() throws CTFException
{
256 StructDeclaration sd
= new StructDeclaration(8);
257 sd
.addField("timestamp_end", IntegerDeclaration
.INT_32B_DECL
);
258 sd
.addField("content_size", IntegerDeclaration
.INT_32B_DECL
);
259 final EnumDeclaration declaration
= new EnumDeclaration(IntegerDeclaration
.createDeclaration(16, false, 10, ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, "", 8));
260 declaration
.add(313, 315, "CPU-PI");
261 sd
.addField("device", declaration
);
262 @SuppressWarnings("null")
263 BitBuffer bb
= new BitBuffer(ByteBuffer
.allocate(128));
264 bb
.getByteBuffer().putInt(-1);
265 bb
.getByteBuffer().putInt(0);
266 bb
.getByteBuffer().putShort((short) 314);
267 StructDefinition sdef
= sd
.createDefinition(null, ILexicalScope
.PACKET_HEADER
, bb
);
268 ICTFPacketDescriptor sipie
= new StreamInputPacketIndexEntry(0, sdef
, 128, 0);
269 assertEquals(Long
.MIN_VALUE
, sipie
.getTimestampBegin());
270 assertEquals(Long
.MAX_VALUE
, sipie
.getTimestampEnd());
271 assertEquals("CPU-PI", sipie
.getTarget());
272 assertEquals(314, sipie
.getTargetId());
276 * Test the constructor
278 * @throws CTFException
282 public void testStreamInputPacketIndexEntryConstructor8() throws CTFException
{
283 StructDeclaration sd
= new StructDeclaration(8);
284 sd
.addField("timestamp_end", IntegerDeclaration
.INT_32B_DECL
);
285 sd
.addField("content_size", IntegerDeclaration
.INT_32B_DECL
);
286 final IDeclaration declaration
= IntegerDeclaration
.createDeclaration(16, false, 10, ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, "", 8);
287 sd
.addField("device", declaration
);
288 @SuppressWarnings("null")
289 BitBuffer bb
= new BitBuffer(ByteBuffer
.allocate(128));
290 bb
.getByteBuffer().putInt(-1);
291 bb
.getByteBuffer().putInt(0);
292 bb
.getByteBuffer().putShort((short) 314);
293 StructDefinition sdef
= sd
.createDefinition(null, ILexicalScope
.PACKET_HEADER
, bb
);
294 ICTFPacketDescriptor sipie
= new StreamInputPacketIndexEntry(0, sdef
, 128, 0);
295 assertEquals(Long
.MIN_VALUE
, sipie
.getTimestampBegin());
296 assertEquals(Long
.MAX_VALUE
, sipie
.getTimestampEnd());
297 assertEquals("314", sipie
.getTarget());
298 assertEquals(314, sipie
.getTargetId());
302 * Run the String toString() method test.
304 * @throws CTFException
308 public void testToString() throws CTFException
{
310 String expectedResult
= "StreamInputPacketIndexEntry [offsetBits=0, timestampBegin=0, timestampEnd=0]";
311 StructDeclaration sd
= new StructDeclaration(8);
312 sd
.addField("timestamp_begin", IntegerDeclaration
.INT_32B_DECL
);
313 sd
.addField("timestamp_end", IntegerDeclaration
.INT_32B_DECL
);
314 @SuppressWarnings("null")
315 BitBuffer bb
= new BitBuffer(ByteBuffer
.allocate(128));
317 StructDefinition sdef
= sd
.createDefinition(null, ILexicalScope
.PACKET_HEADER
, bb
);
318 assertEquals(expectedResult
, new StreamInputPacketIndexEntry(0, sdef
, 10000, 0).toString());