Commit | Line | Data |
---|---|---|
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 | 12 | package org.eclipse.tracecompass.ctf.core.tests.trace; |
866e5b51 FC |
13 | |
14 | import static org.junit.Assert.assertEquals; | |
04f0148f | 15 | import static org.junit.Assert.assertFalse; |
866e5b51 | 16 | import static org.junit.Assert.assertNotNull; |
04f0148f MK |
17 | import static org.junit.Assert.assertNull; |
18 | import static org.junit.Assert.assertTrue; | |
866e5b51 | 19 | |
04f0148f MK |
20 | import java.nio.ByteBuffer; |
21 | import java.nio.ByteOrder; | |
22 | ||
680f9173 | 23 | import org.eclipse.tracecompass.ctf.core.CTFException; |
04f0148f | 24 | import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; |
fbe6fa6f | 25 | import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; |
04f0148f MK |
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.IntegerDeclaration; | |
30 | import org.eclipse.tracecompass.ctf.core.event.types.StringDeclaration; | |
31 | import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration; | |
32 | import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition; | |
f357bcd4 | 33 | import org.eclipse.tracecompass.internal.ctf.core.trace.StreamInputPacketIndexEntry; |
866e5b51 FC |
34 | import org.junit.Before; |
35 | import org.junit.Test; | |
36 | ||
37 | /** | |
38 | * The class <code>StreamInputPacketIndexEntryTest</code> contains tests for the | |
39 | * class <code>{@link StreamInputPacketIndexEntry}</code>. | |
ce2388e0 | 40 | * |
866e5b51 FC |
41 | * @author ematkho |
42 | * @version $Revision: 1.0 $ | |
43 | */ | |
d84419e1 | 44 | public class CTFStreamInputPacketIndexEntryTest { |
866e5b51 FC |
45 | |
46 | private StreamInputPacketIndexEntry fixture; | |
47 | ||
866e5b51 FC |
48 | /** |
49 | * Perform pre-test initialization. | |
50 | */ | |
51 | @Before | |
52 | public void setUp() { | |
04f0148f | 53 | fixture = new StreamInputPacketIndexEntry(1L, 1L); |
866e5b51 FC |
54 | } |
55 | ||
866e5b51 FC |
56 | /** |
57 | * Run the StreamInputPacketIndexEntry(long) constructor test. | |
58 | */ | |
59 | @Test | |
60 | public void testStreamInputPacketIndexEntry_1() { | |
04f0148f MK |
61 | String expectedResult = "StreamInputPacketIndexEntry [offsetBits=1, " + |
62 | "timestampBegin=" + Long.MIN_VALUE + | |
63 | ", timestampEnd=" + Long.MAX_VALUE + | |
64 | "]"; | |
866e5b51 FC |
65 | |
66 | assertNotNull(fixture); | |
67 | assertEquals(expectedResult, fixture.toString()); | |
04f0148f MK |
68 | assertEquals(1, fixture.getOffsetBits()); |
69 | assertEquals(0, fixture.getOffsetBytes()); | |
866e5b51 FC |
70 | } |
71 | ||
72 | /** | |
04f0148f MK |
73 | * Test the constructor |
74 | * | |
680f9173 | 75 | * @throws CTFException |
04f0148f | 76 | * exception |
866e5b51 FC |
77 | */ |
78 | @Test | |
680f9173 | 79 | public void testStreamInputPacketIndexEntryConstructor1() throws CTFException { |
04f0148f MK |
80 | StructDeclaration sd = new StructDeclaration(8); |
81 | sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL); | |
82 | sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); | |
83 | sd.addField("load_factor", new FloatDeclaration(24, 8, ByteOrder.nativeOrder(), 8)); | |
84 | sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII)); | |
85 | sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); | |
86 | @SuppressWarnings("null") | |
87 | BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); | |
88 | bb.getByteBuffer().putInt(100); | |
89 | bb.getByteBuffer().putInt(200); | |
90 | bb.getByteBuffer().putFloat((float) .75); | |
91 | bb.getByteBuffer().put(("Test").getBytes()); | |
92 | bb.getByteBuffer().put((byte) 0); | |
93 | bb.getByteBuffer().put((byte) 0); | |
fbe6fa6f | 94 | StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); |
04f0148f MK |
95 | StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); |
96 | assertNull(sipie.getTarget()); | |
97 | assertEquals(100, sipie.getTimestampBegin()); | |
98 | assertEquals(200, sipie.getTimestampEnd()); | |
99 | } | |
bfe038ff | 100 | |
04f0148f MK |
101 | /** |
102 | * Test the constructor | |
103 | * | |
680f9173 | 104 | * @throws CTFException |
04f0148f MK |
105 | * exception |
106 | */ | |
107 | @Test | |
680f9173 | 108 | public void testStreamInputPacketIndexEntryConstructor2() throws CTFException { |
04f0148f MK |
109 | StructDeclaration sd = new StructDeclaration(8); |
110 | sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL); | |
111 | sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); | |
112 | sd.addField("content_size", IntegerDeclaration.INT_32B_DECL); | |
113 | sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII)); | |
114 | sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); | |
115 | @SuppressWarnings("null") | |
116 | BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); | |
117 | bb.getByteBuffer().putInt(100); | |
118 | bb.getByteBuffer().putInt(200); | |
119 | bb.getByteBuffer().putInt(128); | |
120 | bb.getByteBuffer().put(("Test").getBytes()); | |
121 | bb.getByteBuffer().put((byte) 0); | |
122 | bb.getByteBuffer().put((byte) 0); | |
fbe6fa6f | 123 | StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); |
04f0148f MK |
124 | StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); |
125 | assertNull(sipie.getTarget()); | |
126 | assertEquals(100, sipie.getTimestampBegin()); | |
127 | assertEquals(200, sipie.getTimestampEnd()); | |
128 | } | |
866e5b51 | 129 | |
04f0148f MK |
130 | /** |
131 | * Test the constructor | |
132 | * | |
680f9173 | 133 | * @throws CTFException |
04f0148f MK |
134 | * exception |
135 | */ | |
136 | @Test | |
680f9173 | 137 | public void testStreamInputPacketIndexEntryConstructor3() throws CTFException { |
04f0148f MK |
138 | StructDeclaration sd = new StructDeclaration(8); |
139 | sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL); | |
140 | sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); | |
141 | sd.addField("packet_size", IntegerDeclaration.INT_32B_DECL); | |
142 | sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII)); | |
143 | sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); | |
144 | sd.addField("intruder", new StructDeclaration(8)); | |
145 | @SuppressWarnings("null") | |
146 | BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); | |
147 | bb.getByteBuffer().putInt(100); | |
148 | bb.getByteBuffer().putInt(200); | |
149 | bb.getByteBuffer().putInt(128); | |
150 | bb.getByteBuffer().put(("Test").getBytes()); | |
151 | bb.getByteBuffer().put((byte) 0); | |
152 | bb.getByteBuffer().put((byte) 0); | |
fbe6fa6f | 153 | StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); |
04f0148f MK |
154 | StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); |
155 | assertNull(sipie.getTarget()); | |
156 | assertEquals(100, sipie.getTimestampBegin()); | |
157 | assertEquals(200, sipie.getTimestampEnd()); | |
158 | assertTrue(sipie.includes(150)); | |
159 | assertFalse(sipie.includes(10)); | |
160 | assertFalse(sipie.includes(250)); | |
161 | } | |
866e5b51 | 162 | |
04f0148f MK |
163 | /** |
164 | * Test the constructor | |
165 | * | |
680f9173 | 166 | * @throws CTFException |
04f0148f MK |
167 | * exception |
168 | */ | |
169 | @Test | |
680f9173 | 170 | public void testStreamInputPacketIndexEntryConstructor4() throws CTFException { |
04f0148f MK |
171 | StructDeclaration sd = new StructDeclaration(8); |
172 | sd.addField("content_size", IntegerDeclaration.INT_32B_DECL); | |
173 | sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII)); | |
174 | sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); | |
175 | @SuppressWarnings("null") | |
176 | BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); | |
177 | bb.getByteBuffer().putInt(0); | |
178 | bb.getByteBuffer().put(("Test").getBytes()); | |
179 | bb.getByteBuffer().put((byte) 0); | |
180 | bb.getByteBuffer().put((byte) 0); | |
fbe6fa6f | 181 | StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); |
04f0148f MK |
182 | StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); |
183 | assertNull(sipie.getTarget()); | |
184 | assertEquals(Long.MIN_VALUE, sipie.getTimestampBegin()); | |
185 | assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd()); | |
186 | } | |
187 | ||
188 | /** | |
189 | * Test the constructor | |
190 | * | |
680f9173 | 191 | * @throws CTFException |
04f0148f MK |
192 | * exception |
193 | */ | |
194 | @Test | |
680f9173 | 195 | public void testStreamInputPacketIndexEntryConstructor5() throws CTFException { |
04f0148f MK |
196 | StructDeclaration sd = new StructDeclaration(8); |
197 | sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); | |
198 | sd.addField("content_size", IntegerDeclaration.INT_32B_DECL); | |
199 | sd.addField("device", StringDeclaration.getStringDeclaration(Encoding.ASCII)); | |
200 | sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL)); | |
201 | @SuppressWarnings("null") | |
202 | BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); | |
203 | bb.getByteBuffer().putInt(-1); | |
204 | bb.getByteBuffer().putInt(0); | |
205 | bb.getByteBuffer().put(("Test66").getBytes()); | |
206 | bb.getByteBuffer().put((byte) 0); | |
207 | bb.getByteBuffer().put((byte) 0); | |
fbe6fa6f | 208 | StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); |
04f0148f MK |
209 | StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); |
210 | assertEquals(Long.MIN_VALUE, sipie.getTimestampBegin()); | |
211 | assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd()); | |
212 | assertEquals("Test66", sipie.getTarget()); | |
213 | assertEquals(66, sipie.getTargetId()); | |
214 | } | |
215 | ||
216 | /** | |
217 | * Test the constructor | |
218 | * | |
680f9173 | 219 | * @throws CTFException |
04f0148f MK |
220 | * exception |
221 | */ | |
222 | @Test | |
680f9173 | 223 | public void testStreamInputPacketIndexEntryConstructor6() throws CTFException { |
04f0148f MK |
224 | StructDeclaration sd = new StructDeclaration(8); |
225 | sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); | |
226 | sd.addField("content_size", IntegerDeclaration.INT_32B_DECL); | |
227 | sd.addField("cpu_id", IntegerDeclaration.INT_32B_DECL); | |
228 | sd.addField("events_discarded", IntegerDeclaration.INT_32B_DECL); | |
229 | @SuppressWarnings("null") | |
230 | BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); | |
231 | bb.getByteBuffer().putInt(-1); | |
232 | bb.getByteBuffer().putInt(0); | |
233 | bb.getByteBuffer().putInt(66); | |
234 | bb.getByteBuffer().putInt(300); | |
fbe6fa6f | 235 | StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); |
04f0148f MK |
236 | StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 100); |
237 | assertEquals(Long.MIN_VALUE, sipie.getTimestampBegin()); | |
238 | assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd()); | |
239 | assertEquals("CPU66", sipie.getTarget()); | |
240 | assertEquals(66, sipie.getTargetId()); | |
241 | assertEquals(200, sipie.getLostEvents()); | |
242 | assertEquals(0, sipie.getOffsetBits()); | |
243 | assertEquals(1024, sipie.getPacketSizeBits()); | |
244 | } | |
245 | ||
246 | /** | |
247 | * Run the String toString() method test. | |
248 | * | |
680f9173 | 249 | * @throws CTFException |
04f0148f MK |
250 | * won't happen |
251 | */ | |
252 | @Test | |
680f9173 | 253 | public void testToString() throws CTFException { |
04f0148f MK |
254 | |
255 | String expectedResult = "StreamInputPacketIndexEntry [offsetBits=0, timestampBegin=0, timestampEnd=0]"; | |
256 | StructDeclaration sd = new StructDeclaration(8); | |
257 | sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL); | |
258 | sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL); | |
259 | @SuppressWarnings("null") | |
260 | BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); | |
261 | ||
fbe6fa6f | 262 | StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); |
04f0148f | 263 | assertEquals(expectedResult, new StreamInputPacketIndexEntry(0, sdef, 10000, 0).toString()); |
866e5b51 FC |
264 | } |
265 | } |