1 /*******************************************************************************
2 * Copyright (c) 2014 É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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.tests
.trace
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertNull
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.analysis
.AnalysisManagerTest
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.shared
.TmfTestTrace
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.experiment
.TmfExperiment
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.experiment
.TmfExperimentUtils
;
28 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.analysis
.TestAnalysis
;
29 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.analysis
.TestAnalysis2
;
30 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.TmfExperimentStub
;
31 import org
.junit
.After
;
32 import org
.junit
.Before
;
33 import org
.junit
.Test
;
36 * Test the {@link TmfExperimentUtils} class
38 * @author Geneviève Bastien
40 public class TmfExperimentUtilsTest
{
42 private static final String EXPERIMENT
= "MyExperiment";
43 private static int BLOCK_SIZE
= 1000;
45 private TmfExperimentStub fExperiment
;
46 private ITmfTrace
[] fTraces
;
49 * Setup the experiment
52 public void setupExperiment() {
53 fTraces
= new ITmfTrace
[2];
54 fTraces
[0] = TmfTestTrace
.A_TEST_10K
.getTrace();
55 fTraces
[1] = TmfTestTrace
.A_TEST_10K2
.getTraceAsStub2();
56 /* Re-register the trace to the signal manager */
57 TmfSignalManager
.register(fTraces
[1]);
58 fExperiment
= new TmfExperimentStub(EXPERIMENT
, fTraces
, BLOCK_SIZE
);
59 fExperiment
.getIndexer().buildIndex(0, TmfTimeRange
.ETERNITY
, true);
60 fExperiment
.broadcast(new TmfTraceOpenedSignal(this, fExperiment
, null));
64 * Cleanup after the test
67 public void cleanUp() {
68 fExperiment
.dispose();
73 * {@link TmfExperimentUtils#getAnalysisModuleForHost(TmfExperiment, String, String)}
77 public void testGetModuleById() {
78 String commonModule
= AnalysisManagerTest
.MODULE_PARAM
;
79 String notCommonModule
= AnalysisManagerTest
.MODULE_SECOND
;
80 String host1
= TmfTestTrace
.A_TEST_10K
.getPath();
81 String host2
= TmfTestTrace
.A_TEST_10K2
.getPath();
82 TmfExperiment experiment
= fExperiment
;
83 assertNotNull(experiment
);
85 /* First module for trace 1 */
86 IAnalysisModule module
= TmfExperimentUtils
.getAnalysisModuleForHost(experiment
, host1
, commonModule
);
87 assertNotNull(module
);
88 IAnalysisModule traceModule
= fTraces
[0].getAnalysisModule(commonModule
);
89 assertNotNull(traceModule
);
90 assertEquals(module
, traceModule
);
92 /* Second inexistent module for trace 1 */
93 assertNull(TmfExperimentUtils
.getAnalysisModuleForHost(experiment
, host1
, notCommonModule
));
94 traceModule
= fTraces
[0].getAnalysisModule(notCommonModule
);
95 assertNull(traceModule
);
97 /* First module for trace 2 */
98 module
= TmfExperimentUtils
.getAnalysisModuleForHost(experiment
, host2
, commonModule
);
99 assertNotNull(module
);
100 traceModule
= fTraces
[1].getAnalysisModule(commonModule
);
101 assertNotNull(traceModule
);
102 assertEquals(module
, traceModule
);
104 /* Second module for trace 2 */
105 module
= TmfExperimentUtils
.getAnalysisModuleForHost(experiment
, host2
, notCommonModule
);
106 assertNotNull(module
);
107 traceModule
= fTraces
[1].getAnalysisModule(notCommonModule
);
108 assertNotNull(traceModule
);
109 assertEquals(module
, traceModule
);
114 * {@link TmfExperimentUtils#getAnalysisModuleOfClassForHost(TmfExperiment, String, Class)}
118 public void testGetModuleByClass() {
119 Class
<TestAnalysis
> commonClass
= TestAnalysis
.class;
120 Class
<TestAnalysis2
> notCommonClass
= TestAnalysis2
.class;
121 String host1
= TmfTestTrace
.A_TEST_10K
.getPath();
122 String host2
= TmfTestTrace
.A_TEST_10K2
.getPath();
123 TmfExperiment experiment
= fExperiment
;
124 assertNotNull(experiment
);
126 /* Common module for trace 1 */
127 TestAnalysis module1
= TmfExperimentUtils
.getAnalysisModuleOfClassForHost(experiment
, host1
, commonClass
);
128 assertNotNull(module1
);
129 /* Make sure this module belongs to the trace */
130 IAnalysisModule sameModule
= null;
131 for (IAnalysisModule mod
: fTraces
[0].getAnalysisModules()) {
132 if (mod
== module1
) {
136 assertNotNull(sameModule
);
138 /* Uncommon module from trace 1 */
139 TestAnalysis2 module2
= TmfExperimentUtils
.getAnalysisModuleOfClassForHost(experiment
, host1
, notCommonClass
);
142 /* Common module for trace 1 */
143 module1
= TmfExperimentUtils
.getAnalysisModuleOfClassForHost(experiment
, host2
, commonClass
);
144 assertNotNull(module1
);
145 /* Make sure this module belongs to the trace */
147 for (IAnalysisModule mod
: fTraces
[1].getAnalysisModules()) {
148 if (mod
== module1
) {
152 assertNotNull(sameModule
);
154 /* Uncommon module from trace 1 */
155 module2
= TmfExperimentUtils
.getAnalysisModuleOfClassForHost(experiment
, host2
, notCommonClass
);
156 assertNotNull(module2
);
157 /* Make sure this module belongs to the trace */
159 for (IAnalysisModule mod
: fTraces
[1].getAnalysisModules()) {
160 if (mod
== module1
) {
164 assertNotNull(sameModule
);