Commit | Line | Data |
---|---|---|
8a6ff07f GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 É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.linuxtools.tmf.core.tests.statesystem; | |
14 | ||
15 | import static org.junit.Assert.assertNotNull; | |
16 | import static org.junit.Assert.assertNull; | |
17 | import static org.junit.Assert.fail; | |
18 | ||
19 | import org.eclipse.core.runtime.NullProgressMonitor; | |
20 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; | |
21 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; | |
22 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; | |
23 | import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule; | |
24 | import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace; | |
25 | import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; | |
26 | import org.junit.After; | |
27 | import org.junit.Before; | |
28 | import org.junit.Rule; | |
29 | import org.junit.Test; | |
30 | import org.junit.rules.TestRule; | |
31 | import org.junit.rules.Timeout; | |
32 | ||
33 | /** | |
34 | * Test the {@link TmfStateSystemAnalysisModule} class | |
35 | * | |
36 | * @author Geneviève Bastien | |
37 | */ | |
38 | public class StateSystemAnalysisModuleTest { | |
39 | ||
40 | /** Time-out tests after 20 seconds */ | |
41 | @Rule | |
42 | public TestRule globalTimeout= new Timeout(20000); | |
43 | ||
44 | /** ID of the test state system analysis module */ | |
45 | public static final String MODULE_SS = "org.eclipse.linuxtools.tmf.core.tests.analysis.sstest"; | |
46 | ||
09ec275e | 47 | private TmfStateSystemAnalysisModule module; |
8a6ff07f GB |
48 | |
49 | /** | |
50 | * Setup test trace | |
51 | */ | |
52 | @Before | |
53 | public void setupTraces() { | |
09ec275e AM |
54 | TmfTraceStub trace = (TmfTraceStub) TmfTestTrace.A_TEST_10K.getTrace(); |
55 | TmfSignalManager.deregister(trace); | |
56 | trace.traceOpened(new TmfTraceOpenedSignal(this, trace, null)); | |
57 | ||
58 | module = (TmfStateSystemAnalysisModule) trace.getAnalysisModule(MODULE_SS); | |
8a6ff07f GB |
59 | } |
60 | ||
61 | /** | |
62 | * Some tests use traces, let's clean them here | |
63 | */ | |
64 | @After | |
65 | public void cleanupTraces() { | |
66 | TmfTestTrace.A_TEST_10K.dispose(); | |
67 | } | |
68 | ||
69 | /** | |
70 | * Test the state system module execution and result | |
71 | */ | |
72 | @Test | |
73 | public void testSsModule() { | |
09ec275e | 74 | ITmfStateSystem ss = module.getStateSystem(); |
8a6ff07f GB |
75 | assertNull(ss); |
76 | module.schedule(); | |
77 | if (module.waitForCompletion(new NullProgressMonitor())) { | |
78 | ss = module.getStateSystem(); | |
79 | assertNotNull(ss); | |
80 | } else { | |
81 | fail("Module did not complete properly"); | |
82 | } | |
83 | } | |
84 | ||
09ec275e AM |
85 | /** |
86 | * Make sure that the state system is initialized after calling | |
87 | * {@link TmfStateSystemAnalysisModule#waitForInitialization()}. | |
88 | */ | |
89 | @Test | |
90 | public void testInitialization() { | |
91 | assertNull(module.getStateSystem()); | |
92 | module.schedule(); | |
93 | ||
94 | module.waitForInitialization(); | |
95 | assertNotNull(module.getStateSystem()); | |
96 | } | |
97 | ||
8a6ff07f | 98 | } |