1 /*******************************************************************************
2 * Copyright (c) 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
.tracecompass
.tmf
.core
.tests
.statesystem
;
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
;
20 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
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
.core
.trace
.ITmfTrace
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfExperiment
;
30 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.analysis
.TestExperimentAnalysis
;
31 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.TmfExperimentStub
;
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
;
40 * Test the {@link TmfStateSystemAnalysisModule} class for an experiment
42 * @author Geneviève Bastien
44 public class ExperimentStateSystemModuleTest
{
46 /** Time-out tests after some time */
48 public TestRule globalTimeout
= new Timeout(60000);
50 /** ID of the test state system analysis module */
51 public static final String MODULE_SS
= "org.eclipse.linuxtools.tmf.core.tests.experiment";
53 private TmfStateSystemAnalysisModule fModule
;
54 private TmfExperiment fExperiment
;
60 public void setupTraces() {
61 ITmfTrace trace
= TmfTestTrace
.A_TEST_10K
.getTrace();
62 TmfSignalManager
.deregister(trace
);
63 ITmfTrace trace2
= TmfTestTrace
.A_TEST_10K2
.getTrace();
64 TmfSignalManager
.deregister(trace2
);
65 ITmfTrace
[] traces
= { trace
, trace2
};
66 fExperiment
= new TmfExperimentStub("Test", traces
, 1000);
67 fExperiment
.traceOpened(new TmfTraceOpenedSignal(this, fExperiment
, null));
69 fModule
= (TmfStateSystemAnalysisModule
) fExperiment
.getAnalysisModule(MODULE_SS
);
70 assertNotNull(fModule
);
74 * Some tests use traces, let's clean them here
77 public void cleanupTraces() {
78 fExperiment
.dispose();
82 * Test the state system module execution and result
85 public void testSsModule() {
86 ITmfStateSystem ss
= fModule
.getStateSystem();
89 if (fModule
.waitForCompletion()) {
90 ss
= fModule
.getStateSystem();
93 int quark
= ss
.getQuarkAbsolute(TestExperimentAnalysis
.TRACE_QUARK_NAME
);
94 ITmfStateInterval interval
= ss
.querySingleState(ss
.getCurrentEndTime(), quark
);
95 assertEquals(2, interval
.getStateValue().unboxInt());
96 } catch (AttributeNotFoundException e
) {
97 fail("The quark for number of traces does not exist");
98 } catch (StateSystemDisposedException e
) {
99 fail("Error: state system disposed");
102 fail("Module did not complete properly");
107 * Make sure that the state system is initialized after calling
108 * {@link TmfStateSystemAnalysisModule#waitForInitialization()}.
111 public void testInitialization() {
112 assertNull(fModule
.getStateSystem());
115 fModule
.waitForInitialization();
116 assertNotNull(fModule
.getStateSystem());