1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng2
.ust
.core
.tests
.trace
.callstack
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertFalse
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.assertTrue
;
19 import static org
.junit
.Assert
.fail
;
20 import static org
.junit
.Assume
.assumeTrue
;
24 import org
.eclipse
.core
.resources
.IResource
;
25 import org
.eclipse
.core
.runtime
.IStatus
;
26 import org
.eclipse
.linuxtools
.lttng2
.ust
.core
.trace
.LttngUstTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
33 import org
.junit
.AfterClass
;
34 import org
.junit
.BeforeClass
;
35 import org
.junit
.Test
;
38 * Test suite for the UST callstack state provider, using the trace of a program
39 * instrumented with lttng-ust-cyg-profile.so tracepoints.
41 * @author Alexandre Montplaisir
43 public class LttngUstCallStackProviderTest
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 private static final CtfTmfTestTrace testTrace
= CtfTmfTestTrace
.CYG_PROFILE
;
50 private static final CtfTmfTestTrace otherUstTrace
= CtfTmfTestTrace
.HELLO_LOST
;
52 private static final String PROCNAME
= "glxgears-16073";
54 private static LttngUstTrace fixture
= null;
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * Perform pre-class initialization.
63 * @throws TmfTraceException
64 * If the test trace is not found
67 public static void setUp() throws TmfTraceException
{
68 assumeTrue(testTrace
.exists());
70 /* We init the trace ourselves (we need the specific LttngUstTrace type) */
71 fixture
= new LttngUstTrace();
72 IStatus valid
= fixture
.validate(null, testTrace
.getPath());
73 assertTrue(valid
.isOK());
74 fixture
.initTrace((IResource
) null, testTrace
.getPath(), CtfTmfEvent
.class);
75 TestUtils
.openTrace(fixture
);
79 * Perform post-class clean-up.
82 public static void tearDown() {
83 if (fixture
!= null) {
85 File suppDir
= new File(TmfTraceManager
.getSupplementaryFileDir(fixture
));
86 TestUtils
.deleteDirectory(suppDir
);
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
95 * Test the handling of generic UST traces who do not contain the required
99 public void testOtherUstTrace() {
100 /* Initialize the trace */
101 final LttngUstTrace ustTrace
= new LttngUstTrace();
102 IStatus valid
= ustTrace
.validate(null, otherUstTrace
.getPath());
103 assertTrue(valid
.isOK());
105 ustTrace
.initTrace((IResource
) null, otherUstTrace
.getPath(), CtfTmfEvent
.class);
106 } catch (TmfTraceException e
) {
107 fail(e
.getMessage());
109 TestUtils
.openTrace(ustTrace
);
111 /* Make sure the generated state system exists, but is empty */
112 ITmfStateSystem ss
= ustTrace
.getStateSystems().get(TestUtils
.SSID
);
114 assertTrue(ss
.getStartTime() >= ustTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue());
115 assertEquals(0, ss
.getNbAttributes());
117 /* Dispose the trace */
119 File suppDir
= new File(TmfTraceManager
.getSupplementaryFileDir(ustTrace
));
120 TestUtils
.deleteDirectory(suppDir
);
121 assertFalse(suppDir
.exists());
125 * Test that the callstack state system is there and contains data.
128 public void testConstruction() {
129 ITmfStateSystem ss
= fixture
.getStateSystems().get(TestUtils
.SSID
);
131 assertTrue(ss
.getNbAttributes() > 0);
135 * Test the callstack at the beginning of the state system.
138 public void testCallStackBegin() {
139 long start
= fixture
.getStateSystems().get(TestUtils
.SSID
).getStartTime();
140 String
[] cs
= TestUtils
.getCallStack(fixture
, PROCNAME
, start
);
141 assertEquals(1, cs
.length
);
143 assertEquals("40472b", cs
[0]);
147 * Test the callstack somewhere in the trace.
150 public void testCallStack1() {
151 String
[] cs
= TestUtils
.getCallStack(fixture
, PROCNAME
, 1378850463600000000L);
152 assertEquals(2, cs
.length
);
154 assertEquals("40472b", cs
[0]);
155 assertEquals("403d60", cs
[1]);
159 * Test the callstack somewhere in the trace.
162 public void testCallStack2() {
163 String
[] cs
= TestUtils
.getCallStack(fixture
, PROCNAME
, 1378850463770000000L);
164 assertEquals(3, cs
.length
);
166 assertEquals("40472b", cs
[0]);
167 assertEquals("403b14", cs
[1]);
168 assertEquals("401b23", cs
[2]);
172 * Test the callstack somewhere in the trace.
175 public void testCallStack3() {
176 String
[] cs
= TestUtils
.getCallStack(fixture
, PROCNAME
, 1378850463868753000L);
177 assertEquals(4, cs
.length
);
179 assertEquals("40472b", cs
[0]);
180 assertEquals("4045c8", cs
[1]);
181 assertEquals("403760", cs
[2]);
182 assertEquals("401aac", cs
[3]);
186 * Test the callstack at the end of the trace/state system.
189 public void testCallStackEnd() {
190 long end
= fixture
.getStateSystems().get(TestUtils
.SSID
).getCurrentEndTime();
191 String
[] cs
= TestUtils
.getCallStack(fixture
, PROCNAME
, end
);
192 assertEquals(3, cs
.length
);
194 assertEquals("40472b", cs
[0]);
195 assertEquals("4045c8", cs
[1]);
196 assertEquals("403760", cs
[2]);