55d8a51b3ef409285adf5568adbdbf296e429a09
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / statesystem / StateSystemAnalysisModuleTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 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.statesystem;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertNull;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20
21 import java.util.Map;
22 import java.util.concurrent.TimeUnit;
23
24 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
25 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
26 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
27 import org.eclipse.tracecompass.tmf.core.statesystem.Messages;
28 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
29 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace;
30 import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestStateSystemModule;
31 import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.TestRule;
37 import org.junit.rules.Timeout;
38
39 /**
40 * Test the {@link TmfStateSystemAnalysisModule} class
41 *
42 * @author Geneviève Bastien
43 */
44 public class StateSystemAnalysisModuleTest {
45
46 /** Time-out tests after 1 minute. */
47 @Rule
48 public TestRule globalTimeout = new Timeout(1, TimeUnit.MINUTES);
49
50 /** ID of the test state system analysis module */
51 public static final String MODULE_SS = "org.eclipse.linuxtools.tmf.core.tests.analysis.sstest";
52
53 private TmfStateSystemAnalysisModule module;
54
55 /**
56 * Setup test trace
57 */
58 @Before
59 public void setupTraces() {
60 TmfTraceStub trace = (TmfTraceStub) TmfTestTrace.A_TEST_10K.getTrace();
61 TmfSignalManager.deregister(trace);
62 trace.traceOpened(new TmfTraceOpenedSignal(this, trace, null));
63
64 module = (TmfStateSystemAnalysisModule) trace.getAnalysisModule(MODULE_SS);
65 }
66
67 /**
68 * Some tests use traces, let's clean them here
69 */
70 @After
71 public void cleanupTraces() {
72 TmfTestTrace.A_TEST_10K.dispose();
73 }
74
75 /**
76 * Test the state system module execution and result
77 */
78 @Test
79 public void testSsModule() {
80 ITmfStateSystem ss = module.getStateSystem();
81 assertNull(ss);
82 module.schedule();
83 if (module.waitForCompletion()) {
84 ss = module.getStateSystem();
85 assertNotNull(ss);
86 } else {
87 fail("Module did not complete properly");
88 }
89 }
90
91 /**
92 * Make sure that the state system is initialized after calling
93 * {@link TmfStateSystemAnalysisModule#waitForInitialization()}.
94 */
95 @Test
96 public void testInitialization() {
97 assertNull(module.getStateSystem());
98 module.schedule();
99
100 assertTrue("Initialization succeeded", module.waitForInitialization());
101 assertNotNull(module.getStateSystem());
102 }
103
104 /**
105 * Test that helper returns the right properties
106 */
107 @Test
108 public void testProperties() {
109
110 assertTrue(module instanceof TestStateSystemModule);
111 TestStateSystemModule mod = (TestStateSystemModule) module;
112
113 /* The stub state system has in mem backend 2 properties */
114 Map<String, String> properties = mod.getProperties();
115 assertEquals(mod.getBackendName(), properties.get(Messages.TmfStateSystemAnalysisModule_PropertiesBackend));
116 assertEquals(mod.getId(), properties.get(org.eclipse.tracecompass.tmf.core.analysis.Messages.TmfAbstractAnalysisModule_LabelId));
117 }
118
119 }
This page took 0.034257 seconds and 4 git commands to generate.