lttng: Add unit test for the dependency graph
authorFrancis Giraldeau <francis.giraldeau@gmail.com>
Mon, 9 Feb 2015 03:49:33 +0000 (22:49 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 21 Oct 2015 12:55:51 +0000 (08:55 -0400)
Change-Id: I9233317d3feb240ecf5d98be3c11aeebd68c448f
Signed-off-by: Francis Giraldeau <francis.giraldeau@gmail.com>
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/41480
Reviewed-by: Hudson CI
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/META-INF/MANIFEST.MF
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/build.properties
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/plugin.xml [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/src/org/eclipse/tracecompass/lttng2/kernel/core/tests/AllTests.java
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/src/org/eclipse/tracecompass/lttng2/kernel/core/tests/analysis/graph/AllTests.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/src/org/eclipse/tracecompass/lttng2/kernel/core/tests/analysis/graph/LttngExecutionGraphTest.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/testfiles/graph/sched_only.xml [new file with mode: 0644]

index 2b62411603d43e2b94a51d3a70abd6c6f73fa40e..040e7712b14a2d61731f0b9ac65ff22cf94405fa 100644 (file)
@@ -19,7 +19,8 @@ Require-Bundle: org.junit;bundle-version="4.0.0",
  org.eclipse.core.resources,
  org.eclipse.tracecompass.lttng2.control.core,
  org.eclipse.tracecompass.analysis.os.linux.core,
- org.eclipse.tracecompass.analysis.os.linux.core.tests
+ org.eclipse.tracecompass.analysis.os.linux.core.tests,
+ org.eclipse.tracecompass.analysis.graph.core
 Export-Package: org.eclipse.tracecompass.lttng2.kernel.core.tests,
  org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.kernel;x-internal:=true,
  org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.kernel.statesystem;x-internal:=true,
index 68a4f26c7a3ffb37168eb52d26f18c26fb08d4c5..9a8ad77ccc8cdb763b818f3a7a6dfa724e985ada 100644 (file)
@@ -17,7 +17,8 @@ output.. = bin/
 bin.includes = META-INF/,\
                .,\
                plugin.properties,\
-               about.html
+               about.html,\
+               plugin.xml
 src.includes = about.html
 additional.bundles = org.eclipse.jdt.annotation
 jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/plugin.xml b/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/plugin.xml
new file mode 100644 (file)
index 0000000..e563fb6
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+   <extension
+         point="org.eclipse.linuxtools.tmf.core.analysis">
+      <module
+            analysis_module="org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.building.LttngKernelExecutionGraph"
+            id="org.eclipse.tracecompass.lttng2.kernel.core.tests.kernelgraph"
+            name="LTTng Stub Kernel Execution Graph">
+         <tracetype
+               class="org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub">
+         </tracetype>
+      </module>
+   </extension>
+
+</plugin>
index 2150b4e5aba6493ed75d4c7014ae07d1d01b03ba..c12d9131c5fc4a19e8633ac6e26bfff3c22418b9 100644 (file)
@@ -21,6 +21,7 @@ import org.junit.runner.RunWith;
 @RunWith(DebugSuite.class)
 @DebugSuite.SuiteClasses({
     ActivatorTest.class,
+    org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.graph.AllTests.class,
     org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.kernel.AllTests.class,
     org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.kernel.statesystem.TestAll.class,
     org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.vm.AllTests.class,
diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/src/org/eclipse/tracecompass/lttng2/kernel/core/tests/analysis/graph/AllTests.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/src/org/eclipse/tracecompass/lttng2/kernel/core/tests/analysis/graph/AllTests.java
new file mode 100644 (file)
index 0000000..c8f0b99
--- /dev/null
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.graph;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for execution graph analysis
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+        LttngExecutionGraphTest.class
+})
+public class AllTests {
+
+}
diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/src/org/eclipse/tracecompass/lttng2/kernel/core/tests/analysis/graph/LttngExecutionGraphTest.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/src/org/eclipse/tracecompass/lttng2/kernel/core/tests/analysis/graph/LttngExecutionGraphTest.java
new file mode 100644 (file)
index 0000000..46f008c
--- /dev/null
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.graph;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge.EdgeType;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection;
+import org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule;
+import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.model.LttngWorker;
+import org.eclipse.tracecompass.lttng2.kernel.core.tests.Activator;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+import org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub;
+import org.junit.Test;
+
+/**
+ * Test that the execution graph is built correctly
+ *
+ * @author Geneviève Bastien
+ */
+public class LttngExecutionGraphTest {
+
+    private static final @NonNull String TEST_ANALYSIS_ID = "org.eclipse.tracecompass.lttng2.kernel.core.tests.kernelgraph";
+
+    /**
+     * Setup the trace for the tests
+     *
+     * @param traceFile
+     *            File name relative to this plugin for the trace file to load
+     * @return The trace with its graph module executed
+     */
+    public ITmfTrace setUpTrace(String traceFile) {
+        ITmfTrace trace = new TmfXmlTraceStub();
+        IPath filePath = Activator.getAbsoluteFilePath(traceFile);
+        IStatus status = trace.validate(null, filePath.toOSString());
+        if (!status.isOK()) {
+            fail(status.getException().getMessage());
+        }
+        try {
+            trace.initTrace(null, filePath.toOSString(), TmfEvent.class);
+        } catch (TmfTraceException e) {
+            fail(e.getMessage());
+        }
+        ((TmfTrace) trace).traceOpened(new TmfTraceOpenedSignal(this, trace, null));
+        IAnalysisModule module = null;
+        for (IAnalysisModule mod : TmfTraceUtils.getAnalysisModulesOfClass(trace, TmfGraphBuilderModule.class)) {
+            module = mod;
+        }
+        assertNotNull(module);
+        module.schedule();
+        module.waitForCompletion();
+        return trace;
+    }
+
+    /**
+     * Test the graph building with sched events only
+     *
+     * TODO: Add wakeup events to this test case
+     */
+    @Test
+    public void testSchedEvents() {
+        ITmfTrace trace = setUpTrace("testfiles/graph/sched_only.xml");
+        assertNotNull(trace);
+
+        TmfGraphBuilderModule module = TmfTraceUtils.getAnalysisModuleOfClass(trace, TmfGraphBuilderModule.class, TEST_ANALYSIS_ID);
+        assertNotNull(module);
+        module.schedule();
+        assertTrue(module.waitForCompletion());
+
+        TmfGraph graph = module.getGraph();
+        assertNotNull(graph);
+
+        Set<IGraphWorker> workers = graph.getWorkers();
+        assertEquals(2, workers.size());
+        for (IGraphWorker worker: workers) {
+            assertTrue(worker instanceof LttngWorker);
+            LttngWorker lttngWorker = (LttngWorker) worker;
+            switch(lttngWorker.getHostThread().getTid()) {
+            case 1:
+            {
+                List<TmfVertex> nodesOf = graph.getNodesOf(lttngWorker);
+                assertEquals(4, nodesOf.size());
+                /* Check first vertice has outgoing edge preempted */
+                TmfVertex v = nodesOf.get(0);
+                assertEquals(10, v.getTs());
+                assertNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
+                TmfEdge edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
+                assertNotNull(edge);
+                assertEquals(EdgeType.PREEMPTED, edge.getType());
+                v = nodesOf.get(1);
+                assertEquals(v, edge.getVertexTo());
+
+                /* Check second vertice has outgoing edge running */
+                assertEquals(20, v.getTs());
+                assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
+                assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
+                edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
+                assertNotNull(edge);
+                assertEquals(EdgeType.RUNNING, edge.getType());
+                v = nodesOf.get(2);
+                assertEquals(v, edge.getVertexTo());
+
+                /* Check third vertice has outgoing edge preempted */
+                assertEquals(30, v.getTs());
+                assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
+                assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
+                edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
+                assertNotNull(edge);
+                assertEquals(EdgeType.PREEMPTED, edge.getType());
+                v = nodesOf.get(3);
+                assertEquals(v, edge.getVertexTo());
+
+                /* Check 4th vertice */
+                assertEquals(40, v.getTs());
+                assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
+                assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE));
+            }
+                break;
+            case 2:
+            {
+                List<TmfVertex> nodesOf = graph.getNodesOf(lttngWorker);
+                assertEquals(4, nodesOf.size());
+                /* Check first vertice has outgoing edge preempted */
+                TmfVertex v = nodesOf.get(0);
+                assertEquals(10, v.getTs());
+                assertNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
+                TmfEdge edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
+                assertNotNull(edge);
+                assertEquals(EdgeType.RUNNING, edge.getType());
+                v = nodesOf.get(1);
+                assertEquals(v, edge.getVertexTo());
+
+                /* Check second vertice has outgoing edge running */
+                assertEquals(20, v.getTs());
+                assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
+                assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
+                edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
+                assertNotNull(edge);
+                assertEquals(EdgeType.BLOCKED, edge.getType());
+                v = nodesOf.get(2);
+                assertEquals(v, edge.getVertexTo());
+
+                /* Check third vertice has outgoing edge preempted */
+                assertEquals(30, v.getTs());
+                assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
+                assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
+                edge = v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
+                assertNotNull(edge);
+                assertEquals(EdgeType.RUNNING, edge.getType());
+                v = nodesOf.get(3);
+                assertEquals(v, edge.getVertexTo());
+
+                /* Check 4th vertice */
+                assertEquals(40, v.getTs());
+                assertNull(v.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE));
+                assertNotNull(v.getEdge(EdgeDirection.INCOMING_HORIZONTAL_EDGE));
+                assertNull(v.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE));
+            }
+                break;
+            default:
+                fail("Unknown worker");
+                break;
+            }
+        }
+    }
+}
diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/testfiles/graph/sched_only.xml b/lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/testfiles/graph/sched_only.xml
new file mode 100644 (file)
index 0000000..8ddf577
--- /dev/null
@@ -0,0 +1,45 @@
+<trace>
+<event timestamp="0" name="set_aspects">
+<field name="cpu" value="1" type="int" />
+</event>
+<event timestamp="10" name="sched_switch">
+<field name="cpu" value="0" type="int" />
+<field name="prev_comm" value="proc1" type="string" />
+<field name="prev_tid" value="1" type="long" />
+<field name="prev_prio" value="20" type="int" />
+<field name="prev_state" value="0" type="long" />
+<field name="next_comm" value="proc2" type="string" />
+<field name="next_tid" value="2" type="long" />
+<field name="next_prio" value="20" type="int" />
+</event>
+<event timestamp="20" name="sched_switch">
+<field name="cpu" value="0" type="int" />
+<field name="prev_comm" value="proc2" type="string" />
+<field name="prev_tid" value="2" type="long" />
+<field name="prev_prio" value="20" type="int" />
+<field name="prev_state" value="3" type="long" />
+<field name="next_comm" value="proc1" type="string" />
+<field name="next_tid" value="1" type="long" />
+<field name="next_prio" value="20" type="int" />
+</event>
+<event timestamp="30" name="sched_switch">
+<field name="cpu" value="0" type="int" />
+<field name="prev_comm" value="proc1" type="string" />
+<field name="prev_tid" value="1" type="long" />
+<field name="prev_prio" value="20" type="int" />
+<field name="prev_state" value="0" type="long" />
+<field name="next_comm" value="proc2" type="string" />
+<field name="next_tid" value="2" type="long" />
+<field name="next_prio" value="20" type="int" />
+</event>
+<event timestamp="40" name="sched_switch">
+<field name="cpu" value="0" type="int" />
+<field name="prev_comm" value="proc2" type="string" />
+<field name="prev_tid" value="2" type="long" />
+<field name="prev_prio" value="20" type="int" />
+<field name="prev_state" value="0" type="long" />
+<field name="next_comm" value="proc1" type="string" />
+<field name="next_tid" value="1" type="long" />
+<field name="next_prio" value="20" type="int" />
+</event>
+</trace>
\ No newline at end of file
This page took 0.031604 seconds and 5 git commands to generate.