ctf: make SIPIE enums store both key and value
[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));
23ba30ce
MK
87 final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
88 declaration.add(-100, 100, "");
89 sd.addField("Enum", declaration);
04f0148f
MK
90 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
91 bb.getByteBuffer().putInt(100);
92 bb.getByteBuffer().putInt(200);
93 bb.getByteBuffer().putFloat((float) .75);
94 bb.getByteBuffer().put(("Test").getBytes());
95 bb.getByteBuffer().put((byte) 0);
96 bb.getByteBuffer().put((byte) 0);
fbe6fa6f 97 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 98 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
04f0148f
MK
99 assertNull(sipie.getTarget());
100 assertEquals(100, sipie.getTimestampBegin());
101 assertEquals(200, sipie.getTimestampEnd());
102 }
bfe038ff 103
04f0148f
MK
104 /**
105 * Test the constructor
106 *
680f9173 107 * @throws CTFException
04f0148f
MK
108 * exception
109 */
110 @Test
680f9173 111 public void testStreamInputPacketIndexEntryConstructor2() throws CTFException {
04f0148f
MK
112 StructDeclaration sd = new StructDeclaration(8);
113 sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL);
114 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
115 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
116 sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
23ba30ce
MK
117 final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
118 declaration.add(-100, 100, "");
119 sd.addField("Enum", declaration);
04f0148f
MK
120 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
121 bb.getByteBuffer().putInt(100);
122 bb.getByteBuffer().putInt(200);
123 bb.getByteBuffer().putInt(128);
124 bb.getByteBuffer().put(("Test").getBytes());
125 bb.getByteBuffer().put((byte) 0);
126 bb.getByteBuffer().put((byte) 0);
fbe6fa6f 127 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 128 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
04f0148f
MK
129 assertNull(sipie.getTarget());
130 assertEquals(100, sipie.getTimestampBegin());
131 assertEquals(200, sipie.getTimestampEnd());
132 }
866e5b51 133
04f0148f
MK
134 /**
135 * Test the constructor
136 *
680f9173 137 * @throws CTFException
04f0148f
MK
138 * exception
139 */
140 @Test
680f9173 141 public void testStreamInputPacketIndexEntryConstructor3() throws CTFException {
04f0148f
MK
142 StructDeclaration sd = new StructDeclaration(8);
143 sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL);
144 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
145 sd.addField("packet_size", IntegerDeclaration.INT_32B_DECL);
146 sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
23ba30ce
MK
147 final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
148 declaration.add(-100, 100, "");
149 sd.addField("Enum", declaration);
04f0148f 150 sd.addField("intruder", new StructDeclaration(8));
04f0148f
MK
151 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
152 bb.getByteBuffer().putInt(100);
153 bb.getByteBuffer().putInt(200);
154 bb.getByteBuffer().putInt(128);
155 bb.getByteBuffer().put(("Test").getBytes());
156 bb.getByteBuffer().put((byte) 0);
157 bb.getByteBuffer().put((byte) 0);
fbe6fa6f 158 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 159 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
04f0148f
MK
160 assertNull(sipie.getTarget());
161 assertEquals(100, sipie.getTimestampBegin());
162 assertEquals(200, sipie.getTimestampEnd());
163 assertTrue(sipie.includes(150));
164 assertFalse(sipie.includes(10));
165 assertFalse(sipie.includes(250));
166 }
866e5b51 167
04f0148f
MK
168 /**
169 * Test the constructor
170 *
680f9173 171 * @throws CTFException
04f0148f
MK
172 * exception
173 */
174 @Test
680f9173 175 public void testStreamInputPacketIndexEntryConstructor4() throws CTFException {
04f0148f
MK
176 StructDeclaration sd = new StructDeclaration(8);
177 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
178 sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
23ba30ce
MK
179 final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
180 declaration.add(-100, 100, "");
181 sd.addField("Enum", declaration);
04f0148f
MK
182 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
183 bb.getByteBuffer().putInt(0);
184 bb.getByteBuffer().put(("Test").getBytes());
185 bb.getByteBuffer().put((byte) 0);
186 bb.getByteBuffer().put((byte) 0);
fbe6fa6f 187 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 188 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
04f0148f 189 assertNull(sipie.getTarget());
531b0f6a 190 assertEquals(0, sipie.getTimestampBegin());
04f0148f
MK
191 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
192 }
193
194 /**
195 * Test the constructor
196 *
680f9173 197 * @throws CTFException
04f0148f
MK
198 * exception
199 */
200 @Test
680f9173 201 public void testStreamInputPacketIndexEntryConstructor5() throws CTFException {
04f0148f
MK
202 StructDeclaration sd = new StructDeclaration(8);
203 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
204 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
205 sd.addField("device", StringDeclaration.getStringDeclaration(Encoding.ASCII));
23ba30ce
MK
206 final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
207 declaration.add(-100, 100, "");
208 sd.addField("Enum", declaration);
04f0148f
MK
209 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
210 bb.getByteBuffer().putInt(-1);
211 bb.getByteBuffer().putInt(0);
212 bb.getByteBuffer().put(("Test66").getBytes());
213 bb.getByteBuffer().put((byte) 0);
214 bb.getByteBuffer().put((byte) 0);
fbe6fa6f 215 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 216 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
531b0f6a 217 assertEquals(0, sipie.getTimestampBegin());
04f0148f
MK
218 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
219 assertEquals("Test66", sipie.getTarget());
220 assertEquals(66, sipie.getTargetId());
221 }
222
223 /**
224 * Test the constructor
225 *
680f9173 226 * @throws CTFException
04f0148f
MK
227 * exception
228 */
229 @Test
680f9173 230 public void testStreamInputPacketIndexEntryConstructor6() throws CTFException {
04f0148f
MK
231 StructDeclaration sd = new StructDeclaration(8);
232 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
233 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
234 sd.addField("cpu_id", IntegerDeclaration.INT_32B_DECL);
235 sd.addField("events_discarded", IntegerDeclaration.INT_32B_DECL);
04f0148f
MK
236 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
237 bb.getByteBuffer().putInt(-1);
238 bb.getByteBuffer().putInt(0);
239 bb.getByteBuffer().putInt(66);
240 bb.getByteBuffer().putInt(300);
fbe6fa6f 241 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
1d92f045 242 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 100);
531b0f6a 243 assertEquals(0, sipie.getTimestampBegin());
04f0148f
MK
244 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
245 assertEquals("CPU66", sipie.getTarget());
246 assertEquals(66, sipie.getTargetId());
247 assertEquals(200, sipie.getLostEvents());
248 assertEquals(0, sipie.getOffsetBits());
249 assertEquals(1024, sipie.getPacketSizeBits());
250 }
251
8033e89c
MK
252 /**
253 * Test the constructor
254 *
255 * @throws CTFException
256 * exception
257 */
258 @Test
259 public void testStreamInputPacketIndexEntryConstructor7() throws CTFException {
260 StructDeclaration sd = new StructDeclaration(8);
261 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
262 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
263 final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8));
264 declaration.add(313, 315, "CPU-PI");
265 sd.addField("device", declaration);
8033e89c
MK
266 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
267 bb.getByteBuffer().putInt(-1);
268 bb.getByteBuffer().putInt(0);
269 bb.getByteBuffer().putShort((short) 314);
270 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
271 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
531b0f6a 272 assertEquals(0, sipie.getTimestampBegin());
8033e89c
MK
273 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
274 assertEquals("CPU-PI", sipie.getTarget());
275 assertEquals(314, sipie.getTargetId());
276 }
277
278 /**
279 * Test the constructor
280 *
281 * @throws CTFException
282 * exception
283 */
284 @Test
285 public void testStreamInputPacketIndexEntryConstructor8() throws CTFException {
286 StructDeclaration sd = new StructDeclaration(8);
287 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
288 sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
289 final IDeclaration declaration = IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8);
290 sd.addField("device", declaration);
8033e89c
MK
291 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
292 bb.getByteBuffer().putInt(-1);
293 bb.getByteBuffer().putInt(0);
294 bb.getByteBuffer().putShort((short) 314);
295 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
296 ICTFPacketDescriptor sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0);
531b0f6a 297 assertEquals(0, sipie.getTimestampBegin());
8033e89c
MK
298 assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd());
299 assertEquals("314", sipie.getTarget());
300 assertEquals(314, sipie.getTargetId());
301 }
302
04f0148f
MK
303 /**
304 * Run the String toString() method test.
305 *
680f9173 306 * @throws CTFException
04f0148f
MK
307 * won't happen
308 */
309 @Test
680f9173 310 public void testToString() throws CTFException {
04f0148f
MK
311
312 String expectedResult = "StreamInputPacketIndexEntry [offsetBits=0, timestampBegin=0, timestampEnd=0]";
313 StructDeclaration sd = new StructDeclaration(8);
314 sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL);
315 sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
04f0148f
MK
316 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
317
fbe6fa6f 318 StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
04f0148f 319 assertEquals(expectedResult, new StreamInputPacketIndexEntry(0, sdef, 10000, 0).toString());
866e5b51
FC
320 }
321}
This page took 0.077263 seconds and 5 git commands to generate.