1 /*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.lttng2
.ust
.core
.tests
.analysis
.debuginfo
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
13 import static org
.junit
.Assert
.assertEquals
;
14 import static org
.junit
.Assert
.assertFalse
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.assertTrue
;
17 import static org
.junit
.Assert
.fail
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Comparator
;
21 import java
.util
.List
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.analysis
.debuginfo
.UstDebugInfoAnalysisModule
;
25 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.analysis
.debuginfo
.UstDebugInfoBinaryAspect
;
26 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.analysis
.debuginfo
.UstDebugInfoBinaryFile
;
27 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.analysis
.debuginfo
.UstDebugInfoLoadedBinaryFile
;
28 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.LttngUstEvent
;
29 import org
.eclipse
.tracecompass
.lttng2
.ust
.core
.trace
.LttngUstTrace
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
31 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.requirements
.TmfAbstractAnalysisRequirement
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
41 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
42 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
43 import org
.junit
.After
;
44 import org
.junit
.Before
;
45 import org
.junit
.Test
;
47 import com
.google
.common
.collect
.Iterables
;
48 import com
.google
.common
.collect
.Lists
;
51 * Tests for the {@link UstDebugInfoAnalysisModule}
53 * @author Alexandre Montplaisir
55 public class UstDebugInfoAnalysisModuleTest
{
57 private static final @NonNull CtfTestTrace REAL_TEST_TRACE
= CtfTestTrace
.DEBUG_INFO4
;
58 private static final @NonNull CtfTestTrace SYNTH_EXEC_TRACE
= CtfTestTrace
.DEBUG_INFO_SYNTH_EXEC
;
59 private static final @NonNull CtfTestTrace SYNTH_TWO_PROCESSES_TRACE
= CtfTestTrace
.DEBUG_INFO_SYNTH_TWO_PROCESSES
;
60 private static final @NonNull CtfTestTrace SYNTH_BUILDID_DEBUGLINK_TRACE
= CtfTestTrace
.DEBUG_INFO_SYNTH_BUILDID_DEBUGLINK
;
61 private static final @NonNull CtfTestTrace INVALID_TRACE
= CtfTestTrace
.CYG_PROFILE
;
63 private LttngUstTrace fTrace
;
64 private UstDebugInfoAnalysisModule fModule
;
71 fModule
= new UstDebugInfoAnalysisModule();
78 public void tearDown() {
88 private @NonNull LttngUstTrace
setupTrace(@NonNull CtfTestTrace testTrace
) {
89 LttngUstTrace trace
= new LttngUstTrace();
91 trace
.initTrace(null, CtfTmfTestTraceUtils
.getTrace(testTrace
).getPath(), CtfTmfEvent
.class);
92 } catch (TmfTraceException e
) {
100 * Test for {@link UstDebugInfoAnalysisModule#getAnalysisRequirements()}
103 public void testGetAnalysisRequirements() {
104 Iterable
<TmfAbstractAnalysisRequirement
> requirements
= fModule
.getAnalysisRequirements();
105 assertNotNull(requirements
);
106 assertTrue(Iterables
.isEmpty(requirements
));
110 * Test that the analysis can execute on a valid trace.
113 public void testCanExecute() {
114 LttngUstTrace trace
= setupTrace(REAL_TEST_TRACE
);
115 assertTrue(fModule
.canExecute(trace
));
119 * Test that the analysis correctly refuses to execute on an invalid trace
120 * (LTTng-UST < 2.8 in this case).
123 public void testCannotExcecute() {
124 LttngUstTrace invalidTrace
= setupTrace(INVALID_TRACE
);
125 assertFalse(fModule
.canExecute(invalidTrace
));
128 private void executeModule() {
129 assertNotNull(fTrace
);
131 fModule
.setTrace(fTrace
);
132 } catch (TmfAnalysisException e
) {
136 fModule
.waitForCompletion();
140 * Test that basic execution of the module works well.
143 public void testExecution() {
144 setupTrace(REAL_TEST_TRACE
);
146 ITmfStateSystem ss
= fModule
.getStateSystem();
151 * Test that the binary callsite aspect resolves correctly for some
152 * user-defined tracepoints in the trace.
154 * These should be available even without the binaries with debug symbols
155 * being present on the system.
158 public void testBinaryCallsites() {
159 LttngUstTrace trace
= setupTrace(REAL_TEST_TRACE
);
162 * Fake a "trace opened" signal, so that the relevant analyses are
165 TmfTraceOpenedSignal signal
= new TmfTraceOpenedSignal(this, trace
, null);
166 TmfSignalManager
.dispatchSignal(signal
);
168 UstDebugInfoAnalysisModule module
= TmfTraceUtils
.getAnalysisModuleOfClass(trace
, UstDebugInfoAnalysisModule
.class, UstDebugInfoAnalysisModule
.ID
);
169 assertNotNull(module
);
170 module
.waitForCompletion();
172 /* Send a request to get the 3 events we are interested in */
173 List
<@NonNull LttngUstEvent
> events
= new ArrayList
<>();
174 TmfEventRequest request
= new TmfEventRequest(LttngUstEvent
.class, 31, 1, ExecutionType
.FOREGROUND
) {
176 public void handleData(ITmfEvent event
) {
177 super.handleData(event
);
178 events
.add((LttngUstEvent
) event
);
181 trace
.sendRequest(request
);
183 request
.waitForCompletion();
184 } catch (InterruptedException e
) {
185 fail(e
.getMessage());
188 /* Tests that the aspects are resolved correctly */
189 final UstDebugInfoBinaryAspect aspect
= UstDebugInfoBinaryAspect
.INSTANCE
;
191 String actual
= checkNotNull(aspect
.resolve(events
.get(0))).toString();
192 String expected
= "/home/simark/src/babeltrace/tests/debug-info-data/libhello_so+0x14d4";
193 assertEquals(expected
, actual
);
197 * Test the analysis with a test trace doing an "exec" system call.
200 public void testExec() {
201 UstDebugInfoLoadedBinaryFile matchingFile
, expected
;
205 setupTrace(SYNTH_EXEC_TRACE
);
208 expected
= new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo", null, null, false);
209 matchingFile
= fModule
.getMatchingFile(4000000, vpid
, 0x400100);
210 assertEquals(expected
, matchingFile
);
213 matchingFile
= fModule
.getMatchingFile(8000000, vpid
, 0x400100);
214 assertEquals(expected
, matchingFile
);
216 expected
= new UstDebugInfoLoadedBinaryFile(0x500000, "/tmp/bar", null, null, false);
217 matchingFile
= fModule
.getMatchingFile(9000000, vpid
, 0x500100);
218 assertEquals(expected
, matchingFile
);
222 * Test the analysis with a test trace with two processes doing a statedump
226 public void testTwoProcesses() {
227 UstDebugInfoLoadedBinaryFile matchingFile
, expected
;
231 setupTrace(SYNTH_TWO_PROCESSES_TRACE
);
234 expected
= new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "/tmp/debuglink1", false);
235 matchingFile
= fModule
.getMatchingFile(11000000, vpid1
, 0x400100);
236 assertEquals(expected
, matchingFile
);
238 expected
= new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/bar", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "/tmp/debuglink2", false);
239 matchingFile
= fModule
.getMatchingFile(12000000, vpid2
, 0x400100);
240 assertEquals(expected
, matchingFile
);
245 * Test the analysis with a trace with debug_link information.
248 public void testBuildIDDebugLink() {
249 UstDebugInfoLoadedBinaryFile matchingFile
, expected
;
251 setupTrace(SYNTH_BUILDID_DEBUGLINK_TRACE
);
254 expected
= new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_nn", null, null, false);
255 matchingFile
= fModule
.getMatchingFile(17000000, 1337, 0x400100);
256 assertEquals(expected
, matchingFile
);
258 expected
= new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_yn", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null, false);
259 matchingFile
= fModule
.getMatchingFile(18000000, 1338, 0x400100);
260 assertEquals(expected
, matchingFile
);
262 expected
= new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_ny", null, "/tmp/debug_link1", false);
263 matchingFile
= fModule
.getMatchingFile(19000000, 1339, 0x400100);
264 assertEquals(expected
, matchingFile
);
266 expected
= new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_yy", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "/tmp/debug_link2", false);
267 matchingFile
= fModule
.getMatchingFile(20000000, 1340, 0x400100);
268 assertEquals(expected
, matchingFile
);
272 * Test the {@link UstDebugInfoAnalysisModule#getAllBinaries} method.
275 public void testGetAllBinaries() {
276 setupTrace(REAL_TEST_TRACE
);
279 List
<UstDebugInfoBinaryFile
> actualBinaries
= Lists
.newArrayList(fModule
.getAllBinaries());
280 List
<UstDebugInfoBinaryFile
> expectedBinaries
= Lists
.newArrayList(
281 new UstDebugInfoBinaryFile("/home/simark/src/babeltrace/tests/debug-info-data/libhello_so",
282 "cdd98cdd87f7fe64c13b6daad553987eafd40cbb", null, true),
283 new UstDebugInfoBinaryFile("/home/simark/src/babeltrace/tests/debug-info-data/test",
284 "0683255d2cf219c33cc0efd6039db09ccc4416d7", null, false),
285 new UstDebugInfoBinaryFile("[linux-vdso.so.1]", null, null, false),
286 new UstDebugInfoBinaryFile("/usr/local/lib/liblttng-ust-dl.so.0.0.0",
287 "39c035014cc02008d6884fcb1be4e020cc820366", null, true),
288 new UstDebugInfoBinaryFile("/usr/lib/libdl-2.23.so",
289 "db3f9be9f4ebe9e2a21e4ae0b4ef7165d40fdfef", null, true),
290 new UstDebugInfoBinaryFile("/usr/lib/libc-2.23.so",
291 "946025a5cad7b5f2dfbaebc6ebd1fcc004349b48", null, true),
292 new UstDebugInfoBinaryFile("/usr/local/lib/liblttng-ust.so.0.0.0",
293 "405b0b15daa73eccb88076247ba30356c00d3b92", null, true),
294 new UstDebugInfoBinaryFile("/usr/local/lib/liblttng-ust-tracepoint.so.0.0.0",
295 "62c028aad38adb5e0910c527d522e8c86a0a3344", null, true),
296 new UstDebugInfoBinaryFile("/usr/lib/librt-2.23.so",
297 "aba676bda7fb6adb71e100159915504e1a0c17e6", null, true),
298 new UstDebugInfoBinaryFile("/usr/lib/liburcu-bp.so.4.0.0",
299 "b9dfadea234107f8453bc636fc160047e0c01b7a", null, true),
300 new UstDebugInfoBinaryFile("/usr/lib/liburcu-cds.so.4.0.0",
301 "420527f6dacc762378d9fa7def54d91c80a6c87e", null, true),
302 new UstDebugInfoBinaryFile("/usr/lib/libpthread-2.23.so",
303 "d91ed99c8425b7ce5da5bb750662a91038e02a78", null, true),
304 new UstDebugInfoBinaryFile("/usr/lib/ld-2.23.so",
305 "524eff0527e923e4adc4be9db1ef7475607b92e8", null, true),
306 new UstDebugInfoBinaryFile("/usr/lib/liburcu-common.so.4.0.0",
307 "f279a6d46a2b846e15e7abd99cfe9fbe8d7f8295", null, true));
309 Comparator
<UstDebugInfoBinaryFile
> comparator
= Comparator
.comparing(UstDebugInfoBinaryFile
::getFilePath
);
310 actualBinaries
.sort(comparator
);
311 expectedBinaries
.sort(comparator
);
313 /* Highlights failures more easily */
314 for (int i
= 0; i
< expectedBinaries
.size(); i
++) {
315 assertEquals(expectedBinaries
.get(i
), actualBinaries
.get(i
));
318 assertEquals(actualBinaries
, expectedBinaries
);