lttng: Unit tests for the UST callstack provider
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 12 Sep 2013 19:59:29 +0000 (15:59 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 17 Sep 2013 22:19:57 +0000 (18:19 -0400)
Also contains a small fix to actually create the temporary folder
returned by TmfTraceManager.getSupplementaryFileDir() when it's
used in unit tests.

Change-Id: Iafed5c7099f15d36badd6d486cc0cf632df38c53
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/16399
Tested-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
IP-Clean: Genevieve Bastien <gbastien+lttng@versatic.net>

14 files changed:
org.eclipse.linuxtools.ctf.core.tests/pom.xml
org.eclipse.linuxtools.ctf.core.tests/shared/org/eclipse/linuxtools/ctf/core/tests/shared/CtfTestTrace.java
org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore
org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.sh
org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.xml
org.eclipse.linuxtools.lttng2.ust.core.tests/.settings/org.eclipse.jdt.core.prefs
org.eclipse.linuxtools.lttng2.ust.core.tests/META-INF/MANIFEST.MF
org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/AllTests.java
org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/AllTests.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderFastTest.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderTest.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/TestUtils.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java

index 449cb4ac8c69f4c86cc231ad5f0c6f09e77099f3..831d5a7a9a559d39d103ee9e16282a69f6f6d04a 100644 (file)
                   </excludes>
                 </fileset>
                 <fileset><directory>traces/ctf-testsuite</directory></fileset>
+                <fileset><directory>traces/cyg-profile</directory></fileset>
                 <fileset><directory>traces/hello-lost</directory></fileset>
                 <fileset><directory>traces/kernel</directory></fileset>
                 <fileset><directory>traces/kernel_vm</directory></fileset>
+                <fileset><directory>traces/synctraces</directory></fileset>
                 <fileset><directory>traces/trace2</directory></fileset>
               </filesets>
             </configuration>
index 28c511c2634b64b590754956bec458dedf753575..f125bb6808e9e9f6e239c6c3deb74c0023a198c7 100644 (file)
@@ -27,16 +27,27 @@ import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 public enum CtfTestTrace {
     /** Example kernel trace */
     KERNEL("../org.eclipse.linuxtools.ctf.core.tests/traces/kernel"),
+
     /** Another kernel trace */
     TRACE2("../org.eclipse.linuxtools.ctf.core.tests/traces/trace2"),
+
     /** Kernel trace with event contexts */
     KERNEL_VM("../org.eclipse.linuxtools.ctf.core.tests/traces/kernel_vm"),
+
     /** Trace synchronization: source trace */
     SYNC_SRC("../org.eclipse.linuxtools.ctf.core.tests/traces/synctraces/scp_src"),
+
     /** Trace synchronization: destination trace */
     SYNC_DEST("../org.eclipse.linuxtools.ctf.core.tests/traces/synctraces/scp_dest"),
+
     /** UST trace with lots of lost events */
-    HELLO_LOST("../org.eclipse.linuxtools.ctf.core.tests/traces/hello-lost");
+    HELLO_LOST("../org.eclipse.linuxtools.ctf.core.tests/traces/hello-lost"),
+
+    /** UST trace with lttng-ust-cyg-profile events (aka -finstrument-functions) */
+    CYG_PROFILE("../org.eclipse.linuxtools.ctf.core.tests/traces/cyg-profile/glxgears-cyg-profile"),
+
+    /** UST trace with lttng-ust-cyg-profile-fast events (no address in func_exit) */
+    CYG_PROFILE_FAST("../org.eclipse.linuxtools.ctf.core.tests/traces/cyg-profile/glxgears-cyg-profile-fast");
 
 
     private final String fPath;
index 3678d68c2fe24c2a31f81e6969809f071d4a6553..3f6d15926fecb8821daf1d843843cc935924bcf3 100644 (file)
@@ -3,6 +3,7 @@
 *.tar
 *.ht
 /ctf-testsuite
+/cyg-profile
 /hello-lost
 /kernel
 /kernel_vm
index 66c4f1dd64212c92498da8411005cd0013acf0df..ed3264f2cb2587933ded27fe9374657ab6fe340a 100755 (executable)
@@ -26,8 +26,11 @@ wget http://www.dorsal.polymtl.ca/~alexmont/data/kernel_vm.tar.bz2 -O- | tar xvj
 wget http://www.dorsal.polymtl.ca/~alexmont/data/hello-lost.tar.bz2 -O- | tar xvjf - &&
 
 # CTF test suite, used for testing CTF parser compliance
-git clone https://github.com/efficios/ctf-testsuite.git
+git clone https://github.com/efficios/ctf-testsuite.git &&
 
 # Trace used by the lttng2 kernel to match packets and synchronize
 wget http://www.dorsal.polymtl.ca/~gbastien/traces/synctraces.tar.gz -O- | tar xvzf - &&
 
+# Traces with lttng-ust-cyg-profile (-finstrument-functions) events
+wget http://www.dorsal.polymtl.ca/~alexmont/data/cyg-profile.tar.bz2 -O- | tar xvjf -
+
index 588be110cd48b660d698c6ee803886638c5ec658..f7e52bd02398fcf940239fce09095e1edb38dca9 100644 (file)
@@ -16,6 +16,7 @@
   <get ignoreerrors="true" dest="kernel_vm.tar.bz2" skipexisting="true" src="http://www.dorsal.polymtl.ca/~alexmont/data/kernel_vm.tar.bz2" />
   <get ignoreerrors="true" dest="synctraces.tar.gz" skipexisting="true" src="http://www.dorsal.polymtl.ca/~gbastien/traces/synctraces.tar.gz" />
   <get ignoreerrors="true" dest="hello-lost.tar.bz2" skipexisting="true" src="http://www.dorsal.polymtl.ca/~alexmont/data/hello-lost.tar.bz2" />
+  <get ignoreerrors="true" dest="cyg-profile.tar.bz2" skipexisting="true" src="http://www.dorsal.polymtl.ca/~alexmont/data/cyg-profile.tar.bz2" />
   <exec executable = "git" failifexecutionfails="false">
     <arg value = "clone"/>
     <arg value = "https://github.com/efficios/ctf-testsuite.git"/>
@@ -33,6 +34,7 @@
       <available file="kernel_vm.tar.bz2" />
       <available file="synctraces.tar.gz" />
       <available file="hello-lost.tar.bz2" />
+      <available file="cyg-profile.tar.bz2" />
     </and>
   </condition>
   <antcall target="extractTraces"/>
     <bunzip2 src="kernel_vm.tar.bz2" />
     <gunzip src="synctraces.tar.gz" />
     <bunzip2 src="hello-lost.tar.bz2" />
-    
+    <bunzip2 src="cyg-profile.tar.bz2" />
+
     <untar src="sample-ctf-trace-20120412.tar" dest="." />
     <untar src="trace2.tar" dest="." />
     <untar src="kernel_vm.tar" dest="." />
     <untar src="synctraces.tar" dest="." />
     <untar src="hello-lost.tar" dest="." />
+    <untar src="cyg-profile.tar" dest="." />
 
     <echo message="Traces extracted successfully"/>
 </target>
index 749fd0eb9ab4cc173ece2dcaef913d61cecdcf9f..7acb262bd4f12f6409ab0cd51f5ed6c571069f76 100644 (file)
@@ -61,7 +61,7 @@ org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
 org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
 org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
 org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
 org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
 org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
 org.eclipse.jdt.core.compiler.problem.nullReference=error
index b32f5181a1deb2cd6f3c2a75fe4841b4c9a5d059..541da9ab592fcecc7e08c9370aad2b0590f3b3df 100644 (file)
@@ -7,5 +7,11 @@ Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.ust.core.tests;singleton:=true
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.junit;bundle-version="4.0.0"
-Export-Package: org.eclipse.linuxtools.lttng2.ust.core.tests
+Require-Bundle: org.junit;bundle-version="4.0.0",
+ org.eclipse.core.resources,
+ org.eclipse.core.runtime,
+ org.eclipse.linuxtools.tmf.core,
+ org.eclipse.linuxtools.tmf.core.tests;bundle-version="3.0.0",
+ org.eclipse.linuxtools.lttng2.ust.core
+Export-Package: org.eclipse.linuxtools.lttng2.ust.core.tests,
+ org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack
index 81492a7042c5e0a1d7da12c0b9e326b451319231..cd1cb1cae707f7e6230e1fa4c3a046313c48eab4 100644 (file)
@@ -20,6 +20,7 @@ import org.junit.runners.Suite;
  */
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
-    ActivatorTest.class
+    ActivatorTest.class,
+    org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack.AllTests.class
 })
 public class AllTests { }
diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/AllTests.java b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/AllTests.java
new file mode 100644 (file)
index 0000000..d346900
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    LttngUstCallStackProviderFastTest.class,
+    LttngUstCallStackProviderTest.class
+})
+public class AllTests {
+
+}
diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderFastTest.java b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderFastTest.java
new file mode 100644 (file)
index 0000000..89715ee
--- /dev/null
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.linuxtools.lttng2.ust.core.trace.LttngUstTrace;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test suite for the UST callstack state provider, using the trace of a program
+ * instrumented with lttng-ust-cyg-profile-fast.so tracepoints. These do not
+ * contain the function addresses in the func_exit events.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class LttngUstCallStackProviderFastTest {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.CYG_PROFILE_FAST;
+
+    private static final String PROCNAME = "glxgears-29822";
+
+    private static LttngUstTrace fixture = null;
+
+    // ------------------------------------------------------------------------
+    // Class  methods
+    // ------------------------------------------------------------------------
+
+    /**
+     * Perform pre-class initialization.
+     *
+     * @throws TmfTraceException
+     *             If the test trace is not found
+     */
+    @BeforeClass
+    public static void setUp() throws TmfTraceException {
+        assumeTrue(testTrace.exists());
+
+        /* We init the trace ourselves (we need the specific LttngUstTrace type) */
+        fixture = new LttngUstTrace();
+        IStatus valid = fixture.validate(null, testTrace.getPath());
+        assertTrue(valid.isOK());
+        fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
+        TestUtils.openTrace(fixture);
+    }
+
+    /**
+     * Perform post-class clean-up.
+     */
+    @AfterClass
+    public static void tearDown() {
+        if (fixture != null) {
+            fixture.dispose();
+            File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(fixture));
+            TestUtils.deleteDirectory(suppDir);
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Test methods
+    // ------------------------------------------------------------------------
+
+    /**
+     * Test that the callstack state system is there and contains data.
+     */
+    @Test
+    public void testConstruction() {
+        ITmfStateSystem ss = fixture.getStateSystems().get(TestUtils.SSID);
+        assertNotNull(ss);
+        assertTrue(ss.getNbAttributes() > 0);
+    }
+
+    /**
+     * Test the callstack at the beginning of the state system.
+     */
+    @Test
+    public void testCallStackBegin() {
+        long start = fixture.getStateSystems().get(TestUtils.SSID).getStartTime();
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, start);
+        assertEquals(1, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+    }
+
+    /**
+     * Test the callstack somewhere in the trace.
+     */
+    @Test
+    public void testCallStack1() {
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1379361250310000000L);
+        assertEquals(2, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+        assertEquals("0x403d60", cs[1]);
+    }
+
+    /**
+     * Test the callstack somewhere in the trace.
+     */
+    @Test
+    public void testCallStack2() {
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1379361250498400000L);
+        assertEquals(3, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+        assertEquals("0x403b14", cs[1]);
+        assertEquals("0x401b23", cs[2]);
+    }
+
+    /**
+     * Test the callstack somewhere in the trace.
+     */
+    @Test
+    public void testCallStack3() {
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1379361250499759000L);
+        assertEquals(4, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+        assertEquals("0x4045c8", cs[1]);
+        assertEquals("0x403760", cs[2]);
+        assertEquals("0x401aac", cs[3]);
+    }
+
+    /**
+     * Test the callstack at the end of the trace/state system.
+     */
+    @Test
+    public void testCallStackEnd() {
+        long end = fixture.getStateSystems().get(TestUtils.SSID).getCurrentEndTime();
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, end);
+        assertEquals(3, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+        assertEquals("0x4045c8", cs[1]);
+        assertEquals("0x403760", cs[2]);
+    }
+}
diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderTest.java b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderTest.java
new file mode 100644 (file)
index 0000000..d04fc82
--- /dev/null
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.linuxtools.lttng2.ust.core.trace.LttngUstTrace;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test suite for the UST callstack state provider, using the trace of a program
+ * instrumented with lttng-ust-cyg-profile.so tracepoints.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class LttngUstCallStackProviderTest {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.CYG_PROFILE;
+    private static final CtfTmfTestTrace otherUstTrace = CtfTmfTestTrace.HELLO_LOST;
+
+    private static final String PROCNAME = "glxgears-16073";
+
+    private static LttngUstTrace fixture = null;
+
+    // ------------------------------------------------------------------------
+    // Class  methods
+    // ------------------------------------------------------------------------
+
+    /**
+     * Perform pre-class initialization.
+     *
+     * @throws TmfTraceException
+     *             If the test trace is not found
+     */
+    @BeforeClass
+    public static void setUp() throws TmfTraceException {
+        assumeTrue(testTrace.exists());
+
+        /* We init the trace ourselves (we need the specific LttngUstTrace type) */
+        fixture = new LttngUstTrace();
+        IStatus valid = fixture.validate(null, testTrace.getPath());
+        assertTrue(valid.isOK());
+        fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
+        TestUtils.openTrace(fixture);
+    }
+
+    /**
+     * Perform post-class clean-up.
+     */
+    @AfterClass
+    public static void tearDown() {
+        if (fixture != null) {
+            fixture.dispose();
+            File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(fixture));
+            TestUtils.deleteDirectory(suppDir);
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Test methods
+    // ------------------------------------------------------------------------
+
+    /**
+     * Test the handling of generic UST traces who do not contain the required
+     * information.
+     */
+    @Test
+    public void testOtherUstTrace() {
+        /* Initialize the trace */
+        final LttngUstTrace ustTrace = new LttngUstTrace();
+        IStatus valid = ustTrace.validate(null, otherUstTrace.getPath());
+        assertTrue(valid.isOK());
+        try {
+            ustTrace.initTrace((IResource) null, otherUstTrace.getPath(), CtfTmfEvent.class);
+        } catch (TmfTraceException e) {
+            fail(e.getMessage());
+        }
+        TestUtils.openTrace(ustTrace);
+
+        /* Make sure the generated state system exists, but is empty */
+        ITmfStateSystem ss = ustTrace.getStateSystems().get(TestUtils.SSID);
+        assertNotNull(ss);
+        assertTrue(ss.getStartTime() >= ustTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
+        assertEquals(0, ss.getNbAttributes());
+
+        /* Dispose the trace */
+        ustTrace.dispose();
+        File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(ustTrace));
+        TestUtils.deleteDirectory(suppDir);
+        assertFalse(suppDir.exists());
+    }
+
+    /**
+     * Test that the callstack state system is there and contains data.
+     */
+    @Test
+    public void testConstruction() {
+        ITmfStateSystem ss = fixture.getStateSystems().get(TestUtils.SSID);
+        assertNotNull(ss);
+        assertTrue(ss.getNbAttributes() > 0);
+    }
+
+    /**
+     * Test the callstack at the beginning of the state system.
+     */
+    @Test
+    public void testCallStackBegin() {
+        long start = fixture.getStateSystems().get(TestUtils.SSID).getStartTime();
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, start);
+        assertEquals(1, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+    }
+
+    /**
+     * Test the callstack somewhere in the trace.
+     */
+    @Test
+    public void testCallStack1() {
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1378850463600000000L);
+        assertEquals(2, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+        assertEquals("0x403d60", cs[1]);
+    }
+
+    /**
+     * Test the callstack somewhere in the trace.
+     */
+    @Test
+    public void testCallStack2() {
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1378850463770000000L);
+        assertEquals(3, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+        assertEquals("0x403b14", cs[1]);
+        assertEquals("0x401b23", cs[2]);
+    }
+
+    /**
+     * Test the callstack somewhere in the trace.
+     */
+    @Test
+    public void testCallStack3() {
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1378850463868753000L);
+        assertEquals(4, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+        assertEquals("0x4045c8", cs[1]);
+        assertEquals("0x403760", cs[2]);
+        assertEquals("0x401aac", cs[3]);
+    }
+
+    /**
+     * Test the callstack at the end of the trace/state system.
+     */
+    @Test
+    public void testCallStackEnd() {
+        long end = fixture.getStateSystems().get(TestUtils.SSID).getCurrentEndTime();
+        String[] cs = TestUtils.getCallStack(fixture, PROCNAME, end);
+        assertEquals(3, cs.length);
+
+        assertEquals("0x40472b", cs[0]);
+        assertEquals("0x4045c8", cs[1]);
+        assertEquals("0x403760", cs[2]);
+    }
+}
diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/TestUtils.java b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/TestUtils.java
new file mode 100644 (file)
index 0000000..3b5b23c
--- /dev/null
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ *
+ * Contributors:
+ *   Alexandre Montplaisir - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.linuxtools.lttng2.ust.core.trace.LttngUstTrace;
+import org.eclipse.linuxtools.tmf.core.callstack.CallStackStateProvider;
+import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
+import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
+import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
+
+/**
+ * Common methods for LTTng-UST callstack trace tests.
+ *
+ * @author Alexandre Montplaisir
+ */
+final class TestUtils {
+
+    private TestUtils() {}
+
+    /** ID of the generated state systems */
+    static final String SSID = CallStackStateProvider.ID;
+
+    /** Empty and delete a directory */
+    static void deleteDirectory(File dir) {
+        /* Assuming the dir only contains file or empty directories */
+        for (File file : dir.listFiles()) {
+            file.delete();
+        }
+        dir.delete();
+    }
+
+    /** Simulate a trace being opened (which triggers building the state system) */
+    static void openTrace(LttngUstTrace trace) {
+        trace.indexTrace(true);
+        TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(trace, trace, null));
+        trace.getStateSystems().get(SSID).waitUntilBuilt();
+    }
+
+    /** Get the callstack for the given timestamp, for this particular trace */
+    static String[] getCallStack(LttngUstTrace trace, String processName, long timestamp) {
+        try {
+            ITmfStateSystem ss = trace.getStateSystems().get(SSID);
+            int stackAttribute = ss.getQuarkAbsolute("Threads", processName, "CallStack");
+            List<ITmfStateInterval> state = ss.queryFullState(timestamp);
+            int depth = state.get(stackAttribute).getStateValue().unboxInt();
+
+            int stackTop = ss.getQuarkRelative(stackAttribute, String.valueOf(depth));
+            ITmfStateValue top = state.get(stackTop).getStateValue();
+            assertEquals(top, ss.querySingleStackTop(timestamp, stackAttribute).getStateValue());
+
+            String[] ret = new String[depth];
+            for (int i = 0; i < depth; i++) {
+                int quark = ss.getQuarkRelative(stackAttribute, String.valueOf(i + 1));
+                ret[i] = state.get(quark).getStateValue().unboxStr();
+            }
+            return ret;
+
+        } catch (AttributeNotFoundException e) {
+            fail(e.getMessage());
+        } catch (TimeRangeException e) {
+            fail(e.getMessage());
+        } catch (StateSystemDisposedException e) {
+            fail(e.getMessage());
+        } catch (StateValueTypeException e) {
+            fail(e.getMessage());
+        }
+        fail();
+        return null;
+    }
+
+}
index 8465394d60868a497f09a9d037cd0d3ffee0d19f..21f33495d4a4f6fd37f3fe551005053d555cff75 100644 (file)
@@ -37,7 +37,11 @@ public enum CtfTmfTestTrace {
     /** Trace synchronization: destination trace */
     SYNC_DEST,
     /** UST trace with lots of lost events */
-    HELLO_LOST;
+    HELLO_LOST,
+    /** UST trace with lttng-ust-cyg-profile events (aka -finstrument-functions) */
+    CYG_PROFILE,
+    /** UST trace with lttng-ust-cyg-profile-fast events (no address in func_exit) */
+    CYG_PROFILE_FAST;
 
 
     private final String fPath;
index a2a5d15d0c4c31ddc8951385a3c59b975f0cad77..731a39f30967a6770168f3814f5a6256675a74b7 100644 (file)
@@ -374,12 +374,18 @@ public final class TmfTraceManager {
     }
 
     /**
-     * Get a temporary directory based on a trace's name
+     * Get a temporary directory based on a trace's name. We will create the
+     * directory if it doesn't exist, so that it's ready to be used.
      */
     private static String getTemporaryDir(ITmfTrace trace) {
-        return System.getProperty("java.io.tmpdir") + //$NON-NLS-1$
+        String pathName = System.getProperty("java.io.tmpdir") + //$NON-NLS-1$
             File.separator +
             trace.getName() +
             File.separator;
+        File dir = new File(pathName);
+        if (!dir.exists()) {
+            dir.mkdirs();
+        }
+        return pathName;
     }
 }
This page took 0.037747 seconds and 5 git commands to generate.