lttng: Unit tests for the UST callstack provider
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ust.core.tests / src / org / eclipse / linuxtools / lttng2 / ust / core / tests / trace / callstack / LttngUstCallStackProviderTest.java
CommitLineData
6e4358bd
AM
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
13package org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.assertTrue;
19import static org.junit.Assert.fail;
20import static org.junit.Assume.assumeTrue;
21
22import java.io.File;
23
24import org.eclipse.core.resources.IResource;
25import org.eclipse.core.runtime.IStatus;
26import org.eclipse.linuxtools.lttng2.ust.core.trace.LttngUstTrace;
27import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
28import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
29import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
30import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
31import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
32import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
33import org.junit.AfterClass;
34import org.junit.BeforeClass;
35import org.junit.Test;
36
37/**
38 * Test suite for the UST callstack state provider, using the trace of a program
39 * instrumented with lttng-ust-cyg-profile.so tracepoints.
40 *
41 * @author Alexandre Montplaisir
42 */
43public class LttngUstCallStackProviderTest {
44
45 // ------------------------------------------------------------------------
46 // Attributes
47 // ------------------------------------------------------------------------
48
49 private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.CYG_PROFILE;
50 private static final CtfTmfTestTrace otherUstTrace = CtfTmfTestTrace.HELLO_LOST;
51
52 private static final String PROCNAME = "glxgears-16073";
53
54 private static LttngUstTrace fixture = null;
55
56 // ------------------------------------------------------------------------
57 // Class methods
58 // ------------------------------------------------------------------------
59
60 /**
61 * Perform pre-class initialization.
62 *
63 * @throws TmfTraceException
64 * If the test trace is not found
65 */
66 @BeforeClass
67 public static void setUp() throws TmfTraceException {
68 assumeTrue(testTrace.exists());
69
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);
76 }
77
78 /**
79 * Perform post-class clean-up.
80 */
81 @AfterClass
82 public static void tearDown() {
83 if (fixture != null) {
84 fixture.dispose();
85 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(fixture));
86 TestUtils.deleteDirectory(suppDir);
87 }
88 }
89
90 // ------------------------------------------------------------------------
91 // Test methods
92 // ------------------------------------------------------------------------
93
94 /**
95 * Test the handling of generic UST traces who do not contain the required
96 * information.
97 */
98 @Test
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());
104 try {
105 ustTrace.initTrace((IResource) null, otherUstTrace.getPath(), CtfTmfEvent.class);
106 } catch (TmfTraceException e) {
107 fail(e.getMessage());
108 }
109 TestUtils.openTrace(ustTrace);
110
111 /* Make sure the generated state system exists, but is empty */
112 ITmfStateSystem ss = ustTrace.getStateSystems().get(TestUtils.SSID);
113 assertNotNull(ss);
114 assertTrue(ss.getStartTime() >= ustTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
115 assertEquals(0, ss.getNbAttributes());
116
117 /* Dispose the trace */
118 ustTrace.dispose();
119 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(ustTrace));
120 TestUtils.deleteDirectory(suppDir);
121 assertFalse(suppDir.exists());
122 }
123
124 /**
125 * Test that the callstack state system is there and contains data.
126 */
127 @Test
128 public void testConstruction() {
129 ITmfStateSystem ss = fixture.getStateSystems().get(TestUtils.SSID);
130 assertNotNull(ss);
131 assertTrue(ss.getNbAttributes() > 0);
132 }
133
134 /**
135 * Test the callstack at the beginning of the state system.
136 */
137 @Test
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);
142
143 assertEquals("0x40472b", cs[0]);
144 }
145
146 /**
147 * Test the callstack somewhere in the trace.
148 */
149 @Test
150 public void testCallStack1() {
151 String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1378850463600000000L);
152 assertEquals(2, cs.length);
153
154 assertEquals("0x40472b", cs[0]);
155 assertEquals("0x403d60", cs[1]);
156 }
157
158 /**
159 * Test the callstack somewhere in the trace.
160 */
161 @Test
162 public void testCallStack2() {
163 String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1378850463770000000L);
164 assertEquals(3, cs.length);
165
166 assertEquals("0x40472b", cs[0]);
167 assertEquals("0x403b14", cs[1]);
168 assertEquals("0x401b23", cs[2]);
169 }
170
171 /**
172 * Test the callstack somewhere in the trace.
173 */
174 @Test
175 public void testCallStack3() {
176 String[] cs = TestUtils.getCallStack(fixture, PROCNAME, 1378850463868753000L);
177 assertEquals(4, cs.length);
178
179 assertEquals("0x40472b", cs[0]);
180 assertEquals("0x4045c8", cs[1]);
181 assertEquals("0x403760", cs[2]);
182 assertEquals("0x401aac", cs[3]);
183 }
184
185 /**
186 * Test the callstack at the end of the trace/state system.
187 */
188 @Test
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);
193
194 assertEquals("0x40472b", cs[0]);
195 assertEquals("0x4045c8", cs[1]);
196 assertEquals("0x403760", cs[2]);
197 }
198}
This page took 0.032425 seconds and 5 git commands to generate.