aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Khouzam2012-04-12 17:57:16 (EDT)
committerFrancois Chouinard2012-04-16 14:20:41 (EDT)
commit0733f3b80816cf25a275ed72e54918abbcad570e (patch)
treee7a4a569e628ea8b40a30fdc3e436cc6b327b873
parentf83095792d29998aaa60da3fb2a5da7fb247e8ca (diff)
downloadorg.eclipse.linuxtools-0733f3b80816cf25a275ed72e54918abbcad570e.zip
org.eclipse.linuxtools-0733f3b80816cf25a275ed72e54918abbcad570e.tar.gz
org.eclipse.linuxtools-0733f3b80816cf25a275ed72e54918abbcad570e.tar.bz2
improve test coverage and fix go to last event bug
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java3
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java4
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java10
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java175
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java5
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java13
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java6
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java3
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java35
9 files changed, 162 insertions, 92 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
index 3177f54..1e7f7b6 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
@@ -201,7 +201,8 @@ public class CTFTraceReaderTest {
fixture.goToLastEvent();
long ts1 = getTimestamp();
long ts2 = fixture.getEndTime();
- assertTrue(ts1 == ts2);
+ // the end time can be later than the last event.
+ assertTrue(ts1 <= ts2);
}
/**
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java
index 260b17b..39537d0 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java
@@ -99,7 +99,7 @@ public class CTFTraceTest {
* Run the void addStream(Stream) method test.
*
* @throws ParseException
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Test
public void testAddStream() throws ParseException, CTFReaderException {
@@ -313,7 +313,7 @@ public class CTFTraceTest {
@Test
public void testGetClock_1() {
CTFClock result = fixture.getClock();
- assertNull(result);
+ assertNotNull(result);
}
/**
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java
index 0b558ae..5249397 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputPacketIndexEntryTest.java
@@ -50,9 +50,9 @@ public class StreamInputPacketIndexEntryTest {
*/
@Test
public void testStreamInputPacketIndexEntry_1() {
- String expectedResult = "PacketIndexEntry [offset=1, " + //$NON-NLS-1$
+ String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1, " + //$NON-NLS-1$
"timestampBegin=0, timestampEnd=0, " + //$NON-NLS-1$
- "dataOffset=0, packetSize=0, contentSize=0]"; //$NON-NLS-1$
+ "indexBegin=9223372036854775807, indexEnd=9223372036854775807]"; //$NON-NLS-1$
assertNotNull(fixture);
assertEquals(expectedResult, fixture.toString());
@@ -63,9 +63,9 @@ public class StreamInputPacketIndexEntryTest {
*/
@Test
public void testToString() {
- String expectedResult = "PacketIndexEntry [offset=1, " + //$NON-NLS-1$
- "timestampBegin=1, timestampEnd=1, " + //$NON-NLS-1$
- "dataOffset=1, packetSize=1, contentSize=1]"; //$NON-NLS-1$
+ String expectedResult = "StreamInputPacketIndexEntry [offsetBytes=1,"+ //$NON-NLS-1$
+ " timestampBegin=1, timestampEnd=1, indexBegin=9223372036854775807,"+ //$NON-NLS-1$
+ " indexEnd=9223372036854775807]"; //$NON-NLS-1$
fixture.setContentSizeBits(1);
fixture.setDataOffsetBits(1);
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
index d995e26..3bdf3f9 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
@@ -7,21 +7,19 @@ import static org.junit.Assert.assertTrue;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.tests.TestParams;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
import org.junit.After;
import org.junit.Before;
@@ -37,7 +35,9 @@ import org.junit.Test;
public class ArrayDefinitionTest {
private CTFTrace trace;
- private ArrayDefinition fixture;
+ private ArrayDefinition charArrayFixture;
+ private ArrayDefinition stringArrayFixture;
+ private ArrayDefinition longArrayFixture;
/**
* Launch the test.
@@ -54,34 +54,70 @@ public class ArrayDefinitionTest {
*
* structDef shouldn't be null after parsing the CTFTraceReader object, so
* we can ignore the warning.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
this.trace = TestParams.createTrace();
- CTFTraceReader tr = new CTFTraceReader(this.trace);
- String name = ""; //$NON-NLS-1$
- StructDefinition structDef = null;
- boolean foundArray = false;
-
- while (tr.hasMoreEvents() && !foundArray) {
- tr.advance();
- EventDefinition ed = tr.getCurrentEventDef();
- for (String key : ed.fields.getDefinitions().keySet()) {
- structDef = ed.fields;
- Definition d = structDef.lookupDefinition(key);
- if (d instanceof ArrayDefinition) {
- foundArray = true;
- name = key;
- break;
- }
- }
- }
- fixture = structDef.lookupArray(name);
+ charArrayFixture = createCharArray();
+ stringArrayFixture = createStringArray();
+ longArrayFixture = createLongArray();
}
+ private ArrayDefinition createLongArray() {
+ IntegerDeclaration decl = new IntegerDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none"); //$NON-NLS-1$
+ IntegerDefinition[] defs = createIntDefs(10, 32);
+ ArrayDefinition temp = setUpDeclaration(decl, defs);
+ return temp;
+ }
+
+ private ArrayDefinition createCharArray() {
+ IntegerDeclaration decl = new IntegerDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none"); //$NON-NLS-1$
+ IntegerDefinition[] defs = createIntDefs(4,8);
+ ArrayDefinition temp = setUpDeclaration(decl, defs);
+ return temp;
+ }
+
+
+ /**
+ * @return
+ */
+ private ArrayDefinition createStringArray() {
+ StringDeclaration strDecl = new StringDeclaration();
+ StringDefinition[] defs = createDefs();
+ ArrayDefinition temp = setUpDeclaration(strDecl, defs);
+ return temp;
+ }
+ /**
+ * @param decl
+ * @param defs
+ * @return
+ */
+ private ArrayDefinition setUpDeclaration(IDeclaration decl,
+ Definition[] defs) {
+ ArrayDeclaration ad = new ArrayDeclaration(0, decl);
+ ArrayDefinition temp = new ArrayDefinition(ad , this.trace , "Testx"); //$NON-NLS-1$
+ temp.setDefinitions(defs);
+ return temp;
+ }
+ /**
+ * @param size
+ * @param bits
+ * @return
+ */
+ private IntegerDefinition[] createIntDefs(int size, int bits) {
+ IntegerDefinition[] defs = new IntegerDefinition[size];
+ for (int i = 0; i < size; i++) {
+
+ String content = "test" + i; //$NON-NLS-1$
+ defs[i] = new IntegerDefinition(new IntegerDeclaration(bits, false,
+ 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content), null, content);
+ defs[i].setValue(i);
+ }
+ return defs;
+ }
/**
* Perform post-test clean-up.
*/
@@ -109,7 +145,7 @@ public class ArrayDefinitionTest {
*/
@Test
public void testArrayDefinition_baseDeclaration() {
- ArrayDeclaration declaration = fixture.getDeclaration();
+ ArrayDeclaration declaration = charArrayFixture.getDeclaration();
String fieldName = ""; //$NON-NLS-1$
ArrayDefinition result = new ArrayDefinition(declaration, this.trace,
@@ -140,8 +176,8 @@ public class ArrayDefinitionTest {
*/
@Test
public void testGetDeclaration() {
- fixture.setDefinitions(new Definition[] {});
- ArrayDeclaration result = fixture.getDeclaration();
+ charArrayFixture.setDefinitions(new Definition[] {});
+ ArrayDeclaration result = charArrayFixture.getDeclaration();
assertNotNull(result);
}
@@ -152,7 +188,7 @@ public class ArrayDefinitionTest {
@Test
public void testGetElem_noDefs() {
int i = 0;
- Definition result = fixture.getElem(i);
+ Definition result = charArrayFixture.getElem(i);
assertNotNull(result);
}
@@ -163,10 +199,10 @@ public class ArrayDefinitionTest {
@Test
public void testGetElem_withDefs() {
Definition defs[] = createDefs();
- fixture.setDefinitions(defs);
+ charArrayFixture.setDefinitions(defs);
int j = 1;
- Definition result = fixture.getElem(j);
+ Definition result = charArrayFixture.getElem(j);
assertNotNull(result);
}
@@ -176,14 +212,14 @@ public class ArrayDefinitionTest {
*/
@Test
public void testIsString_ownDefs() {
- StringDefinition[] defs = createDefs();
- fixture.setDefinitions(defs);
- boolean result = fixture.isString();
+ boolean result = stringArrayFixture.isString();
assertFalse(result);
}
+
+
/**
* Run the boolean isString() method test.
*/
@@ -196,14 +232,8 @@ public class ArrayDefinitionTest {
"Testx"); //$NON-NLS-1$
int size = 4;
- IntegerDefinition[] defs = new IntegerDefinition[size];
- for (int i = 0; i < size; i++) {
-
- String content = "test" + i; //$NON-NLS-1$
- defs[i] = new IntegerDefinition(new IntegerDeclaration(8, false,
- 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content), null, content);
- defs[i].setValue(i);
- }
+ int bits = 8;
+ IntegerDefinition[] defs = createIntDefs(size, bits);
ownFixture.setDefinitions(defs);
boolean result = ownFixture.isString();
@@ -211,25 +241,36 @@ public class ArrayDefinitionTest {
assertTrue(result);
}
+
+
/**
* Run the boolean isString() method test.
*/
@Test
public void testIsString_emptyDef() {
- fixture.setDefinitions(new Definition[] {});
- boolean result = fixture.isString();
+ charArrayFixture.setDefinitions(new Definition[] {});
+ boolean result = charArrayFixture.isString();
- assertFalse(result);
+ assertTrue(result);
}
/**
+ * Run the boolean isString() method test.
+ */
+ @Test
+ public void testIsString_emptyDefStrDecl() {
+ ArrayDefinition ownFixture = createStringArray();
+ boolean result = ownFixture.isString();
+ assertFalse(result);
+ }
+ /**
* Run the void read(BitBuffer) method test.
*/
@Test
public void testRead_noDefs() {
BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
- fixture.read(input);
+ charArrayFixture.read(input);
}
/**
@@ -237,19 +278,26 @@ public class ArrayDefinitionTest {
*/
@Test
public void testRead_withDefs() {
- fixture.setDefinitions(new Definition[] {});
+ charArrayFixture.setDefinitions(new Definition[] {});
BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
- fixture.read(input);
+ charArrayFixture.read(input);
}
/**
* Run the String toString() method test.
*/
@Test
- public void testToString_base() {
- String result = fixture.toString();
-
+ public void testToString_char() {
+ String result = charArrayFixture.toString();
+ assertNotNull(result);
+ }
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString_long() {
+ String result = longArrayFixture.toString();
assertNotNull(result);
}
@@ -257,14 +305,25 @@ public class ArrayDefinitionTest {
* Run the String toString() method test.
*/
@Test
+ public void testToString_string() {
+ String result = stringArrayFixture.toString();
+ assertNotNull(result);
+ }
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
public void testToString_withDefs() {
- int size = 2;
- StringDefinition[] defs = new StringDefinition[size];
- for (int i = 0; i < size; i++) {
- defs[i] = new StringDefinition(null, null, ("test" + i)); //$NON-NLS-1$
- }
- fixture.setDefinitions(defs);
- String result = fixture.toString();
+ String result = charArrayFixture.toString();
+
+ assertNotNull(result);
+ }
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToStringStringArray() {
+ String result = stringArrayFixture.toString();
assertNotNull(result);
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java
index 5e312b6..56c17d5 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java
@@ -28,6 +28,7 @@ public class SequenceDeclarationTest {
private SequenceDeclaration fixture;
+ static final String fieldName = "LengthName"; //$NON-NLS-1$
/**
* Launch the test.
*
@@ -40,7 +41,7 @@ public class SequenceDeclarationTest {
@Before
public void setUp() {
- fixture = new SequenceDeclaration("", new StringDeclaration()); //$NON-NLS-1$
+ fixture = new SequenceDeclaration(fieldName, new StringDeclaration());
}
@After
@@ -71,7 +72,7 @@ public class SequenceDeclarationTest {
public void testCreateDefinition() {
IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
- String fieldName = "LengthName"; //$NON-NLS-1$
+
StructDeclaration structDec = new StructDeclaration(0);
structDec.addField(fieldName, id);
StructDefinition structDef = new StructDefinition(structDec, null, "x"); //$NON-NLS-1$
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
index 136581c..2ab82a0 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
@@ -21,7 +21,6 @@ import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -29,7 +28,7 @@ import org.junit.Test;
/**
* The class <code>StructDefinitionTest</code> contains tests for the class
* <code>{@link StructDefinition}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
@@ -41,7 +40,7 @@ public class StructDefinitionTest {
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
@@ -51,8 +50,8 @@ public class StructDefinitionTest {
/**
* Perform pre-test initialization.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
@@ -104,7 +103,7 @@ public class StructDefinitionTest {
*/
@Test
public void testLookupDefinition() {
- String lookupPath = "id"; //$NON-NLS-1$
+ String lookupPath = "args"; //$NON-NLS-1$
Definition result = fixture.lookupDefinition(lookupPath);
assertNotNull(result);
@@ -127,7 +126,7 @@ public class StructDefinitionTest {
*/
@Test
public void testLookupInteger_1() {
- String name = "id"; //$NON-NLS-1$
+ String name = "_args"; //$NON-NLS-1$
IntegerDefinition result = fixture.lookupInteger(name);
assertNotNull(result);
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java
index 29d946e..1abe327 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java
@@ -37,17 +37,17 @@ public class SequenceDefinition extends Definition {
IDefinitionScope definitionScope, String fieldName) throws CTFReaderException {
super(definitionScope, fieldName);
Definition lenDef = null;
-
+
this.declaration = declaration;
if (definitionScope != null) {
lenDef = definitionScope.lookupDefinition(declaration.getLengthName());
}
- if (lenDef == null) {
+ if (lenDef == null) {
throw new CTFReaderException("Sequence length field not found"); //$NON-NLS-1$
}
-
+
if (!(lenDef instanceof IntegerDefinition)) {
throw new CTFReaderException("Sequence length field not integer"); //$NON-NLS-1$
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java
index a4fccaa..fda5613 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java
@@ -289,7 +289,6 @@ public class CTFTraceReader {
*/
public void goToLastEvent() throws CTFReaderException {
- this.seek(0);
for (StreamInputReader streamInputReader : this.streamInputReaders) {
/*
* Seek the trace reader.
@@ -297,7 +296,7 @@ public class CTFTraceReader {
streamInputReader.goToLastEvent();
}
int count = prio.size();
- for (int i = 0; i < (count); i++) {
+ for (int i = 0; i < (count-1); i++) {
advance();
}
}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
index b33dd77..7c4bf08 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
@@ -46,7 +46,6 @@ public class StreamInputReader {
*/
private ListIterator<StreamInputPacketIndexEntry> packetIndexIt;
-
/**
* Reference to the current event of this trace file (iow, the last on that
* was read, the next one to be returned)
@@ -171,7 +170,7 @@ public class StreamInputReader {
* The timestamp to seek to.
*/
public long seek(long timestamp) {
- long offset = 0 ;
+ long offset = 0;
/*
* Search in the index for the packet to search in.
*/
@@ -192,14 +191,12 @@ public class StreamInputReader {
while (!done && (this.getCurrentEvent().timestamp < timestamp)) {
readNextEvent();
done = (this.getCurrentEvent() == null);
- offset++ ;
+ offset++;
}
return offset;
}
-
- public long seekIndex(long index) throws CTFReaderException
- {
+ public long seekIndex(long index) throws CTFReaderException {
/*
* Search in the index for the packet to search in.
*/
@@ -215,8 +212,9 @@ public class StreamInputReader {
/*
* get the current index
*/
- if(this.packetReader.getCurrentPacket() == null){
- throw new CTFReaderException("Current packet null in index seek, did you index your trace yet?");
+ if (this.packetReader.getCurrentPacket() == null) {
+ throw new CTFReaderException(
+ "Current packet null in index seek, did you index your trace yet?");
}
return this.packetReader.getCurrentPacket().getIndexBegin();
@@ -227,13 +225,28 @@ public class StreamInputReader {
* Search in the index for the packet to search in.
*/
int len = this.streamInput.getIndex().getEntries().size();
- StreamInputPacketIndexEntry entry = this.streamInput.getIndex().getEntries().get(len-1);
- seek(entry.getTimestampEnd() - 1 );
+ int back = 0;
+ long desired_timestamp = -1;
+ do {
+ back++;
+ StreamInputPacketIndexEntry entry = this.streamInput.getIndex()
+ .getEntries().get(len - back);
+ desired_timestamp = entry.getTimestampBegin() + 1;
+ seek(desired_timestamp);
+
+ } while (!this.packetReader.hasMoreEvents());
/*
* Go until the end of that packet
*/
+
+ int packet_size = 0;
while (this.packetReader.hasMoreEvents()) {
this.packetReader.readNextEvent();
+ packet_size++;
+ }
+ seek(desired_timestamp);
+ for (int i = 0; i < (packet_size - 1); i++) {
+ this.packetReader.readNextEvent();
}
}
@@ -255,6 +268,4 @@ public class StreamInputReader {
return packetReader;
}
-
-
}