Merge branch 'master' into luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ust.core.tests / src / org / eclipse / linuxtools / lttng2 / ust / core / tests / trace / callstack / LttngUstCallStackProviderFastTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertTrue;
18 import static org.junit.Assume.assumeTrue;
19
20 import java.io.File;
21
22 import org.eclipse.core.resources.IResource;
23 import org.eclipse.core.runtime.IStatus;
24 import org.eclipse.linuxtools.lttng2.ust.core.trace.LttngUstTrace;
25 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
26 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
27 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
28 import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
29 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33
34 /**
35 * Test suite for the UST callstack state provider, using the trace of a program
36 * instrumented with lttng-ust-cyg-profile-fast.so tracepoints. These do not
37 * contain the function addresses in the func_exit events.
38 *
39 * @author Alexandre Montplaisir
40 */
41 public class LttngUstCallStackProviderFastTest {
42
43 // ------------------------------------------------------------------------
44 // Attributes
45 // ------------------------------------------------------------------------
46
47 private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.CYG_PROFILE_FAST;
48
49 private static final String PROCNAME = "glxgears-29822";
50
51 private static LttngUstTrace fixture = null;
52
53 // ------------------------------------------------------------------------
54 // Class methods
55 // ------------------------------------------------------------------------
56
57 /**
58 * Perform pre-class initialization.
59 *
60 * @throws TmfTraceException
61 * If the test trace is not found
62 */
63 @BeforeClass
64 public static void setUp() throws TmfTraceException {
65 assumeTrue(testTrace.exists());
66
67 /* We init the trace ourselves (we need the specific LttngUstTrace type) */
68 fixture = new LttngUstTrace();
69 IStatus valid = fixture.validate(null, testTrace.getPath());
70 assertTrue(valid.isOK());
71 fixture.initTrace((IResource) null, testTrace.getPath(), CtfTmfEvent.class);
72 TestUtils.openTrace(fixture);
73 }
74
75 /**
76 * Perform post-class clean-up.
77 */
78 @AfterClass
79 public static void tearDown() {
80 if (fixture != null) {
81 fixture.dispose();
82 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(fixture));
83 TestUtils.deleteDirectory(suppDir);
84 }
85 }
86
87 // ------------------------------------------------------------------------
88 // Test methods
89 // ------------------------------------------------------------------------
90
91 /**
92 * Test that the callstack state system is there and contains data.
93 */
94 @Test
95 public void testConstruction() {
96 ITmfStateSystem ss = fixture.getStateSystems().get(TestUtils.SSID);
97 assertNotNull(ss);
98 assertTrue(ss.getNbAttributes() > 0);
99 }
100
101 /**
102 * Test the callstack at the beginning of the state system.
103 */
104 @Test
105 public void testCallStackBegin() {
106 long start = fixture.getStateSystems().get(TestUtils.SSID).getStartTime();
107 String[] cs = TestUtils.getCallStack(fixture, PROCNAME, start);
108 assertEquals(1, cs.length);
109
110 assertEquals("40472b", cs[0]);
111 }
112
113 /**
114 * Test the callstack somewhere in the trace.
115 */
116 @Test
117 public void testCallStack1() {
118 String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1379361250310000000L);
119 assertEquals(2, cs.length);
120
121 assertEquals("40472b", cs[0]);
122 assertEquals("403d60", cs[1]);
123 }
124
125 /**
126 * Test the callstack somewhere in the trace.
127 */
128 @Test
129 public void testCallStack2() {
130 String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1379361250498400000L);
131 assertEquals(3, cs.length);
132
133 assertEquals("40472b", cs[0]);
134 assertEquals("403b14", cs[1]);
135 assertEquals("401b23", cs[2]);
136 }
137
138 /**
139 * Test the callstack somewhere in the trace.
140 */
141 @Test
142 public void testCallStack3() {
143 String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1379361250499759000L);
144 assertEquals(4, cs.length);
145
146 assertEquals("40472b", cs[0]);
147 assertEquals("4045c8", cs[1]);
148 assertEquals("403760", cs[2]);
149 assertEquals("401aac", cs[3]);
150 }
151
152 /**
153 * Test the callstack at the end of the trace/state system.
154 */
155 @Test
156 public void testCallStackEnd() {
157 long end = fixture.getStateSystems().get(TestUtils.SSID).getCurrentEndTime();
158 String[] cs = TestUtils.getCallStack(fixture, PROCNAME, end);
159 assertEquals(3, cs.length);
160
161 assertEquals("40472b", cs[0]);
162 assertEquals("4045c8", cs[1]);
163 assertEquals("403760", cs[2]);
164 }
165 }
This page took 0.037071 seconds and 6 git commands to generate.