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