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
.analysis
.graph
.core
.tests
.graph
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.fail
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.runtime
.IPath
;
19 import org
.eclipse
.core
.runtime
.IStatus
;
20 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfGraph
;
21 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfVertex
;
22 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.TmfVertex
.EdgeDirection
;
23 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.building
.TmfGraphBuilderModule
;
24 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.tests
.Activator
;
25 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.tests
.stubs
.TestGraphWorker
;
26 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.tests
.stubs
.module
.GraphBuilderModuleStub
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
33 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.xml
.TmfXmlTraceStub
;
34 import org
.junit
.Test
;
37 * Test suite for the {@link TmfGraphBuilderModule} class
39 * @author Geneviève Bastien
40 * @author Francis Giraldeau
42 public class TmfGraphBuilderModuleTest
{
44 private static final String STUB_TRACE_FILE
= "testfiles/stubtrace.xml";
47 * With this trace, the resulting graph should look like this:
50 * 0 1 2 3 4 5 6 7 8 9 10 11 12 13
51 * Player 1 *--* *-----* *
53 * Player 2 *--------* *------*
58 private TmfGraphBuilderModule
getModule() {
59 ITmfTrace trace
= new TmfXmlTraceStub();
60 IPath filePath
= Activator
.getAbsoluteFilePath(STUB_TRACE_FILE
);
61 IStatus status
= trace
.validate(null, filePath
.toOSString());
63 fail(status
.getException().getMessage());
66 trace
.initTrace(null, filePath
.toOSString(), TmfEvent
.class);
67 } catch (TmfTraceException e
) {
70 ((TmfTrace
) trace
).traceOpened(new TmfTraceOpenedSignal(this, trace
, null));
71 GraphBuilderModuleStub module
= null;
72 for (GraphBuilderModuleStub mod
: TmfTraceUtils
.getAnalysisModulesOfClass(trace
, GraphBuilderModuleStub
.class)) {
75 assertNotNull(module
);
81 * Test the graph builder execution
84 public void testBuildGraph() {
86 TmfGraphBuilderModule module
= getModule();
88 module
.waitForCompletion();
90 TmfGraph graph
= module
.getGraph();
93 assertEquals(2, graph
.getWorkers().size());
94 assertEquals(9, graph
.size());
96 List
<TmfVertex
> vertices
= graph
.getNodesOf(new TestGraphWorker(1));
97 assertEquals(5, vertices
.size());
99 long timestamps1
[] = { 1, 2, 5, 7, 12 };
100 boolean hasEdges1
[][] = {
101 { false, true, false, false },
102 { true, false, false, true },
103 { false, true, true, false },
104 { true, false, false, false},
105 { false, false, true, false} };
106 for (int i
= 0; i
< vertices
.size(); i
++) {
107 TmfVertex v
= vertices
.get(i
);
108 assertEquals(timestamps1
[i
], v
.getTs());
109 assertEquals(hasEdges1
[i
][0], v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
) != null);
110 assertEquals(hasEdges1
[i
][1], v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
) != null);
111 assertEquals(hasEdges1
[i
][2], v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
) != null);
112 assertEquals(hasEdges1
[i
][3], v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
) != null);
115 vertices
= graph
.getNodesOf(new TestGraphWorker(2));
116 assertEquals(4, vertices
.size());
118 long timestamps2
[] = { 2, 5, 10, 12 };
119 boolean hasEdges2
[][] = {
120 { false, true, true, false },
121 { true, false, false, true },
122 { false, true, false, false },
123 { true, false, false, true} };
124 for (int i
= 0; i
< vertices
.size(); i
++) {
125 TmfVertex v
= vertices
.get(i
);
126 assertEquals(timestamps2
[i
], v
.getTs());
127 assertEquals(hasEdges2
[i
][0], v
.getEdge(EdgeDirection
.INCOMING_HORIZONTAL_EDGE
) != null);
128 assertEquals(hasEdges2
[i
][1], v
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
) != null);
129 assertEquals(hasEdges2
[i
][2], v
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
) != null);
130 assertEquals(hasEdges2
[i
][3], v
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
) != null);