LTTng: CPU usage analysis from the LTTng kernel trace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfTraceTest.java
index 5d81111557ab8f779cadae766c160b4c5c24fbfd..602551c5767440c00f910c4f2b7414d9797854c8 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 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
 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.junit.After;
 import org.junit.Before;
@@ -47,20 +50,10 @@ import org.junit.Test;
  */
 public class CtfTmfTraceTest {
 
-    private static final String PATH = TestParams.getPath();
+    private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
 
     private CtfTmfTrace fixture;
 
-    /**
-     * Launch the test.
-     *
-     * @param args
-     *            the command line arguments
-     */
-    public static void main(String[] args) {
-        new org.junit.runner.JUnitCore().run(CtfTmfTraceTest.class);
-    }
-
     /**
      * Perform pre-test initialization.
      *
@@ -69,8 +62,9 @@ public class CtfTmfTraceTest {
      */
     @Before
     public void setUp() throws TmfTraceException {
+        assumeTrue(testTrace.exists());
         fixture = new CtfTmfTrace();
-        fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class);
+        fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
     }
 
     /**
@@ -78,7 +72,9 @@ public class CtfTmfTraceTest {
      */
     @After
     public void tearDown() {
-        fixture.dispose();
+        if (fixture != null) {
+            fixture.dispose();
+        }
     }
 
     /**
@@ -93,9 +89,7 @@ public class CtfTmfTraceTest {
         assertEquals(1000, result.getCacheSize());
         assertEquals(0L, result.getNbEvents());
         assertEquals(0L, result.getStreamingInterval());
-        assertNull(result.getStateSystem());
         assertNull(result.getResource());
-        assertEquals(1000, result.getQueueSize());
         assertNull(result.getType());
     }
 
@@ -180,22 +174,13 @@ public class CtfTmfTraceTest {
     }
 
     /**
-     * Run the String[] getEnvNames() method test.
-     */
-    @Test
-    public void testGetEnvNames() {
-        String[] result = fixture.getEnvNames();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String getEnvValue(String) method test.
+     * Run the String getEnvironment method test.
      */
     @Test
     public void testGetEnvValue() {
-        String key = "tracer_name"; //$NON-NLS-1$
-        String result = fixture.getEnvValue(key);
-        assertEquals("\"lttng-modules\"",result); //$NON-NLS-1$
+        String key = "tracer_name";
+        String result = fixture.getTraceProperties().get(key);
+        assertEquals("\"lttng-modules\"",result);
     }
 
     /**
@@ -203,7 +188,7 @@ public class CtfTmfTraceTest {
      */
     @Test
     public void testGetEventType() {
-        Class<ITmfEvent> result = fixture.getEventType();
+        Class<? extends ITmfEvent> result = fixture.getEventType();
         assertNotNull(result);
     }
 
@@ -212,9 +197,8 @@ public class CtfTmfTraceTest {
      */
     @Test
     public void testGetLocationRatio() {
-        final CtfLocationData location2 = new CtfLocationData(1, 0);
+        final CtfLocationInfo location2 = new CtfLocationInfo(1, 0);
         CtfLocation location = new CtfLocation(location2);
-        location.setLocation(location2);
         double result = fixture.getLocationRatio(location);
 
         assertEquals(Double.NEGATIVE_INFINITY, result, 0.1);
@@ -234,7 +218,7 @@ public class CtfTmfTraceTest {
      */
     @Test
     public void testGetNbEnvVars() {
-        int result = fixture.getNbEnvVars();
+        int result = fixture.getTraceProperties().size();
         assertEquals(8, result);
     }
 
@@ -284,15 +268,6 @@ public class CtfTmfTraceTest {
         assertNotNull(result);
     }
 
-    /**
-     * Run the IStateSystemQuerier getStateSystem() method test.
-     */
-    @Test
-    public void testGetStateSystem() {
-        IStateSystemQuerier result = fixture.getStateSystem();
-        assertNull(result);
-    }
-
     /**
      * Run the long getStreamingInterval() method test.
      */
@@ -356,7 +331,7 @@ public class CtfTmfTraceTest {
      */
     @Test
     public void testSeekEvent_location() {
-        final CtfLocationData location2 = new CtfLocationData(1L, 0L);
+        final CtfLocationInfo location2 = new CtfLocationInfo(1L, 0L);
         CtfLocation ctfLocation = new CtfLocation(location2);
         ITmfContext result = fixture.seekEvent(ctfLocation);
         assertNotNull(result);
@@ -368,8 +343,32 @@ public class CtfTmfTraceTest {
     @Test
     public void testValidate() {
         IProject project = null;
-        String path = PATH;
-        boolean result = fixture.validate(project, path);
-        assertTrue(result);
+        IStatus result = fixture.validate(project, testTrace.getPath());
+        assertTrue(result.isOK());
+    }
+
+    /**
+     * Run the boolean hasEvent(final String) method test
+     */
+    @Test
+    public void testEventLookup() {
+        assertTrue(fixture.hasEvent("sched_switch"));
+        assertFalse(fixture.hasEvent("Sched_switch"));
+        String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
+        assertTrue(fixture.hasAllEvents(events));
+        assertTrue(fixture.hasAtLeastOneOfEvents(events));
+        String[] names = { "inexistent", "sched_switch", "SomeThing" };
+        assertTrue(fixture.hasAtLeastOneOfEvents(names));
+        assertFalse(fixture.hasAllEvents(names));
     }
+
+    /**
+     * Run the String getHostId() method test
+     */
+    @Test
+    public void testCtfHostId() {
+        String a = fixture.getHostId();
+        assertEquals("\"84db105b-b3f4-4821-b662-efc51455106a\"", a);
+    }
+
 }
This page took 0.026553 seconds and 5 git commands to generate.