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 | ||
367e2932 | 19 | import org.eclipse.jdt.annotation.NonNull; |
9529060e GB |
20 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; |
21 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; | |
22 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; | |
23 | import org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest; | |
24 | import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace; | |
25 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; | |
26 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
27 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; | |
28 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperimentUtils; | |
29 | import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis; | |
30 | import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis2; | |
31 | import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub; | |
32 | import org.junit.After; | |
33 | import org.junit.Before; | |
34 | import org.junit.Test; | |
35 | ||
36 | /** | |
37 | * Test the {@link TmfExperimentUtils} class | |
38 | * | |
39 | * @author Geneviève Bastien | |
40 | */ | |
41 | public class TmfExperimentUtilsTest { | |
42 | ||
43 | private static final String EXPERIMENT = "MyExperiment"; | |
44 | private static int BLOCK_SIZE = 1000; | |
45 | ||
46 | private TmfExperimentStub fExperiment; | |
47 | private ITmfTrace[] fTraces; | |
48 | ||
49 | /** | |
50 | * Setup the experiment | |
51 | */ | |
52 | @Before | |
53 | public void setupExperiment() { | |
54 | fTraces = new ITmfTrace[2]; | |
55 | fTraces[0] = TmfTestTrace.A_TEST_10K.getTrace(); | |
56 | fTraces[1] = TmfTestTrace.A_TEST_10K2.getTraceAsStub2(); | |
57 | /* Re-register the trace to the signal manager */ | |
58 | TmfSignalManager.register(fTraces[1]); | |
59 | fExperiment = new TmfExperimentStub(EXPERIMENT, fTraces, BLOCK_SIZE); | |
60 | fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); | |
61 | fExperiment.broadcast(new TmfTraceOpenedSignal(this, fExperiment, null)); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Cleanup after the test | |
66 | */ | |
67 | @After | |
68 | public void cleanUp() { | |
69 | fExperiment.dispose(); | |
70 | } | |
71 | ||
72 | /** | |
73 | * Test the | |
74 | * {@link TmfExperimentUtils#getAnalysisModuleForHost(TmfExperiment, String, String)} | |
75 | * method | |
76 | */ | |
77 | @Test | |
78 | public void testGetModuleById() { | |
79 | String commonModule = AnalysisManagerTest.MODULE_PARAM; | |
80 | String notCommonModule = AnalysisManagerTest.MODULE_SECOND; | |
81 | String host1 = TmfTestTrace.A_TEST_10K.getPath(); | |
82 | String host2 = TmfTestTrace.A_TEST_10K2.getPath(); | |
83 | TmfExperiment experiment = fExperiment; | |
84 | assertNotNull(experiment); | |
85 | ||
86 | /* First module for trace 1 */ | |
87 | IAnalysisModule module = TmfExperimentUtils.getAnalysisModuleForHost(experiment, host1, commonModule); | |
88 | assertNotNull(module); | |
89 | IAnalysisModule traceModule = fTraces[0].getAnalysisModule(commonModule); | |
90 | assertNotNull(traceModule); | |
91 | assertEquals(module, traceModule); | |
92 | ||
93 | /* Second inexistent module for trace 1 */ | |
94 | assertNull(TmfExperimentUtils.getAnalysisModuleForHost(experiment, host1, notCommonModule)); | |
95 | traceModule = fTraces[0].getAnalysisModule(notCommonModule); | |
96 | assertNull(traceModule); | |
97 | ||
98 | /* First module for trace 2 */ | |
99 | module = TmfExperimentUtils.getAnalysisModuleForHost(experiment, host2, commonModule); | |
100 | assertNotNull(module); | |
101 | traceModule = fTraces[1].getAnalysisModule(commonModule); | |
102 | assertNotNull(traceModule); | |
103 | assertEquals(module, traceModule); | |
104 | ||
105 | /* Second module for trace 2 */ | |
106 | module = TmfExperimentUtils.getAnalysisModuleForHost(experiment, host2, notCommonModule); | |
107 | assertNotNull(module); | |
108 | traceModule = fTraces[1].getAnalysisModule(notCommonModule); | |
109 | assertNotNull(traceModule); | |
110 | assertEquals(module, traceModule); | |
111 | } | |
112 | ||
113 | /** | |
114 | * Test the | |
115 | * {@link TmfExperimentUtils#getAnalysisModuleOfClassForHost(TmfExperiment, String, Class)} | |
116 | * method | |
117 | */ | |
118 | @Test | |
119 | public void testGetModuleByClass() { | |
367e2932 AM |
120 | Class<@NonNull TestAnalysis> commonClass = TestAnalysis.class; |
121 | Class<@NonNull TestAnalysis2> notCommonClass = TestAnalysis2.class; | |
9529060e GB |
122 | String host1 = TmfTestTrace.A_TEST_10K.getPath(); |
123 | String host2 = TmfTestTrace.A_TEST_10K2.getPath(); | |
124 | TmfExperiment experiment = fExperiment; | |
125 | assertNotNull(experiment); | |
126 | ||
127 | /* Common module for trace 1 */ | |
128 | TestAnalysis module1 = TmfExperimentUtils.getAnalysisModuleOfClassForHost(experiment, host1, commonClass); | |
129 | assertNotNull(module1); | |
130 | /* Make sure this module belongs to the trace */ | |
131 | IAnalysisModule sameModule = null; | |
132 | for (IAnalysisModule mod : fTraces[0].getAnalysisModules()) { | |
133 | if (mod == module1) { | |
134 | sameModule = mod; | |
135 | } | |
136 | } | |
137 | assertNotNull(sameModule); | |
138 | ||
139 | /* Uncommon module from trace 1 */ | |
140 | TestAnalysis2 module2 = TmfExperimentUtils.getAnalysisModuleOfClassForHost(experiment, host1, notCommonClass); | |
141 | assertNull(module2); | |
142 | ||
143 | /* Common module for trace 1 */ | |
144 | module1 = TmfExperimentUtils.getAnalysisModuleOfClassForHost(experiment, host2, commonClass); | |
145 | assertNotNull(module1); | |
146 | /* Make sure this module belongs to the trace */ | |
147 | sameModule = null; | |
148 | for (IAnalysisModule mod : fTraces[1].getAnalysisModules()) { | |
149 | if (mod == module1) { | |
150 | sameModule = mod; | |
151 | } | |
152 | } | |
153 | assertNotNull(sameModule); | |
154 | ||
155 | /* Uncommon module from trace 1 */ | |
156 | module2 = TmfExperimentUtils.getAnalysisModuleOfClassForHost(experiment, host2, notCommonClass); | |
157 | assertNotNull(module2); | |
158 | /* Make sure this module belongs to the trace */ | |
159 | sameModule = null; | |
160 | for (IAnalysisModule mod : fTraces[1].getAnalysisModules()) { | |
161 | if (mod == module1) { | |
162 | sameModule = mod; | |
163 | } | |
164 | } | |
165 | assertNotNull(sameModule); | |
166 | } | |
167 | ||
168 | } |