ctf: Depend on the tracecompass-test-traces project
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / CTFStreamInputPacketIndexEntryTest.java
CommitLineData
4bd7f2db 1/*******************************************************************************
04f0148f 2 * Copyright (c) 2013, 2015 Ericsson
4bd7f2db
AM
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
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
f357bcd4 12package org.eclipse.tracecompass.ctf.core.tests.trace;
866e5b51
FC
13
14import static org.junit.Assert.assertEquals;
04f0148f 15import static org.junit.Assert.assertFalse;
866e5b51 16import static org.junit.Assert.assertNotNull;
04f0148f
MK
17import static org.junit.Assert.assertNull;
18import static org.junit.Assert.assertTrue;
866e5b51 19
04f0148f
MK
20import java.nio.ByteBuffer;
21import java.nio.ByteOrder;
22
680f9173 23import org.eclipse.tracecompass.ctf.core.CTFException;
04f0148f 24import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
fbe6fa6f 25import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
04f0148f
MK
26import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
27import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration;
28import org.eclipse.tracecompass.ctf.core.event.types.FloatDeclaration;
8033e89c 29import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
04f0148f
MK
30import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
31import org.eclipse.tracecompass.ctf.core.event.types.StringDeclaration;
32import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
33import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
1d92f045 34import org.eclipse.tracecompass.ctf.core.trace.ICTFPacketDescriptor;
f357bcd4 35import org.eclipse.tracecompass.internal.ctf.core.trace.StreamInputPacketIndexEntry;
866e5b51
FC
36import org.junit.Before;
37import org.junit.Test;
38
39/**
40 * The class <code>StreamInputPacketIndexEntryTest</code> contains tests for the
41 * class <code>{@link StreamInputPacketIndexEntry}</code>.
ce2388e0 42 *
866e5b51
FC
43 * @author ematkho
44 * @version $Revision: 1.0 $
45 */
d84419e1 46public class CTFStreamInputPacketIndexEntryTest {
866e5b51 47
1d92f045 48 private ICTFPacketDescriptor fixture;
866e5b51 49
866e5b51
FC
50 /**
51 * Perform pre-test initialization.
52 */
53 @Before
54 public void setUp() {
04f0148f 55 fixture = new StreamInputPacketIndexEntry(1L, 1L);
866e5b51
FC
56 }
57
866e5b51
FC
58 /**
59 * Run the StreamInputPacketIndexEntry(long) constructor test.
60 */
61 @Test
62 public void testStreamInputPacketIndexEntry_1() {
04f0148f 63 String expectedResult = "StreamInputPacketIndexEntry [offsetBits=1, " +
531b0f6a 64 "timestampBegin=" + 0 +
04f0148f
MK
65 ", timestampEnd=" + Long.MAX_VALUE +
66 "]";
866e5b51
FC
67
68 assertNotNull(fixture);
69 assertEquals(expectedResult, fixture.toString());
04f0148f
MK
70 assertEquals(1, fixture.getOffsetBits());
71 assertEquals(0, fixture.getOffsetBytes());
866e5b51
FC
72 }
73
74 /**
04f0148f
MK
75 * Test the constructor
76 *
680f9173 77 * @throws CTFException
04f0148f 78 * exception
866e5b51
FC
79 */
80 @Test
680f9173 81 public void testStreamInputPacketIndexEntryConstructor1() throws CTFException {
04f0148f
MK
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);
fbe6fa6f 96 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 97 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
04f0148f
MK
98 assertNull(sipie.getTarget());
99 assertEquals(100, sipie.getTimestampBegin());
100 assertEquals(200, sipie.getTimestampEnd());
101 }
bfe038ff 102
04f0148f
MK
103 /**
104 * Test the constructor
105 *
680f9173 106 * @throws CTFException
04f0148f
MK
107 * exception
108 */
109 @Test
680f9173 110 public void testStreamInputPacketIndexEntryConstructor2() throws CTFException {
04f0148f
MK
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);
fbe6fa6f 125 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 126 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
04f0148f
MK
127 assertNull(sipie.getTarget());
128 assertEquals(100, sipie.getTimestampBegin());
129 assertEquals(200, sipie.getTimestampEnd());
130 }
866e5b51 131
04f0148f
MK
132 /**
133 * Test the constructor
134 *
680f9173 135 * @throws CTFException
04f0148f
MK
136 * exception
137 */
138 @Test
680f9173 139 public void testStreamInputPacketIndexEntryConstructor3() throws CTFException {
04f0148f
MK
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);
fbe6fa6f 155 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 156 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
04f0148f
MK
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));
163 }
866e5b51 164
04f0148f
MK
165 /**
166 * Test the constructor
167 *
680f9173 168 * @throws CTFException
04f0148f
MK
169 * exception
170 */
171 @Test
680f9173 172 public void testStreamInputPacketIndexEntryConstructor4() throws CTFException {
04f0148f
MK
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);
fbe6fa6f 183 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 184 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
04f0148f 185 assertNull(sipie.getTarget());
531b0f6a 186 assertEquals(0, sipie.getTimestampBegin());
04f0148f
MK
187 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
188 }
189
190 /**
191 * Test the constructor
192 *
680f9173 193 * @throws CTFException
04f0148f
MK
194 * exception
195 */
196 @Test
680f9173 197 public void testStreamInputPacketIndexEntryConstructor5() throws CTFException {
04f0148f
MK
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);
fbe6fa6f 210 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 211 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
531b0f6a 212 assertEquals(0, sipie.getTimestampBegin());
04f0148f
MK
213 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
214 assertEquals("Test66", sipie.getTarget());
215 assertEquals(66, sipie.getTargetId());
216 }
217
218 /**
219 * Test the constructor
220 *
680f9173 221 * @throws CTFException
04f0148f
MK
222 * exception
223 */
224 @Test
680f9173 225 public void testStreamInputPacketIndexEntryConstructor6() throws CTFException {
04f0148f
MK
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);
fbe6fa6f 237 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 238 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 100);
531b0f6a 239 assertEquals(0, sipie.getTimestampBegin());
04f0148f
MK
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());
246 }
247
8033e89c
MK
248 /**
249 * Test the constructor
250 *
251 * @throws CTFException
252 * exception
253 */
254 @Test
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);
531b0f6a 269 assertEquals(0, sipie.getTimestampBegin());
8033e89c
MK
270 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
271 assertEquals("CPU-PI", sipie.getTarget());
272 assertEquals(314, sipie.getTargetId());
273 }
274
275 /**
276 * Test the constructor
277 *
278 * @throws CTFException
279 * exception
280 */
281 @Test
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);
531b0f6a 295 assertEquals(0, sipie.getTimestampBegin());
8033e89c
MK
296 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
297 assertEquals("314", sipie.getTarget());
298 assertEquals(314, sipie.getTargetId());
299 }
300
04f0148f
MK
301 /**
302 * Run the String toString() method test.
303 *
680f9173 304 * @throws CTFException
04f0148f
MK
305 * won't happen
306 */
307 @Test
680f9173 308 public void testToString() throws CTFException {
04f0148f
MK
309
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));
316
fbe6fa6f 317 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
04f0148f 318 assertEquals(expectedResult, new StreamInputPacketIndexEntry(0, sdef, 10000, 0).toString());
866e5b51
FC
319 }
320}
This page took 0.07626 seconds and 5 git commands to generate.