1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.analysis
.graph
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertNull
;
15 import static org
.junit
.Assert
.assertTrue
;
16 import static org
.junit
.Assert
.fail
;
18 import java
.util
.List
;
21 import org
.eclipse
.core
.runtime
.IPath
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.IGraphWorker
;
25 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfEdge
;
26 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfGraph
;
27 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfVertex
;
28 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfEdge
.EdgeType
;
29 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfVertex
.EdgeDirection
;
30 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.building
.TmfGraphBuilderModule
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.analysis
.graph
.model
.LttngWorker
;
32 import org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.Activator
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
40 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.xml
.TmfXmlTraceStub
;
41 import org
.junit
.Test
;
44 * Test that the execution graph is built correctly
46 * @author Geneviève Bastien
48 public class LttngExecutionGraphTest
{
50 private static final @NonNull String TEST_ANALYSIS_ID
= "org.eclipse.tracecompass.lttng2.kernel.core.tests.kernelgraph";
53 * Setup the trace for the tests
56 * File name relative to this plugin for the trace file to load
57 * @return The trace with its graph module executed
59 public ITmfTrace
setUpTrace(String traceFile
) {
60 ITmfTrace trace
= new TmfXmlTraceStub();
61 IPath filePath
= Activator
.getAbsoluteFilePath(traceFile
);
62 IStatus status
= trace
.validate(null, filePath
.toOSString());
64 fail(status
.getException().getMessage());
67 trace
.initTrace(null, filePath
.toOSString(), TmfEvent
.class);
68 } catch (TmfTraceException e
) {
71 ((TmfTrace
) trace
).traceOpened(new TmfTraceOpenedSignal(this, trace
, null));
72 IAnalysisModule module
= null;
73 for (IAnalysisModule mod
: TmfTraceUtils
.getAnalysisModulesOfClass(trace
, TmfGraphBuilderModule
.class)) {
76 assertNotNull(module
);
78 module
.waitForCompletion();
83 * Test the graph building with sched events only
85 * TODO: Add wakeup events to this test case
88 public void testSchedEvents() {
89 ITmfTrace trace
= setUpTrace("testfiles/graph/sched_only.xml");
92 TmfGraphBuilderModule module
= TmfTraceUtils
.getAnalysisModuleOfClass(trace
, TmfGraphBuilderModule
.class, TEST_ANALYSIS_ID
);
93 assertNotNull(module
);
95 assertTrue(module
.waitForCompletion());
97 TmfGraph graph
= module
.getGraph();
100 Set
<IGraphWorker
> workers
= graph
.getWorkers();
101 assertEquals(2, workers
.size());
102 for (IGraphWorker worker
: workers
) {
103 assertTrue(worker
instanceof LttngWorker
);
104 LttngWorker lttngWorker
= (LttngWorker
) worker
;
105 switch(lttngWorker
.getHostThread().getTid()) {
108 List
<TmfVertex
> nodesOf
= graph
.getNodesOf(lttngWorker
);
109 assertEquals(4, nodesOf
.size());
110 /* Check first vertice has outgoing edge preempted */
111 TmfVertex v
= nodesOf
.get(0);
112 assertEquals(10, v
.getTs());
113 assertNull(v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
));
114 assertNull(v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
));
115 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
));
116 TmfEdge edge
= v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
);
118 assertEquals(EdgeType
.PREEMPTED
, edge
.getType());
120 assertEquals(v
, edge
.getVertexTo());
122 /* Check second vertice has outgoing edge running */
123 assertEquals(20, v
.getTs());
124 assertNull(v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
));
125 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
));
126 assertNotNull(v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
));
127 edge
= v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
);
129 assertEquals(EdgeType
.RUNNING
, edge
.getType());
131 assertEquals(v
, edge
.getVertexTo());
133 /* Check third vertice has outgoing edge preempted */
134 assertEquals(30, v
.getTs());
135 assertNull(v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
));
136 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
));
137 assertNotNull(v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
));
138 edge
= v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
);
140 assertEquals(EdgeType
.PREEMPTED
, edge
.getType());
142 assertEquals(v
, edge
.getVertexTo());
144 /* Check 4th vertice */
145 assertEquals(40, v
.getTs());
146 assertNull(v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
));
147 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
));
148 assertNotNull(v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
));
149 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
));
154 List
<TmfVertex
> nodesOf
= graph
.getNodesOf(lttngWorker
);
155 assertEquals(4, nodesOf
.size());
156 /* Check first vertice has outgoing edge preempted */
157 TmfVertex v
= nodesOf
.get(0);
158 assertEquals(10, v
.getTs());
159 assertNull(v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
));
160 assertNull(v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
));
161 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
));
162 TmfEdge edge
= v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
);
164 assertEquals(EdgeType
.RUNNING
, edge
.getType());
166 assertEquals(v
, edge
.getVertexTo());
168 /* Check second vertice has outgoing edge running */
169 assertEquals(20, v
.getTs());
170 assertNull(v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
));
171 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
));
172 assertNotNull(v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
));
173 edge
= v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
);
175 assertEquals(EdgeType
.BLOCKED
, edge
.getType());
177 assertEquals(v
, edge
.getVertexTo());
179 /* Check third vertice has outgoing edge preempted */
180 assertEquals(30, v
.getTs());
181 assertNull(v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
));
182 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
));
183 assertNotNull(v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
));
184 edge
= v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
);
186 assertEquals(EdgeType
.RUNNING
, edge
.getType());
188 assertEquals(v
, edge
.getVertexTo());
190 /* Check 4th vertice */
191 assertEquals(40, v
.getTs());
192 assertNull(v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
));
193 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
));
194 assertNotNull(v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
));
195 assertNull(v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
));
199 fail("Unknown worker");