gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / stateprovider / PartialStateSystemTest.java
index 6eb4882c9ccd402e3680003057ff0e785ec92b0e..5e33dcdbd6dfc95fc6ce466e2d0da6d754978224 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 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
@@ -7,21 +7,29 @@
  *
  * Contributors:
  *   Alexandre Montplaisir - Initial API and implementation
+ *   Bernd Hufmann - Use state system analysis module instead of factory
  ******************************************************************************/
 
 package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider;
 
-import static org.junit.Assume.assumeTrue;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
-import java.io.IOException;
-
-import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateProvider;
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory;
-import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
-import org.junit.BeforeClass;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider;
+import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
+import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
+import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
+import org.junit.After;
 import org.junit.Test;
 
 /**
@@ -31,23 +39,39 @@ import org.junit.Test;
  */
 public class PartialStateSystemTest extends StateSystemTest {
 
+    private static final @NonNull String TEST_FILE_NAME = "test-partial";
+
+    private File stateFile;
+    private TestLttngKernelAnalysisModule module;
+
+    @Override
+    protected ITmfStateSystem initialize() {
+        stateFile = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + TEST_FILE_NAME);
+        if (stateFile.exists()) {
+            stateFile.delete();
+        }
+
+        module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);
+        try {
+            module.setTrace(testTrace.getTrace());
+        } catch (TmfAnalysisException e) {
+            fail();
+        }
+        module.schedule();
+        assertTrue(module.waitForCompletion());
+        return module.getStateSystem();
+    }
+
     /**
-     * Initialization
+     * Class clean-up
      */
-    @BeforeClass
-    public static void initialize() {
-        assumeTrue(CtfTmfTestTraces.tracesExist());
-        File stateFile = null;
-        try {
-            stateFile = File.createTempFile("test-partial", ".ht");
-            stateFile.deleteOnExit();
-
-            input = new CtfKernelStateProvider(CtfTmfTestTraces.getTestTrace(TRACE_INDEX));
-            ssq = TmfStateSystemFactory.newPartialHistory(stateFile, input, true);
-        } catch (IOException e) {
-            e.printStackTrace();
-        } catch (TmfTraceException e) {
-            e.printStackTrace();
+    @After
+    public void cleanup() {
+        if (module != null) {
+            module.close();
+        }
+        if (stateFile != null) {
+            stateFile.delete();
         }
     }
 
@@ -112,4 +136,44 @@ public class PartialStateSystemTest extends StateSystemTest {
     public void testRangeQueryInvalidTime2() throws TimeRangeException {
         super.testRangeQueryInvalidTime2();
     }
+
+    @NonNullByDefault
+    private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule {
+
+        private final String htFileName;
+
+        /**
+         * Constructor adding the views to the analysis
+         * @param htFileName
+         *      The History File Name
+         */
+        public TestLttngKernelAnalysisModule(String htFileName) {
+            super();
+            this.htFileName = htFileName;
+        }
+
+        @Override
+        public void setTrace(@Nullable ITmfTrace trace) throws TmfAnalysisException {
+            if (!(trace instanceof CtfTmfTrace)) {
+                throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$
+            }
+            super.setTrace(trace);
+        }
+
+        @Override
+        protected ITmfStateProvider createStateProvider() {
+            return new LttngKernelStateProvider(getTrace());
+        }
+
+        @Override
+        protected StateSystemBackendType getBackendType() {
+            return StateSystemBackendType.PARTIAL;
+        }
+
+        @Override
+        protected String getSsFileName() {
+            return htFileName;
+        }
+
+    }
 }
This page took 0.026247 seconds and 5 git commands to generate.