From 6e4358bd56f8d7fdc396acae1cf34d60dbf3f75c Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 12 Sep 2013 15:59:29 -0400 Subject: [PATCH] lttng: Unit tests for the UST callstack provider 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 Reviewed-on: https://git.eclipse.org/r/16399 Tested-by: Hudson CI Reviewed-by: Genevieve Bastien IP-Clean: Genevieve Bastien --- org.eclipse.linuxtools.ctf.core.tests/pom.xml | 2 + .../ctf/core/tests/shared/CtfTestTrace.java | 13 +- .../traces/.gitignore | 1 + .../traces/get-traces.sh | 5 +- .../traces/get-traces.xml | 6 +- .../.settings/org.eclipse.jdt.core.prefs | 2 +- .../META-INF/MANIFEST.MF | 10 +- .../lttng2/ust/core/tests/AllTests.java | 3 +- .../core/tests/trace/callstack/AllTests.java | 28 +++ .../LttngUstCallStackProviderFastTest.java | 165 +++++++++++++++ .../LttngUstCallStackProviderTest.java | 198 ++++++++++++++++++ .../core/tests/trace/callstack/TestUtils.java | 93 ++++++++ .../core/tests/shared/CtfTmfTestTrace.java | 6 +- .../tmf/core/trace/TmfTraceManager.java | 10 +- 14 files changed, 532 insertions(+), 10 deletions(-) create mode 100644 org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/AllTests.java create mode 100644 org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderFastTest.java create mode 100644 org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderTest.java create mode 100644 org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/TestUtils.java diff --git a/org.eclipse.linuxtools.ctf.core.tests/pom.xml b/org.eclipse.linuxtools.ctf.core.tests/pom.xml index 449cb4ac8c..831d5a7a9a 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/pom.xml +++ b/org.eclipse.linuxtools.ctf.core.tests/pom.xml @@ -88,9 +88,11 @@ traces/ctf-testsuite + traces/cyg-profile traces/hello-lost traces/kernel traces/kernel_vm + traces/synctraces traces/trace2 diff --git a/org.eclipse.linuxtools.ctf.core.tests/shared/org/eclipse/linuxtools/ctf/core/tests/shared/CtfTestTrace.java b/org.eclipse.linuxtools.ctf.core.tests/shared/org/eclipse/linuxtools/ctf/core/tests/shared/CtfTestTrace.java index 28c511c263..f125bb6808 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/shared/org/eclipse/linuxtools/ctf/core/tests/shared/CtfTestTrace.java +++ b/org.eclipse.linuxtools.ctf.core.tests/shared/org/eclipse/linuxtools/ctf/core/tests/shared/CtfTestTrace.java @@ -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; diff --git a/org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore b/org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore index 3678d68c2f..3f6d15926f 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore +++ b/org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore @@ -3,6 +3,7 @@ *.tar *.ht /ctf-testsuite +/cyg-profile /hello-lost /kernel /kernel_vm diff --git a/org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.sh b/org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.sh index 66c4f1dd64..ed3264f2cb 100755 --- a/org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.sh +++ b/org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.sh @@ -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 - + diff --git a/org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.xml b/org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.xml index 588be110cd..f7e52bd023 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.xml +++ b/org.eclipse.linuxtools.ctf.core.tests/traces/get-traces.xml @@ -16,6 +16,7 @@ + @@ -33,6 +34,7 @@ + @@ -50,12 +52,14 @@ - + + + diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.lttng2.ust.core.tests/.settings/org.eclipse.jdt.core.prefs index 749fd0eb9a..7acb262bd4 100644 --- a/org.eclipse.linuxtools.lttng2.ust.core.tests/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.ust.core.tests/META-INF/MANIFEST.MF index b32f5181a1..541da9ab59 100644 --- a/org.eclipse.linuxtools.lttng2.ust.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/META-INF/MANIFEST.MF @@ -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 diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/AllTests.java b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/AllTests.java index 81492a7042..cd1cb1cae7 100644 --- a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/AllTests.java +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/AllTests.java @@ -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 index 0000000000..d34690034f --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/AllTests.java @@ -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 index 0000000000..89715eeaa3 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderFastTest.java @@ -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 index 0000000000..d04fc824bf --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/LttngUstCallStackProviderTest.java @@ -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 index 0000000000..3b5b23cf68 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/trace/callstack/TestUtils.java @@ -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 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; + } + +} diff --git a/org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTrace.java b/org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTrace.java index 8465394d60..21f33495d4 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTrace.java +++ b/org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTrace.java @@ -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; diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java index a2a5d15d0c..731a39f309 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java @@ -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; } } -- 2.34.1