| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2015 Ericsson |
| 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 | * Jean-Christian Kouame - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stateprovider; |
| 13 | |
| 14 | import static org.junit.Assert.assertEquals; |
| 15 | import static org.junit.Assert.assertNotNull; |
| 16 | import static org.junit.Assert.fail; |
| 17 | |
| 18 | import java.util.List; |
| 19 | |
| 20 | import org.eclipse.jdt.annotation.NonNull; |
| 21 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
| 22 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; |
| 23 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; |
| 24 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; |
| 25 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; |
| 26 | import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule; |
| 27 | import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles; |
| 28 | import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest; |
| 29 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException; |
| 30 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
| 31 | import org.junit.Test; |
| 32 | |
| 33 | /** |
| 34 | * Test suite for the XML conditions |
| 35 | * |
| 36 | */ |
| 37 | public class TmfXmlConditionTest { |
| 38 | |
| 39 | private static final @NonNull String testTrace2 = "test_traces/testTrace2.xml"; |
| 40 | |
| 41 | /** |
| 42 | * |
| 43 | */ |
| 44 | @Test |
| 45 | public void testConditionsValidation() { |
| 46 | ITmfTrace trace = XmlUtilsTest.initializeTrace(testTrace2); |
| 47 | XmlStateSystemModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.CONDITION_FILE); |
| 48 | try { |
| 49 | module.setTrace(trace); |
| 50 | |
| 51 | module.schedule(); |
| 52 | module.waitForCompletion(); |
| 53 | |
| 54 | ITmfStateSystem ss = module.getStateSystem(); |
| 55 | assertNotNull(ss); |
| 56 | |
| 57 | List<Integer> quarks = ss.getQuarks("*"); |
| 58 | assertEquals(3, quarks.size()); |
| 59 | |
| 60 | for (Integer quark : quarks) { |
| 61 | String name = ss.getAttributeName(quark); |
| 62 | switch (name) { |
| 63 | case "test": { |
| 64 | final int[] expectedStarts = { 1, 5, 7 }; |
| 65 | ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0) }; |
| 66 | XmlUtilsTest.verifyStateIntervals("test", ss, quark, expectedStarts, expectedValues); |
| 67 | } |
| 68 | break; |
| 69 | case "test1": { |
| 70 | final int[] expectedStarts = { 1, 3, 7, 7 }; |
| 71 | ITmfStateValue[] expectedValues = { TmfStateValue.nullValue(), TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1) }; |
| 72 | XmlUtilsTest.verifyStateIntervals("test1", ss, quark, expectedStarts, expectedValues); |
| 73 | } |
| 74 | break; |
| 75 | case "checkpoint": { |
| 76 | final int[] expectedStarts = { 1, 5, 7, 7 }; |
| 77 | ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0) }; |
| 78 | XmlUtilsTest.verifyStateIntervals("checkpoint", ss, quark, expectedStarts, expectedValues); |
| 79 | } |
| 80 | break; |
| 81 | default: |
| 82 | fail("Wrong attribute name " + name); |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | } catch (TmfAnalysisException | AttributeNotFoundException | StateSystemDisposedException e) { |
| 87 | fail(e.getMessage()); |
| 88 | } finally { |
| 89 | module.dispose(); |
| 90 | trace.dispose(); |
| 91 | } |
| 92 | } |
| 93 | } |