Commit | Line | Data |
---|---|---|
2d208fb7 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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.tests.statesystem; |
2d208fb7 GB |
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 | ||
d291a715 MAL |
20 | import java.util.concurrent.TimeUnit; |
21 | ||
e894a508 AM |
22 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
23 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; | |
24 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; | |
25 | import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; | |
2bdf0193 AM |
26 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; |
27 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; | |
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.core.trace.ITmfTrace; | |
5c5fa260 | 31 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
2bdf0193 AM |
32 | import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestExperimentAnalysis; |
33 | import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub; | |
2d208fb7 GB |
34 | import org.junit.After; |
35 | import org.junit.Before; | |
36 | import org.junit.Rule; | |
37 | import org.junit.Test; | |
38 | import org.junit.rules.TestRule; | |
39 | import org.junit.rules.Timeout; | |
40 | ||
41 | /** | |
42 | * Test the {@link TmfStateSystemAnalysisModule} class for an experiment | |
43 | * | |
44 | * @author Geneviève Bastien | |
45 | */ | |
46 | public class ExperimentStateSystemModuleTest { | |
47 | ||
48 | /** Time-out tests after some time */ | |
49 | @Rule | |
d291a715 | 50 | public TestRule globalTimeout = new Timeout(1, TimeUnit.MINUTES); |
2d208fb7 GB |
51 | |
52 | /** ID of the test state system analysis module */ | |
53 | public static final String MODULE_SS = "org.eclipse.linuxtools.tmf.core.tests.experiment"; | |
54 | ||
55 | private TmfStateSystemAnalysisModule fModule; | |
56 | private TmfExperiment fExperiment; | |
57 | ||
58 | /** | |
59 | * Setup test trace | |
60 | */ | |
61 | @Before | |
62 | public void setupTraces() { | |
63 | ITmfTrace trace = TmfTestTrace.A_TEST_10K.getTrace(); | |
64 | TmfSignalManager.deregister(trace); | |
65 | ITmfTrace trace2 = TmfTestTrace.A_TEST_10K2.getTrace(); | |
66 | TmfSignalManager.deregister(trace2); | |
67 | ITmfTrace[] traces = { trace, trace2 }; | |
68 | fExperiment = new TmfExperimentStub("Test", traces, 1000); | |
69 | fExperiment.traceOpened(new TmfTraceOpenedSignal(this, fExperiment, null)); | |
70 | ||
71 | fModule = (TmfStateSystemAnalysisModule) fExperiment.getAnalysisModule(MODULE_SS); | |
72 | assertNotNull(fModule); | |
73 | } | |
74 | ||
75 | /** | |
76 | * Some tests use traces, let's clean them here | |
77 | */ | |
78 | @After | |
79 | public void cleanupTraces() { | |
80 | fExperiment.dispose(); | |
81 | } | |
82 | ||
83 | /** | |
84 | * Test the state system module execution and result | |
85 | */ | |
86 | @Test | |
87 | public void testSsModule() { | |
88 | ITmfStateSystem ss = fModule.getStateSystem(); | |
89 | assertNull(ss); | |
90 | fModule.schedule(); | |
91 | if (fModule.waitForCompletion()) { | |
92 | ss = fModule.getStateSystem(); | |
93 | assertNotNull(ss); | |
94 | try { | |
95 | int quark = ss.getQuarkAbsolute(TestExperimentAnalysis.TRACE_QUARK_NAME); | |
96 | ITmfStateInterval interval = ss.querySingleState(ss.getCurrentEndTime(), quark); | |
97 | assertEquals(2, interval.getStateValue().unboxInt()); | |
98 | } catch (AttributeNotFoundException e) { | |
99 | fail("The quark for number of traces does not exist"); | |
100 | } catch (StateSystemDisposedException e) { | |
101 | fail("Error: state system disposed"); | |
102 | } | |
103 | } else { | |
104 | fail("Module did not complete properly"); | |
105 | } | |
106 | } | |
107 | ||
108 | /** | |
109 | * Make sure that the state system is initialized after calling | |
110 | * {@link TmfStateSystemAnalysisModule#waitForInitialization()}. | |
111 | */ | |
112 | @Test | |
113 | public void testInitialization() { | |
114 | assertNull(fModule.getStateSystem()); | |
115 | fModule.schedule(); | |
116 | ||
117 | fModule.waitForInitialization(); | |
118 | assertNotNull(fModule.getStateSystem()); | |
119 | } | |
120 | ||
121 | } |