-
Notifications
You must be signed in to change notification settings - Fork 10
/
BinaryFTraceByteBufferTest.java
85 lines (72 loc) · 3.5 KB
/
BinaryFTraceByteBufferTest.java
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
/*******************************************************************************
* Copyright (c) 2022 Ericsson
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tracecompass.incubator.ftrace.core.tests.binary.buffer;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.eclipse.tracecompass.incubator.ftrace.core.tests.shared.FTraceUtils;
import org.eclipse.tracecompass.incubator.internal.ftrace.core.binary.header.BinaryFTraceDataType;
import org.eclipse.tracecompass.incubator.internal.ftrace.core.binary.parser.BinaryFTraceByteBuffer;
import org.eclipse.tracecompass.incubator.internal.ftrace.core.binary.parser.BinaryFTraceHeaderElementSize;
import org.eclipse.tracecompass.testtraces.ftrace.FtraceTestTrace;
import org.junit.Test;
/**
* Tests for {@link BinaryFTraceByteBuffer}
*
* @author Hoang Thuan Pham
*/
public class BinaryFTraceByteBufferTest {
private static final String TRACING = "tracing";
private static final String VERSION = "6";
private static final int RANDOM_OFFSET = 3;
private static final int MAGIC_VALUE_SIZE = 3;
private static final int TRACING_STRING_SIZE = 7;
private static final int FTRACE_VERSION_SIZE = 1;
/**
* Test to make sure the current offset is incremented properly when reading
* the data.
*
* @throws IOException
* If an error occurred while getting the file path or reading
* the data
*/
@Test
public void testOffsetCounter() throws IOException {
String traceLocation = FTraceUtils.getTraceAbsolutePath(FtraceTestTrace.TEST_2_6_MULTIPLE_CPUS);
long currentOffset = 0;
try (BinaryFTraceByteBuffer buffer = new BinaryFTraceByteBuffer(traceLocation)) {
// Read the magic values
buffer.getNextBytes(MAGIC_VALUE_SIZE);
currentOffset += MAGIC_VALUE_SIZE;
assertEquals(buffer.getCurrentOffset(), currentOffset);
String tracingString = buffer.getNextBytesAsString(TRACING_STRING_SIZE);
currentOffset += TRACING_STRING_SIZE;
assertEquals(tracingString, TRACING);
assertEquals(buffer.getCurrentOffset(), currentOffset);
String versionString = buffer.getNextString();
currentOffset += (FTRACE_VERSION_SIZE + BinaryFTraceHeaderElementSize.STRING_TERMINATOR);
assertEquals(versionString, VERSION);
assertEquals(buffer.getCurrentOffset(), currentOffset);
// Read various data types and validate offset changes
buffer.getNextShort();
currentOffset += BinaryFTraceDataType.SHORT.getSize();
assertEquals(buffer.getCurrentOffset(), currentOffset);
buffer.getNextInt();
currentOffset += BinaryFTraceDataType.INT.getSize();
assertEquals(buffer.getCurrentOffset(), currentOffset);
buffer.getNextLong();
currentOffset += BinaryFTraceDataType.LONG.getSize();
assertEquals(buffer.getCurrentOffset(), currentOffset);
buffer.movePointerToOffset(RANDOM_OFFSET);
currentOffset = RANDOM_OFFSET;
assertEquals(buffer.getCurrentOffset(), currentOffset);
}
}
}