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 | ||
e894a508 AM |
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; | |
2bdf0193 AM |
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; | |
2d208fb7 GB |
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 for an experiment | |
41 | * | |
42 | * @author Geneviève Bastien | |
43 | */ | |
44 | public class ExperimentStateSystemModuleTest { | |
45 | ||
46 | /** Time-out tests after some time */ | |
47 | @Rule | |
48 | public TestRule globalTimeout = new Timeout(60000); | |
49 | ||
50 | /** ID of the test state system analysis module */ | |
51 | public static final String MODULE_SS = "org.eclipse.linuxtools.tmf.core.tests.experiment"; | |
52 | ||
53 | private TmfStateSystemAnalysisModule fModule; | |
54 | private TmfExperiment fExperiment; | |
55 | ||
56 | /** | |
57 | * Setup test trace | |
58 | */ | |
59 | @Before | |
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)); | |
68 | ||
69 | fModule = (TmfStateSystemAnalysisModule) fExperiment.getAnalysisModule(MODULE_SS); | |
70 | assertNotNull(fModule); | |
71 | } | |
72 | ||
73 | /** | |
74 | * Some tests use traces, let's clean them here | |
75 | */ | |
76 | @After | |
77 | public void cleanupTraces() { | |
78 | fExperiment.dispose(); | |
79 | } | |
80 | ||
81 | /** | |
82 | * Test the state system module execution and result | |
83 | */ | |
84 | @Test | |
85 | public void testSsModule() { | |
86 | ITmfStateSystem ss = fModule.getStateSystem(); | |
87 | assertNull(ss); | |
88 | fModule.schedule(); | |
89 | if (fModule.waitForCompletion()) { | |
90 | ss = fModule.getStateSystem(); | |
91 | assertNotNull(ss); | |
92 | try { | |
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"); | |
100 | } | |
101 | } else { | |
102 | fail("Module did not complete properly"); | |
103 | } | |
104 | } | |
105 | ||
106 | /** | |
107 | * Make sure that the state system is initialized after calling | |
108 | * {@link TmfStateSystemAnalysisModule#waitForInitialization()}. | |
109 | */ | |
110 | @Test | |
111 | public void testInitialization() { | |
112 | assertNull(fModule.getStateSystem()); | |
113 | fModule.schedule(); | |
114 | ||
115 | fModule.waitForInitialization(); | |
116 | assertNotNull(fModule.getStateSystem()); | |
117 | } | |
118 | ||
119 | } |