1 /*******************************************************************************
2 * Copyright (c) 2016 É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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.model
;
12 import static org
.junit
.Assert
.assertNotNull
;
14 import org
.eclipse
.jdt
.annotation
.NonNull
;
15 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.stateprovider
.XmlStateSystemModule
;
16 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
17 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
18 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
19 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
20 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
21 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.common
.TmfXmlTestFiles
;
22 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.module
.XmlUtilsTest
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
25 import org
.junit
.After
;
26 import org
.junit
.Before
;
27 import org
.junit
.Test
;
30 * Test the various cases for the state value changes. To add new test cases,
31 * the trace test file and the state value test files can be modified to cover
34 * @author Geneviève Bastien
36 public class TmfStateValueTest
{
38 private static final @NonNull String TEST_TRACE
= "test_traces/testTrace4.xml";
41 XmlStateSystemModule fModule
;
44 * Initializes the trace and the module for the tests
46 * @throws TmfAnalysisException
47 * Any exception thrown during module initialization
50 public void setUp() throws TmfAnalysisException
{
51 ITmfTrace trace
= XmlUtilsTest
.initializeTrace(TEST_TRACE
);
52 XmlStateSystemModule module
= XmlUtilsTest
.initializeModule(TmfXmlTestFiles
.STATE_VALUE_FILE
);
54 module
.setTrace(trace
);
57 module
.waitForCompletion();
64 * Dispose the module and the trace
67 public void cleanUp() {
73 * Test that the ongoing state is updated instead of creating a new state
75 * @throws StateSystemDisposedException
76 * Exceptions thrown during state system verification
77 * @throws AttributeNotFoundException
78 * Exceptions thrown during state system verification
81 public void testStateValueUpdate() throws AttributeNotFoundException
, StateSystemDisposedException
{
82 XmlStateSystemModule module
= fModule
;
83 assertNotNull(module
);
85 ITmfStateSystem ss
= module
.getStateSystem();
88 int quark
= ss
.getQuarkAbsolute("update", "0");
90 final int[] expectedStarts
= { 1, 3, 5, 7, 7 };
91 ITmfStateValue
[] expectedValues
= { TmfStateValue
.newValueString("GOOD"), TmfStateValue
.nullValue(), TmfStateValue
.newValueString("BAD"), TmfStateValue
.nullValue() };
92 XmlUtilsTest
.verifyStateIntervals("testStateValueUpdate", ss
, quark
, expectedStarts
, expectedValues
);
97 * Test that a state change with no update causes the modification of the
98 * state value at the time of the event
100 * @throws StateSystemDisposedException
101 * Exceptions thrown during state system verification
102 * @throws AttributeNotFoundException
103 * Exceptions thrown during state system verification
106 public void testStateValueModify() throws AttributeNotFoundException
, StateSystemDisposedException
{
107 XmlStateSystemModule module
= fModule
;
108 assertNotNull(module
);
110 ITmfStateSystem ss
= module
.getStateSystem();
113 int quark
= ss
.getQuarkAbsolute("modify", "0");
115 final int[] expectedStarts
= { 1, 3, 5, 7, 7 };
116 ITmfStateValue
[] expectedValues
= { TmfStateValue
.newValueString("UNKNOWN"), TmfStateValue
.newValueString("GOOD"), TmfStateValue
.newValueString("UNKNOWN"), TmfStateValue
.newValueString("BAD") };
117 XmlUtilsTest
.verifyStateIntervals("testStateValueModify", ss
, quark
, expectedStarts
, expectedValues
);
123 * it tests that a state change on stack, with a peek() condition. This test
124 * verifies the value on the top of the stack and verifies that the peek
125 * operation do not remove the value on the top of the stack.
127 * @throws StateSystemDisposedException
128 * Exceptions thrown during state system verification
129 * @throws AttributeNotFoundException
130 * Exceptions thrown during state system verification
133 public void testStateValuePeek() throws AttributeNotFoundException
, StateSystemDisposedException
{
134 XmlStateSystemModule module
= fModule
;
135 assertNotNull(module
);
137 ITmfStateSystem ss
= module
.getStateSystem();
140 int quark
= ss
.getQuarkAbsolute("stack");
142 final int[] expectedStarts
= { 1, 5, 7, 7 };
143 ITmfStateValue
[] expectedValues
= { TmfStateValue
.newValueLong(1l), TmfStateValue
.newValueLong(5l), TmfStateValue
.newValueLong(1l) };
144 XmlUtilsTest
.verifyStackStateIntervals("testStateValueModify", ss
, quark
, expectedStarts
, expectedValues
);