ctf: Add advanced trace tests
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 16 Oct 2013 23:18:56 +0000 (19:18 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 18 Nov 2013 20:00:41 +0000 (15:00 -0500)
Using a more exotic test trace.

I'm not exactly sure why a string field ends up in-between the variant
selector and its value, but this is how they are printed by Babeltrace,
so I assume we're doing the right thing.

Change-Id: I4bd0f35d31a7c592fafd64b3321f182f9de71c79
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/17550

org.eclipse.linuxtools.ctf.core.tests/pom.xml
org.eclipse.linuxtools.ctf.core.tests/shared/org/eclipse/linuxtools/ctf/core/tests/shared/CtfTestTrace.java
org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore
org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.xml
org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTrace.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/AllTests.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/FunkyTraceTest.java [new file with mode: 0644]

index 5df378b027e316a73682d650ba7dc8281d4fb154..4537d74df1d8e800af962b03fdcec07583d3483d 100644 (file)
@@ -88,6 +88,7 @@
                   </excludes>
                 </fileset>
                 <fileset><directory>traces/ctf-testsuite</directory></fileset>
+                <fileset><directory>traces/funky_trace</directory></fileset>
                 <fileset><directory>traces/hello-lost</directory></fileset>
                 <fileset><directory>traces/kernel</directory></fileset>
                 <fileset><directory>traces/kernel_vm</directory></fileset>
index 9d896ea672618bfc6bf2915cf7cd37789298b67a..8a169c41362cf4bee2a9b4d5ac8644865f7f9c15 100644 (file)
@@ -35,7 +35,9 @@ public enum CtfTestTrace {
     /** UST trace with lots of lost events */
     HELLO_LOST("../org.eclipse.linuxtools.ctf.core.tests/traces/hello-lost"),
     /** Autogenerated Syntetic trace */
-    SYNTHETIC_TRACE(LttngKernelTraceGenerator.getPath());
+    SYNTHETIC_TRACE(LttngKernelTraceGenerator.getPath()),
+    /** Trace with non-standard field sizes */
+    FUNKY_TRACE("../org.eclipse.linuxtools.ctf.core.tests/traces/funky_trace");
 
 
     private final String fPath;
index e84b9285d4b98ee38e2ad5cd95625323e3235b90..dc5ab29919115964035fe3334f1e0517ad314e4c 100644 (file)
@@ -1,6 +1,7 @@
 *.bz2
 *.tar
 /ctf-testsuite
+/funky_trace
 /hello-lost
 /kernel
 /kernel_vm
index 02b40e7fe7333feac0345a8e77e78dfc407fca64..52ed627645ecf1e16a1a1483beb29aad5d1fdab7 100644 (file)
@@ -15,6 +15,7 @@
   <get ignoreerrors="true" dest="trace2.tar.bz2" skipexisting="true" src="http://www.dorsal.polymtl.ca/~alexmont/data/trace2.tar.bz2"/>
   <get ignoreerrors="true" dest="kernel_vm.tar.bz2" skipexisting="true" src="http://www.dorsal.polymtl.ca/~alexmont/data/kernel_vm.tar.bz2" />
   <get ignoreerrors="true" dest="hello-lost.tar.bz2" skipexisting="true" src="http://www.dorsal.polymtl.ca/~alexmont/data/hello-lost.tar.bz2" />
+  <get ignoreerrors="true" dest="funky_trace.tar.bz2" skipexisting="true" src="http://www.dorsal.polymtl.ca/~alexmont/data/funky_trace.tar.bz2" />
   <exec executable = "git" failifexecutionfails="false">
     <arg value = "clone"/>
     <arg value = "https://github.com/efficios/ctf-testsuite.git"/>
@@ -31,6 +32,7 @@
       <available file="trace2.tar.bz2"/>
       <available file="kernel_vm.tar.bz2" />
       <available file="hello-lost.tar.bz2" />
+      <available file="funky_trace.tar.bz2" />
     </and>
   </condition>
   <antcall target="extractTraces"/>
     <bunzip2 src="trace2.tar.bz2"/>
     <bunzip2 src="kernel_vm.tar.bz2" />
     <bunzip2 src="hello-lost.tar.bz2" />
+    <bunzip2 src="funky_trace.tar.bz2" />
+
     <untar src="sample-ctf-trace-20120412.tar" dest="." />
     <untar src="trace2.tar" dest="." />
     <untar src="kernel_vm.tar" dest="." />
     <untar src="hello-lost.tar" dest="." />
+    <untar src="funky_trace.tar" dest="." />
     <echo message="Traces extracted successfully"/>
 </target>
 </project>
index 0992dc825681e32626c2b3ff95fbd55d09005d0f..e9c07f42289bccad65b471c7908fa3f5ddbd4016 100644 (file)
@@ -35,7 +35,9 @@ public enum CtfTmfTestTrace {
     /** UST trace with lots of lost events */
     HELLO_LOST,
     /** Autogenerated Syntetic trace */
-    SYNTHETIC_TRACE;
+    SYNTHETIC_TRACE,
+    /** Trace with non-standard field sizes */
+    FUNKY_TRACE;
 
 
     private final String fPath;
index e0545eba8ec235670272d25a0c31ea18745ade73..5fc88a1f81d90095497dd30633fd1e1d39802db8 100644 (file)
@@ -36,7 +36,8 @@ import org.junit.runners.Suite;
     CtfTmfLostEventsTest.class,
     CtfTmfTimestampTest.class,
     CtfTmfTraceTest.class,
-    EventContextTest.class
+    EventContextTest.class,
+    FunkyTraceTest.class
 })
 public class AllTests {
 
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/FunkyTraceTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/FunkyTraceTest.java
new file mode 100644 (file)
index 0000000..415585b
--- /dev/null
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfEnumPair;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * More advanced CTF tests using "funky_trace", a trace generated with the
+ * Babeltrace CTF writer API, which has lots of fun things like different
+ * integer/float sizes and non-standard struct alignments.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class FunkyTraceTest {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.FUNKY_TRACE;
+    private static final double DELTA = 0.0000001;
+
+    private static CtfTmfTrace fTrace;
+
+    // ------------------------------------------------------------------------
+    // Setup
+    // ------------------------------------------------------------------------
+
+    /**
+     * Test setup
+     */
+    @BeforeClass
+    public static void setupClass() {
+        assumeTrue(testTrace.exists());
+        fTrace = testTrace.getTrace();
+        fTrace.indexTrace(true);
+    }
+
+    /**
+     * Clean-up
+     */
+    @AfterClass
+    public static void tearDownClass() {
+        fTrace.dispose();
+    }
+
+    // ------------------------------------------------------------------------
+    // Test methods
+    // ------------------------------------------------------------------------
+
+    /**
+     * Verify the contents of the first event
+     */
+    @Test
+    public void testFirstEvent() {
+        CtfTmfEvent event = getEvent(0);
+        assertEquals("Simple Event", event.getEventName());
+        assertEquals(1234567, event.getTimestamp().getValue());
+        assertEquals(42, ((Long) event.getContent().getField("integer_field").getValue()).intValue());
+        assertEquals(3.1415, ((Double) event.getContent().getField("float_field").getValue()).doubleValue(), DELTA);
+    }
+
+    /**
+     * Verify the contents of the second event (the first "spammy event")
+     */
+    @Test
+    public void testSecondEvent() {
+        CtfTmfEvent event = getEvent(1);
+        assertEquals("Spammy_Event", event.getEventName());
+        assertEquals(1234568, event.getTimestamp().getValue());
+        assertEquals(0, ((Long) event.getContent().getField("field_1").getValue()).intValue());
+        assertEquals("This is a test", event.getContent().getField("a_string").getValue());
+    }
+
+    /**
+     * Verify the contents of the last "spammy event"
+     */
+    @Test
+    public void testSecondToLastEvent() {
+        CtfTmfEvent event = getEvent(100000);
+        assertEquals("Spammy_Event", event.getEventName());
+        assertEquals(1334567, event.getTimestamp().getValue());
+        assertEquals(99999, ((Long) event.getContent().getField("field_1").getValue()).intValue());
+        assertEquals("This is a test", event.getContent().getField("a_string").getValue());
+    }
+
+    /**
+     * Verify the contents of the last, complex event
+     */
+    @Test
+    public void testLastEvent() {
+        /*
+         * Last event as seen in Babeltrace:
+         * [19:00:00.001334568] (+0.000000001) Complex Test Event: { }, {
+         *     uint_35 = 0xDDF00D,
+         *     int_16 = -12345,
+         *     complex_structure = {
+         *         variant_selector = ( INT16_TYPE : container = 1 ),
+         *         a_string = "Test string",
+         *         variant_value = { INT16_TYPE = -200 },
+         *         inner_structure = {
+         *             seq_len = 0xA,
+         *             a_sequence = [ [0] = 4, [1] = 3, [2] = 2, [3] = 1, [4] = 0, [5] = -1, [6] = -2, [7] = -3, [8] = -4, [9] = -5 ]
+         *         }
+         *     }
+         * }
+         */
+
+        CtfTmfEvent event = getEvent(100001);
+        assertEquals("Complex Test Event", event.getEventName());
+        assertEquals(1334568, event.getTimestamp().getValue());
+        assertEquals(0xddf00d, ((Long) event.getContent().getField("uint_35").getValue()).intValue());
+        assertEquals(-12345, ((Long) event.getContent().getField("int_16").getValue()).intValue());
+
+        ITmfEventField[] complexStruct =
+                (ITmfEventField[]) event.getContent().getField("complex_structure").getValue();
+
+        assertEquals("variant_selector", complexStruct[0].getName());
+        CtfEnumPair variant1 = (CtfEnumPair) complexStruct[0].getValue();
+        assertEquals("INT16_TYPE", variant1.getStringValue());
+        assertEquals(Long.valueOf(1), variant1.getLongValue());
+
+        assertEquals("a_string", complexStruct[1].getName());
+        assertEquals("Test string", complexStruct[1].getValue());
+
+        assertEquals("variant_value", complexStruct[2].getName());
+        ITmfEventField variantField = (ITmfEventField) complexStruct[2].getValue();
+        assertEquals("INT16_TYPE", variantField.getName());
+        assertEquals(Long.valueOf(-200), variantField.getValue());
+
+        ITmfEventField[] innerStruct = (ITmfEventField[]) complexStruct[3].getValue();
+
+        assertEquals("seq_len", innerStruct[0].getName());
+        assertEquals(Long.valueOf(10), innerStruct[0].getValue());
+
+        assertEquals("a_sequence", innerStruct[1].getName());
+        long[] seqValues = (long[]) innerStruct[1].getValue();
+        long[] expectedValues = { 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 };
+        assertArrayEquals(expectedValues, seqValues);
+    }
+
+    // ------------------------------------------------------------------------
+    // Private stuff
+    // ------------------------------------------------------------------------
+
+    private synchronized CtfTmfEvent getEvent(long index) {
+        TestEventRequest req = new TestEventRequest(index);
+        fTrace.sendRequest(req);
+        try {
+            req.waitForCompletion();
+        } catch (InterruptedException e) {
+            return null;
+        }
+        return req.getEvent();
+    }
+
+    private class TestEventRequest extends TmfEventRequest {
+
+        private CtfTmfEvent fRetEvent = null;
+
+        public TestEventRequest(long index) {
+            super(CtfTmfEvent.class,
+                    TmfTimeRange.ETERNITY,
+                    index,
+                    1,
+                    1,
+                    ExecutionType.FOREGROUND);
+        }
+
+        @Override
+        public void handleData(ITmfEvent event) {
+            fRetEvent = (CtfTmfEvent) event;
+        }
+
+        public CtfTmfEvent getEvent() {
+            return fRetEvent;
+        }
+    }
+
+}
This page took 0.032835 seconds and 5 git commands to generate.