Commit | Line | Data |
---|---|---|
9529060e GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 É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 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.tmf.core.tests.trace; | |
14 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertNotNull; | |
17 | import static org.junit.Assert.assertNull; | |
18 | ||
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; | |
34 | ||
35 | /** | |
36 | * Test the {@link TmfExperimentUtils} class | |
37 | * | |
38 | * @author Geneviève Bastien | |
39 | */ | |
40 | public class TmfExperimentUtilsTest { | |
41 | ||
42 | private static final String EXPERIMENT = "MyExperiment"; | |
43 | private static int BLOCK_SIZE = 1000; | |
44 | ||
45 | private TmfExperimentStub fExperiment; | |
46 | private ITmfTrace[] fTraces; | |
47 | ||
48 | /** | |
49 | * Setup the experiment | |
50 | */ | |
51 | @Before | |
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)); | |
61 | } | |
62 | ||
63 | /** | |
64 | * Cleanup after the test | |
65 | */ | |
66 | @After | |
67 | public void cleanUp() { | |
68 | fExperiment.dispose(); | |
69 | } | |
70 | ||
71 | /** | |
72 | * Test the | |
73 | * {@link TmfExperimentUtils#getAnalysisModuleForHost(TmfExperiment, String, String)} | |
74 | * method | |
75 | */ | |
76 | @Test | |
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); | |
84 | ||
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); | |
91 | ||
92 | /* Second inexistent module for trace 1 */ | |
93 | assertNull(TmfExperimentUtils.getAnalysisModuleForHost(experiment, host1, notCommonModule)); | |
94 | traceModule = fTraces[0].getAnalysisModule(notCommonModule); | |
95 | assertNull(traceModule); | |
96 | ||
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); | |
103 | ||
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); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Test the | |
114 | * {@link TmfExperimentUtils#getAnalysisModuleOfClassForHost(TmfExperiment, String, Class)} | |
115 | * method | |
116 | */ | |
117 | @Test | |
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); | |
125 | ||
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) { | |
133 | sameModule = mod; | |
134 | } | |
135 | } | |
136 | assertNotNull(sameModule); | |
137 | ||
138 | /* Uncommon module from trace 1 */ | |
139 | TestAnalysis2 module2 = TmfExperimentUtils.getAnalysisModuleOfClassForHost(experiment, host1, notCommonClass); | |
140 | assertNull(module2); | |
141 | ||
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 */ | |
146 | sameModule = null; | |
147 | for (IAnalysisModule mod : fTraces[1].getAnalysisModules()) { | |
148 | if (mod == module1) { | |
149 | sameModule = mod; | |
150 | } | |
151 | } | |
152 | assertNotNull(sameModule); | |
153 | ||
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 */ | |
158 | sameModule = null; | |
159 | for (IAnalysisModule mod : fTraces[1].getAnalysisModules()) { | |
160 | if (mod == module1) { | |
161 | sameModule = mod; | |
162 | } | |
163 | } | |
164 | assertNotNull(sameModule); | |
165 | } | |
166 | ||
167 | } |