1 /*******************************************************************************
2 * Copyright (c) 2013, 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
.linuxtools
.tmf
.core
.tests
.analysis
;
15 import static org
.junit
.Assert
.assertFalse
;
16 import static org
.junit
.Assert
.assertTrue
;
17 import static org
.junit
.Assume
.assumeTrue
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleSource
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisManager
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.TmfTestTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.analysis
.AnalysisModuleSourceStub
;
29 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.analysis
.AnalysisModuleTestHelper
;
30 import org
.junit
.After
;
31 import org
.junit
.Test
;
34 * Test suite for the TmfAnalysisModule class
36 public class AnalysisManagerTest
{
38 /** Id of analysis module with parameter */
39 public static final String MODULE_PARAM
= "org.eclipse.linuxtools.tmf.core.tests.analysis.test";
40 /** ID of analysis module with parameter and default value */
41 public static final String MODULE_PARAM_DEFAULT
= "org.eclipse.linuxtools.tmf.core.tests.analysis.test2";
42 /** ID of analysis module for CTF traces only */
43 public static final String MODULE_CTF
= "org.eclipse.linuxtools.tmf.core.tests.analysis.testctf";
46 * Some tests use traces, let's clean them here
49 public void cleanupTraces() {
50 TmfTestTrace
.A_TEST_10K
.dispose();
51 CtfTmfTestTrace
.KERNEL
.dispose();
55 * Test suite for the {@link TmfAnalysisManager#getAnalysisModules()} method
58 public void testGetAnalysisModules() {
59 Map
<String
, IAnalysisModuleHelper
> modules
= TmfAnalysisManager
.getAnalysisModules();
60 /* At least 3 modules should be found */
61 assertTrue(modules
.size() >= 3);
63 IAnalysisModuleHelper module
= modules
.get(MODULE_PARAM_DEFAULT
);
64 assertTrue(module
.isAutomatic());
66 module
= modules
.get(MODULE_PARAM
);
67 assertFalse(module
.isAutomatic());
71 * Test suite for {@link TmfAnalysisManager#getAnalysisModules(Class)} Use
72 * the test TMF trace and test Ctf trace as sample traces
75 public void testListForTraces() {
76 /* Generic TmfTrace */
77 ITmfTrace trace
= TmfTestTrace
.A_TEST_10K
.getTrace();
78 Map
<String
, IAnalysisModuleHelper
> map
= TmfAnalysisManager
.getAnalysisModules(trace
.getClass());
80 assertTrue(map
.containsKey(MODULE_PARAM
));
81 assertTrue(map
.containsKey(MODULE_PARAM_DEFAULT
));
82 assertFalse(map
.containsKey(MODULE_CTF
));
85 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
86 CtfTmfTrace ctftrace
= CtfTmfTestTrace
.KERNEL
.getTrace();
88 map
= TmfAnalysisManager
.getAnalysisModules(ctftrace
.getClass());
90 assertFalse(map
.containsKey(MODULE_PARAM
));
91 assertFalse(map
.containsKey(MODULE_PARAM_DEFAULT
));
92 assertTrue(map
.containsKey(MODULE_CTF
));
96 * Test suite to test refresh of analysis module when adding a {@link IAnalysisModuleSource}
99 public void testSources() {
100 /* Make sure that modules in the new source are not in the list already */
101 /* Generic TmfTrace */
102 ITmfTrace trace
= TmfTestTrace
.A_TEST_10K
.getTrace();
103 Map
<String
, IAnalysisModuleHelper
> map
= TmfAnalysisManager
.getAnalysisModules(trace
.getClass());
105 assertFalse(map
.containsKey(AnalysisModuleTestHelper
.moduleStubEnum
.TEST
.name()));
108 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
109 CtfTmfTrace ctftrace
= CtfTmfTestTrace
.KERNEL
.getTrace();
111 map
= TmfAnalysisManager
.getAnalysisModules(ctftrace
.getClass());
113 assertFalse(map
.containsKey(AnalysisModuleTestHelper
.moduleStubEnum
.TESTCTF
.name()));
116 TmfAnalysisManager
.registerModuleSource(new AnalysisModuleSourceStub());
118 /* Now make sure the modules are present */
119 map
= TmfAnalysisManager
.getAnalysisModules(trace
.getClass());
120 assertTrue(map
.containsKey(AnalysisModuleTestHelper
.moduleStubEnum
.TEST
.name()));
122 map
= TmfAnalysisManager
.getAnalysisModules(ctftrace
.getClass());
123 assertTrue(map
.containsKey(AnalysisModuleTestHelper
.moduleStubEnum
.TESTCTF
.name()));