Commit | Line | Data |
---|---|---|
43b5f69a FG |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 École Polytechnique de Montréal | |
3 | * | |
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 | *******************************************************************************/ | |
9 | ||
10 | package org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.graph; | |
11 | ||
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; | |
17 | ||
18 | import java.util.List; | |
19 | import java.util.Set; | |
20 | ||
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; | |
698fde87 | 26 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge.EdgeType; |
43b5f69a FG |
27 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph; |
28 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex; | |
43b5f69a FG |
29 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection; |
30 | import org.eclipse.tracecompass.analysis.graph.core.building.TmfGraphBuilderModule; | |
698fde87 | 31 | import org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.TmfXmlKernelTraceStub; |
43b5f69a FG |
32 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.model.LttngWorker; |
33 | import org.eclipse.tracecompass.lttng2.kernel.core.tests.Activator; | |
34 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; | |
35 | import org.eclipse.tracecompass.tmf.core.event.TmfEvent; | |
36 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; | |
37 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; | |
38 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
39 | import org.eclipse.tracecompass.tmf.core.trace.TmfTrace; | |
40 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; | |
43b5f69a FG |
41 | import org.junit.Test; |
42 | ||
43 | /** | |
44 | * Test that the execution graph is built correctly | |
45 | * | |
46 | * @author Geneviève Bastien | |
47 | */ | |
48 | public class LttngExecutionGraphTest { | |
49 | ||
50 | private static final @NonNull String TEST_ANALYSIS_ID = "org.eclipse.tracecompass.lttng2.kernel.core.tests.kernelgraph"; | |
51 | ||
52 | /** | |
53 | * Setup the trace for the tests | |
54 | * | |
55 | * @param traceFile | |
56 | * File name relative to this plugin for the trace file to load | |
57 | * @return The trace with its graph module executed | |
58 | */ | |
59 | public ITmfTrace setUpTrace(String traceFile) { | |
698fde87 | 60 | ITmfTrace trace = new TmfXmlKernelTraceStub(); |
43b5f69a FG |
61 | IPath filePath = Activator.getAbsoluteFilePath(traceFile); |
62 | IStatus status = trace.validate(null, filePath.toOSString()); | |
63 | if (!status.isOK()) { | |
64 | fail(status.getException().getMessage()); | |
65 | } | |
66 | try { | |
67 | trace.initTrace(null, filePath.toOSString(), TmfEvent.class); | |
68 | } catch (TmfTraceException e) { | |
69 | fail(e.getMessage()); | |
70 | } | |
71 | ((TmfTrace) trace).traceOpened(new TmfTraceOpenedSignal(this, trace, null)); | |
72 | IAnalysisModule module = null; | |
73 | for (IAnalysisModule mod : TmfTraceUtils.getAnalysisModulesOfClass(trace, TmfGraphBuilderModule.class)) { | |
74 | module = mod; | |
75 | } | |
76 | assertNotNull(module); | |
77 | module.schedule(); | |
78 | module.waitForCompletion(); | |
79 | return trace; | |
80 | } | |
81 | ||
82 | /** | |
83 | * Test the graph building with sched events only | |
84 | * | |
85 | * TODO: Add wakeup events to this test case | |
86 | */ | |
87 | @Test | |
88 | public void testSchedEvents() { | |
89 | ITmfTrace trace = setUpTrace("testfiles/graph/sched_only.xml"); | |
90 | assertNotNull(trace); | |
91 | ||
92 | TmfGraphBuilderModule module = TmfTraceUtils.getAnalysisModuleOfClass(trace, TmfGraphBuilderModule.class, TEST_ANALYSIS_ID); | |
93 | assertNotNull(module); | |
94 | module.schedule(); | |
95 | assertTrue(module.waitForCompletion()); | |
96 | ||
97 | TmfGraph graph = module.getGraph(); | |
98 | assertNotNull(graph); | |
99 | ||
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()) { | |
106 | case 1: | |
107 | { | |
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); | |
117 | assertNotNull(edge); | |
118 | assertEquals(EdgeType.PREEMPTED, edge.getType()); | |
119 | v = nodesOf.get(1); | |
120 | assertEquals(v, edge.getVertexTo()); | |
121 | ||
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); | |
128 | assertNotNull(edge); | |
129 | assertEquals(EdgeType.RUNNING, edge.getType()); | |
130 | v = nodesOf.get(2); | |
131 | assertEquals(v, edge.getVertexTo()); | |
132 | ||
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); | |
139 | assertNotNull(edge); | |
140 | assertEquals(EdgeType.PREEMPTED, edge.getType()); | |
141 | v = nodesOf.get(3); | |
142 | assertEquals(v, edge.getVertexTo()); | |
143 | ||
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)); | |
150 | } | |
151 | break; | |
152 | case 2: | |
153 | { | |
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); | |
163 | assertNotNull(edge); | |
164 | assertEquals(EdgeType.RUNNING, edge.getType()); | |
165 | v = nodesOf.get(1); | |
166 | assertEquals(v, edge.getVertexTo()); | |
167 | ||
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); | |
174 | assertNotNull(edge); | |
175 | assertEquals(EdgeType.BLOCKED, edge.getType()); | |
176 | v = nodesOf.get(2); | |
177 | assertEquals(v, edge.getVertexTo()); | |
178 | ||
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); | |
185 | assertNotNull(edge); | |
186 | assertEquals(EdgeType.RUNNING, edge.getType()); | |
187 | v = nodesOf.get(3); | |
188 | assertEquals(v, edge.getVertexTo()); | |
189 | ||
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)); | |
196 | } | |
197 | break; | |
198 | default: | |
199 | fail("Unknown worker"); | |
200 | break; | |
201 | } | |
202 | } | |
203 | } | |
204 | } |