--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stateprovider;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
+
+/**
+ * Test the pattern analysis module
+ *
+ * @author Jean-Christian Kouame
+ */
+public class PatternModuleTest extends XmlModuleTestBase {
+
+ @Override
+ protected String getAnalysisId() {
+ return "syscall.analysis";
+ }
+
+ @Override
+ protected String getAnalysisName() {
+ return "XML system call analysis";
+ }
+
+ @Override
+ protected TmfXmlTestFiles getXmlFile() {
+ return TmfXmlTestFiles.VALID_PATTERN_FILE;
+ }
+
+ @Override
+ protected @NonNull String getAnalysisNodeName() {
+ return TmfXmlStrings.PATTERN;
+ }
+
+ @Override
+ protected @NonNull CtfTestTrace getTrace() {
+ return CtfTestTrace.ARM_64_BIT_HEADER;
+ }
+
+}
/*******************************************************************************
- * Copyright (c) 2013, 2014 École Polytechnique de Montréal
+ * Copyright (c) 2013, 2016 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stateprovider;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
-import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
-import org.junit.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
/**
* Test suite for the XmlStateSystemModule Test. It tests the reading of the
*
* @author Geneviève Bastien
*/
-public class StateProviderModuleTest {
-
- private static String ANALYSIS_ID = "kernel.linux.sp";
- private static String ANALYSIS_NAME = "Xml kernel State System";
-
- private XmlStateSystemModule fModule;
-
- /**
- * Test the module construction
- */
- @Test
- public void testModuleConstruction() {
-
- Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument();
- assertNotNull(doc);
-
- /* get State Providers modules */
- NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
- assertTrue(stateproviderNodes.getLength() > 0);
-
- Element node = (Element) stateproviderNodes.item(0);
- fModule = new XmlStateSystemModule();
- String moduleId = node.getAttribute(TmfXmlStrings.ID);
- assertNotNull(moduleId);
- fModule.setId(moduleId);
- assertEquals(ANALYSIS_ID, fModule.getId());
-
- fModule.setXmlFile(TmfXmlTestFiles.VALID_FILE.getPath());
+public class StateProviderModuleTest extends XmlModuleTestBase {
- assertEquals(ANALYSIS_NAME, fModule.getName());
+ @Override
+ protected String getAnalysisId() {
+ return "kernel.linux.sp";
}
- /**
- * Test the module executes correctly
- */
- @Test
- public void testModuleExecution() {
- Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument();
- assertNotNull(doc);
-
- /* get State Providers modules */
- NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
-
- Element node = (Element) stateproviderNodes.item(0);
- fModule = new XmlStateSystemModule();
- String moduleId = node.getAttribute(TmfXmlStrings.ID);
- assertNotNull(moduleId);
- fModule.setId(moduleId);
-
- fModule.setXmlFile(TmfXmlTestFiles.VALID_FILE.getPath());
+ @Override
+ protected String getAnalysisName() {
+ return "Xml kernel State System";
+ }
- CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.KERNEL);
- try {
- fModule.setTrace(trace);
- fModule.schedule();
- assertTrue(fModule.waitForCompletion(new NullProgressMonitor()));
+ @Override
+ protected TmfXmlTestFiles getXmlFile() {
+ return TmfXmlTestFiles.VALID_FILE;
+ }
- } catch (TmfAnalysisException e) {
- fail("Cannot set trace " + e.getMessage());
- } finally {
- trace.dispose();
- }
+ @Override
+ protected @NonNull String getAnalysisNodeName() {
+ return TmfXmlStrings.STATE_PROVIDER;
+ }
+ @Override
+ protected @NonNull CtfTestTrace getTrace() {
+ return CtfTestTrace.KERNEL;
}
+
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stateprovider;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * Base test for XML analysis module
+ *
+ * @author Jean-Christian Kouame
+ */
+public abstract class XmlModuleTestBase {
+
+ private TmfAbstractAnalysisModule fModule;
+
+ /**
+ * Test the module construction
+ */
+ @Test
+ public void testModuleConstruction() {
+
+ Document doc = getXmlFile().getXmlDocument();
+ assertNotNull(doc);
+
+ /* get analysis modules */
+ NodeList analysisNodes = doc.getElementsByTagName(getAnalysisNodeName());
+ assertTrue(analysisNodes.getLength() > 0);
+
+ final Element node = (Element) analysisNodes.item(0);
+ assertNotNull(node);
+
+ createModule(node);
+
+ String moduleId = node.getAttribute(TmfXmlStrings.ID);
+ assertNotNull(moduleId);
+ fModule.setId(moduleId);
+ assertEquals(getAnalysisId(), fModule.getId());
+
+ assertEquals(getAnalysisName(), fModule.getName());
+ }
+
+ private void createModule(@NonNull Element element) {
+ switch (getAnalysisNodeName()) {
+ case TmfXmlStrings.PATTERN:
+ fModule = new XmlPatternAnalysis();
+ ((XmlPatternAnalysis) fModule).setXmlFile(new Path(getXmlFile().getFile().getAbsolutePath()));
+ fModule.setName(getName(element));
+ break;
+ case TmfXmlStrings.STATE_PROVIDER:
+ fModule = new XmlStateSystemModule();
+ ((XmlStateSystemModule) fModule).setXmlFile(new Path(getXmlFile().getFile().getAbsolutePath()));
+ break;
+
+ default:
+ fail();
+ }
+ }
+
+ /**
+ * Get the analysis XML node name
+ *
+ * @return The name
+ */
+ protected abstract @NonNull String getAnalysisNodeName();
+
+ /**
+ * Get the XML file this test use
+ *
+ * @return The file
+ */
+ protected abstract TmfXmlTestFiles getXmlFile();
+
+ /**
+ * Get the analysis name
+ *
+ * @return The name
+ */
+ protected abstract String getAnalysisName();
+
+ /**
+ * Get the id of the analysis
+ *
+ * @return The id
+ */
+ protected abstract String getAnalysisId();
+
+ /**
+ * Get the trace this test use
+ *
+ * @return The trace
+ */
+ protected abstract @NonNull CtfTestTrace getTrace();
+
+ /**
+ * Get the name of the analysis
+ *
+ * @param element
+ * The analysis element
+ * @return The name
+ */
+ public @NonNull String getName(Element element) {
+ String name = null;
+ List<Element> head = XmlUtils.getChildElements(element, TmfXmlStrings.HEAD);
+ if (head.size() == 1) {
+ List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
+ if (!labels.isEmpty()) {
+ name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
+ }
+ }
+ assertNotNull("analysis name", name);
+ return name;
+ }
+
+ /**
+ * Test the module executes correctly
+ */
+ @Test
+ public void testModuleExecution() {
+ Document doc = getXmlFile().getXmlDocument();
+ assertNotNull(doc);
+
+ /* get State Providers modules */
+ NodeList stateproviderNodes = doc.getElementsByTagName(getAnalysisNodeName());
+
+ Element node = (Element) stateproviderNodes.item(0);
+ assertNotNull(node);
+
+ createModule(node);
+
+ String moduleId = node.getAttribute(TmfXmlStrings.ID);
+ assertNotNull(moduleId);
+ fModule.setId(moduleId);
+
+ CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(getTrace());
+ try {
+ fModule.setTrace(trace);
+ fModule.schedule();
+ assertTrue(fModule.waitForCompletion(new NullProgressMonitor()));
+
+ } catch (TmfAnalysisException e) {
+ fail("Cannot set trace " + e.getMessage());
+ } finally {
+ trace.dispose();
+ }
+
+ }
+}