Additional fix for bug 374008: Incorrect seek by location in LTTng trace.
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 13 Mar 2012 19:50:14 +0000 (15:50 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Tue, 13 Mar 2012 19:51:27 +0000 (15:51 -0400)
org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/trace/LTTngTraceTest.java
org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/lttng/core/trace/LTTngTrace.java

index 781eaa3736926fd0ed545b90d17f46b7b419b040..cfa88e28a3c4873265a2c239532ccc35945f76d5 100644 (file)
@@ -58,6 +58,9 @@ public class LTTngTraceTest extends TestCase {
     private final static long   locationToSeekTest1 = 13589826657302L;
     private final static long   contextValueAfterSeekTest1 = 13589826657302L;
     private final static String seek1EventReference = tracename + "/vm_state_0"; 
+    private final static long   seekTimestamp = 13589826657302L;
+    private final static long   nextEventTimestamp = 13589826659739L;
+    private final static long   nextnextEventTimestamp = 13589826662017L;
     
     private final static long   timestampToSeekLast = 13589906758692L;
     private final static Long  indexToSeekLast = 15315L;
@@ -230,7 +233,183 @@ public class LTTngTraceTest extends TestCase {
                assertNotSame("tmpEvent is null after seekLocation() to start ",null,tmpEvent );
                assertTrue("tmpEvent has wrong reference after seekLocation() to start", firstEventReference.contains((String)tmpEvent.getReference()));
        }
-       
+
+    public void testLocationOperations() {
+        TmfEvent tmpEvent = null;
+        TmfContext tmpContext = new TmfContext(null, 0);
+        LTTngTrace testStream1 = prepareStreamToTest();
+
+        // Test LttngLocation after a seek
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        LttngLocation location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationSeek());
+        assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a parse
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationParse());
+        assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a getNext
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationReadNext());
+        assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a parse and parse
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationParse());
+        assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a getNext and getNext
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationReadNext());
+        assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a getNext and parse
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationParse());
+        assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a parse and getNext
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationReadNext());
+        assertEquals("location has wrong operation time", seekTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a parse, getNext and parse
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationParse());
+        assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a parse, getNext and getNext
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationReadNext());
+        assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a getNext, parse and parse
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationParse());
+        assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a getNext, parse and getNext
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationReadNext());
+        assertEquals("location has wrong operation time", nextEventTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
+
+        // Test LttngLocation after a getNext, getNext and parse
+        tmpContext = testStream1.seekLocation(new LttngLocation(seekTimestamp));
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", seekTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.getNextEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        tmpEvent = testStream.parseEvent(tmpContext);
+        assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
+        location = (LttngLocation) tmpContext.getLocation().clone();
+        assertTrue("location has wrong flag", location.isLastOperationParse());
+        assertEquals("location has wrong operation time", nextnextEventTimestamp, location.getOperationTimeValue());
+        tmpContext = testStream1.seekLocation(location);
+        tmpEvent = testStream1.getNextEvent(tmpContext);
+        assertTrue("tmpContext is null after getNextEvent()", tmpEvent != null);
+        assertEquals("tmpEvent has wrong timestamp", nextnextEventTimestamp, tmpEvent.getTimestamp().getValue());
+    }
+
        public void testGetter() {
        TmfEvent tmpEvent = null;
        LTTngTrace testStream1 = prepareStreamToTest();
index 9b02d9199c43891ea54bac29889e57dfcd42b5f9..d17d42739216e82cde88ffac8d173480e748e042 100644 (file)
@@ -695,11 +695,10 @@ public class LTTngTrace extends TmfTrace<LttngEvent> {
             // one we read)
             returnedEvent = currentLttngEvent;
 
-            // *** IMPORTANT!
-            // Reset (erase) the operation marker to both location, to be able
-            // to detect we did NOT "read" this event
-            previousLocation.resetLocationState();
-            curLocation.resetLocationState();
+            // Set the operation marker as read to both locations, to be able to
+            // detect we need to read the next event
+            previousLocation.setLastOperationReadNext();
+            curLocation.setLastOperationReadNext();
         }
 
         // If we read an event, set it's time to the locations (both previous
@@ -756,8 +755,8 @@ public class LTTngTrace extends TmfTrace<LttngEvent> {
         returnedEvent = readEvent(curLocation);
         nbEventsRead++;
 
-        // Set the operation marker as read to both location, to be able to
-        // detect we did "read" this event
+        // Set the operation marker as read to both locations, to be able to
+        // detect we need to read the next event
         previousLocation.setLastOperationReadNext();
         curLocation.setLastOperationReadNext();
         return returnedEvent;
@@ -820,12 +819,11 @@ public class LTTngTrace extends TmfTrace<LttngEvent> {
 
         // *** Positionning trick :
         // ParseEvent only read the trace if :
-        // 1- The last operation was NOT a ParseEvent or a GetNextEvent --> A
-        // read is required
+        // 1- The last operation was NOT a ParseEvent --> A read is required
         // OR
         // 2- The time of the previous location is different from the current
         // one --> A seek + a read is required
-        if (((!(curLocation.isLastOperationParse())) && ((!(curLocation.isLastOperationReadNext()))))
+        if (!curLocation.isLastOperationParse()
                 || (previousLocation.getOperationTimeValue() != curLocation.getOperationTimeValue())) {
             // Previous time != Current time : We need to reposition to the
             // current time
This page took 0.02979 seconds and 5 git commands to generate.