lttng.ust: Do not block in UstDebugInfoAnalysisModule
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core.tests / src / org / eclipse / tracecompass / lttng2 / ust / core / tests / analysis / debuginfo / UstDebugInfoAnalysisModuleTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
3 *
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 *******************************************************************************/
9
10 package org.eclipse.tracecompass.lttng2.ust.core.tests.analysis.debuginfo;
11
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;
18
19 import java.util.ArrayList;
20 import java.util.Comparator;
21 import java.util.List;
22
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;
46
47 import com.google.common.collect.Iterables;
48 import com.google.common.collect.Lists;
49
50 /**
51 * Tests for the {@link UstDebugInfoAnalysisModule}
52 *
53 * @author Alexandre Montplaisir
54 */
55 public class UstDebugInfoAnalysisModuleTest {
56
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;
62
63 private LttngUstTrace fTrace;
64 private UstDebugInfoAnalysisModule fModule;
65
66 /**
67 * Test setup
68 */
69 @Before
70 public void setup() {
71 fModule = new UstDebugInfoAnalysisModule();
72 }
73
74 /**
75 * Test cleanup
76 */
77 @After
78 public void tearDown() {
79 if (fTrace != null) {
80 fTrace.dispose();
81 fTrace = null;
82 }
83
84 fModule.dispose();
85 fModule = null;
86 }
87
88 private @NonNull LttngUstTrace setupTrace(@NonNull CtfTestTrace testTrace) {
89 LttngUstTrace trace = new LttngUstTrace();
90 try {
91 trace.initTrace(null, CtfTmfTestTraceUtils.getTrace(testTrace).getPath(), CtfTmfEvent.class);
92 } catch (TmfTraceException e) {
93 fail(e.getMessage());
94 }
95 fTrace = trace;
96 return trace;
97 }
98
99 /**
100 * Test for {@link UstDebugInfoAnalysisModule#getAnalysisRequirements()}
101 */
102 @Test
103 public void testGetAnalysisRequirements() {
104 Iterable<TmfAbstractAnalysisRequirement> requirements = fModule.getAnalysisRequirements();
105 assertNotNull(requirements);
106 assertTrue(Iterables.isEmpty(requirements));
107 }
108
109 /**
110 * Test that the analysis can execute on a valid trace.
111 */
112 @Test
113 public void testCanExecute() {
114 LttngUstTrace trace = setupTrace(REAL_TEST_TRACE);
115 assertTrue(fModule.canExecute(trace));
116 }
117
118 /**
119 * Test that the analysis correctly refuses to execute on an invalid trace
120 * (LTTng-UST < 2.8 in this case).
121 */
122 @Test
123 public void testCannotExcecute() {
124 LttngUstTrace invalidTrace = setupTrace(INVALID_TRACE);
125 assertFalse(fModule.canExecute(invalidTrace));
126 }
127
128 private void executeModule() {
129 assertNotNull(fTrace);
130 try {
131 fModule.setTrace(fTrace);
132 } catch (TmfAnalysisException e) {
133 fail();
134 }
135 fModule.schedule();
136 fModule.waitForCompletion();
137 }
138
139 /**
140 * Test that basic execution of the module works well.
141 */
142 @Test
143 public void testExecution() {
144 setupTrace(REAL_TEST_TRACE);
145 executeModule();
146 ITmfStateSystem ss = fModule.getStateSystem();
147 assertNotNull(ss);
148 }
149
150 /**
151 * Test that the binary callsite aspect resolves correctly for some
152 * user-defined tracepoints in the trace.
153 *
154 * These should be available even without the binaries with debug symbols
155 * being present on the system.
156 */
157 @Test
158 public void testBinaryCallsites() {
159 LttngUstTrace trace = setupTrace(REAL_TEST_TRACE);
160
161 /*
162 * Fake a "trace opened" signal, so that the relevant analyses are
163 * started.
164 */
165 TmfTraceOpenedSignal signal = new TmfTraceOpenedSignal(this, trace, null);
166 TmfSignalManager.dispatchSignal(signal);
167
168 UstDebugInfoAnalysisModule module = TmfTraceUtils.getAnalysisModuleOfClass(trace, UstDebugInfoAnalysisModule.class, UstDebugInfoAnalysisModule.ID);
169 assertNotNull(module);
170 module.waitForCompletion();
171
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) {
175 @Override
176 public void handleData(ITmfEvent event) {
177 super.handleData(event);
178 events.add((LttngUstEvent) event);
179 }
180 };
181 trace.sendRequest(request);
182 try {
183 request.waitForCompletion();
184 } catch (InterruptedException e) {
185 fail(e.getMessage());
186 }
187
188 /* Tests that the aspects are resolved correctly */
189 final UstDebugInfoBinaryAspect aspect = UstDebugInfoBinaryAspect.INSTANCE;
190
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);
194 }
195
196 /**
197 * Test the analysis with a test trace doing an "exec" system call.
198 */
199 @Test
200 public void testExec() {
201 UstDebugInfoLoadedBinaryFile matchingFile, expected;
202
203 int vpid = 1337;
204
205 setupTrace(SYNTH_EXEC_TRACE);
206 executeModule();
207
208 expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo", null, null, false);
209 matchingFile = fModule.getMatchingFile(4000000, vpid, 0x400100);
210 assertEquals(expected, matchingFile);
211
212 expected = null;
213 matchingFile = fModule.getMatchingFile(8000000, vpid, 0x400100);
214 assertEquals(expected, matchingFile);
215
216 expected = new UstDebugInfoLoadedBinaryFile(0x500000, "/tmp/bar", null, null, false);
217 matchingFile = fModule.getMatchingFile(9000000, vpid, 0x500100);
218 assertEquals(expected, matchingFile);
219 }
220
221 /**
222 * Test the analysis with a test trace with two processes doing a statedump
223 * simultaneously.
224 */
225 @Test
226 public void testTwoProcesses() {
227 UstDebugInfoLoadedBinaryFile matchingFile, expected;
228 int vpid1 = 1337;
229 int vpid2 = 2001;
230
231 setupTrace(SYNTH_TWO_PROCESSES_TRACE);
232 executeModule();
233
234 expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "/tmp/debuglink1", false);
235 matchingFile = fModule.getMatchingFile(11000000, vpid1, 0x400100);
236 assertEquals(expected, matchingFile);
237
238 expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/bar", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "/tmp/debuglink2", false);
239 matchingFile = fModule.getMatchingFile(12000000, vpid2, 0x400100);
240 assertEquals(expected, matchingFile);
241 }
242
243
244 /**
245 * Test the analysis with a trace with debug_link information.
246 */
247 @Test
248 public void testBuildIDDebugLink() {
249 UstDebugInfoLoadedBinaryFile matchingFile, expected;
250
251 setupTrace(SYNTH_BUILDID_DEBUGLINK_TRACE);
252 executeModule();
253
254 expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_nn", null, null, false);
255 matchingFile = fModule.getMatchingFile(17000000, 1337, 0x400100);
256 assertEquals(expected, matchingFile);
257
258 expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_yn", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null, false);
259 matchingFile = fModule.getMatchingFile(18000000, 1338, 0x400100);
260 assertEquals(expected, matchingFile);
261
262 expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_ny", null, "/tmp/debug_link1", false);
263 matchingFile = fModule.getMatchingFile(19000000, 1339, 0x400100);
264 assertEquals(expected, matchingFile);
265
266 expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_yy", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "/tmp/debug_link2", false);
267 matchingFile = fModule.getMatchingFile(20000000, 1340, 0x400100);
268 assertEquals(expected, matchingFile);
269 }
270
271 /**
272 * Test the {@link UstDebugInfoAnalysisModule#getAllBinaries} method.
273 */
274 @Test
275 public void testGetAllBinaries() {
276 setupTrace(REAL_TEST_TRACE);
277 executeModule();
278
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));
308
309 Comparator<UstDebugInfoBinaryFile> comparator = Comparator.comparing(UstDebugInfoBinaryFile::getFilePath);
310 actualBinaries.sort(comparator);
311 expectedBinaries.sort(comparator);
312
313 /* Highlights failures more easily */
314 for (int i = 0; i < expectedBinaries.size(); i++) {
315 assertEquals(expectedBinaries.get(i), actualBinaries.get(i));
316 }
317
318 assertEquals(actualBinaries, expectedBinaries);
319 }
320
321 }
This page took 0.042561 seconds and 5 git commands to generate.