Commit | Line | Data |
---|---|---|
eb65ae32 AM |
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 | ||
0b49411f AM |
12 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
13 | import static org.junit.Assert.assertEquals; | |
eb65ae32 AM |
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 | ||
0b49411f | 19 | import java.util.ArrayList; |
d89151ba | 20 | import java.util.Comparator; |
0b49411f | 21 | import java.util.List; |
eb65ae32 AM |
22 | |
23 | import org.eclipse.jdt.annotation.NonNull; | |
eb65ae32 | 24 | import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoAnalysisModule; |
0b49411f | 25 | import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoBinaryAspect; |
1633ee0d SM |
26 | import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoBinaryFile; |
27 | import org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo.UstDebugInfoLoadedBinaryFile; | |
0b49411f | 28 | import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstEvent; |
eb65ae32 AM |
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; | |
58080002 | 32 | import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement; |
0b49411f | 33 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
eb65ae32 AM |
34 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException; |
35 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; | |
0b49411f AM |
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; | |
eb65ae32 AM |
40 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; |
41 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils; | |
42 | import org.junit.After; | |
43 | import org.junit.Before; | |
44 | import org.junit.Test; | |
45 | ||
eb65ae32 | 46 | import com.google.common.collect.Iterables; |
d89151ba | 47 | import com.google.common.collect.Lists; |
eb65ae32 AM |
48 | |
49 | /** | |
50 | * Tests for the {@link UstDebugInfoAnalysisModule} | |
51 | * | |
52 | * @author Alexandre Montplaisir | |
53 | */ | |
54 | public class UstDebugInfoAnalysisModuleTest { | |
55 | ||
1633ee0d SM |
56 | private static final @NonNull CtfTestTrace REAL_TEST_TRACE = CtfTestTrace.DEBUG_INFO4; |
57 | private static final @NonNull CtfTestTrace SYNTH_EXEC_TRACE = CtfTestTrace.DEBUG_INFO_SYNTH_EXEC; | |
58 | private static final @NonNull CtfTestTrace SYNTH_TWO_PROCESSES_TRACE = CtfTestTrace.DEBUG_INFO_SYNTH_TWO_PROCESSES; | |
59 | private static final @NonNull CtfTestTrace SYNTH_BUILDID_DEBUGLINK_TRACE = CtfTestTrace.DEBUG_INFO_SYNTH_BUILDID_DEBUGLINK; | |
eb65ae32 AM |
60 | private static final @NonNull CtfTestTrace INVALID_TRACE = CtfTestTrace.CYG_PROFILE; |
61 | ||
62 | private LttngUstTrace fTrace; | |
63 | private UstDebugInfoAnalysisModule fModule; | |
64 | ||
65 | /** | |
66 | * Test setup | |
67 | */ | |
68 | @Before | |
69 | public void setup() { | |
70 | fModule = new UstDebugInfoAnalysisModule(); | |
eb65ae32 AM |
71 | } |
72 | ||
73 | /** | |
74 | * Test cleanup | |
75 | */ | |
76 | @After | |
77 | public void tearDown() { | |
1633ee0d SM |
78 | if (fTrace != null) { |
79 | fTrace.dispose(); | |
80 | fTrace = null; | |
81 | } | |
82 | ||
eb65ae32 | 83 | fModule.dispose(); |
eb65ae32 AM |
84 | fModule = null; |
85 | } | |
86 | ||
1633ee0d SM |
87 | private @NonNull LttngUstTrace setupTrace(@NonNull CtfTestTrace testTrace) { |
88 | LttngUstTrace trace = new LttngUstTrace(); | |
89 | try { | |
90 | trace.initTrace(null, CtfTmfTestTraceUtils.getTrace(testTrace).getPath(), CtfTmfEvent.class); | |
91 | } catch (TmfTraceException e) { | |
92 | fail(e.getMessage()); | |
93 | } | |
94 | fTrace = trace; | |
95 | return trace; | |
96 | } | |
97 | ||
eb65ae32 AM |
98 | /** |
99 | * Test for {@link UstDebugInfoAnalysisModule#getAnalysisRequirements()} | |
100 | */ | |
101 | @Test | |
102 | public void testGetAnalysisRequirements() { | |
58080002 | 103 | Iterable<TmfAbstractAnalysisRequirement> requirements = fModule.getAnalysisRequirements(); |
eb65ae32 AM |
104 | assertNotNull(requirements); |
105 | assertTrue(Iterables.isEmpty(requirements)); | |
106 | } | |
107 | ||
108 | /** | |
109 | * Test that the analysis can execute on a valid trace. | |
110 | */ | |
111 | @Test | |
112 | public void testCanExecute() { | |
1633ee0d SM |
113 | LttngUstTrace trace = setupTrace(REAL_TEST_TRACE); |
114 | assertTrue(fModule.canExecute(trace)); | |
eb65ae32 AM |
115 | } |
116 | ||
117 | /** | |
118 | * Test that the analysis correctly refuses to execute on an invalid trace | |
119 | * (LTTng-UST < 2.8 in this case). | |
eb65ae32 AM |
120 | */ |
121 | @Test | |
1633ee0d SM |
122 | public void testCannotExcecute() { |
123 | LttngUstTrace invalidTrace = setupTrace(INVALID_TRACE); | |
eb65ae32 | 124 | assertFalse(fModule.canExecute(invalidTrace)); |
eb65ae32 AM |
125 | } |
126 | ||
127 | private void executeModule() { | |
128 | assertNotNull(fTrace); | |
129 | try { | |
130 | fModule.setTrace(fTrace); | |
131 | } catch (TmfAnalysisException e) { | |
132 | fail(); | |
133 | } | |
134 | fModule.schedule(); | |
135 | fModule.waitForCompletion(); | |
136 | } | |
137 | ||
138 | /** | |
139 | * Test that basic execution of the module works well. | |
140 | */ | |
141 | @Test | |
142 | public void testExecution() { | |
1633ee0d | 143 | setupTrace(REAL_TEST_TRACE); |
eb65ae32 AM |
144 | executeModule(); |
145 | ITmfStateSystem ss = fModule.getStateSystem(); | |
146 | assertNotNull(ss); | |
147 | } | |
148 | ||
0b49411f AM |
149 | /** |
150 | * Test that the binary callsite aspect resolves correctly for some | |
151 | * user-defined tracepoints in the trace. | |
152 | * | |
153 | * These should be available even without the binaries with debug symbols | |
154 | * being present on the system. | |
155 | */ | |
156 | @Test | |
157 | public void testBinaryCallsites() { | |
1633ee0d SM |
158 | LttngUstTrace trace = setupTrace(REAL_TEST_TRACE); |
159 | ||
0b49411f AM |
160 | /* |
161 | * Fake a "trace opened" signal, so that the relevant analyses are | |
162 | * started. | |
163 | */ | |
1633ee0d | 164 | TmfTraceOpenedSignal signal = new TmfTraceOpenedSignal(this, trace, null); |
0b49411f AM |
165 | TmfSignalManager.dispatchSignal(signal); |
166 | ||
167 | /* Send a request to get the 3 events we are interested in */ | |
168 | List<@NonNull LttngUstEvent> events = new ArrayList<>(); | |
1633ee0d | 169 | TmfEventRequest request = new TmfEventRequest(LttngUstEvent.class, 31, 1, ExecutionType.FOREGROUND) { |
0b49411f AM |
170 | @Override |
171 | public void handleData(ITmfEvent event) { | |
172 | super.handleData(event); | |
173 | events.add((LttngUstEvent) event); | |
174 | } | |
175 | }; | |
1633ee0d | 176 | trace.sendRequest(request); |
0b49411f AM |
177 | try { |
178 | request.waitForCompletion(); | |
179 | } catch (InterruptedException e) { | |
180 | fail(e.getMessage()); | |
181 | } | |
182 | ||
183 | /* Tests that the aspects are resolved correctly */ | |
184 | final UstDebugInfoBinaryAspect aspect = UstDebugInfoBinaryAspect.INSTANCE; | |
185 | ||
186 | String actual = checkNotNull(aspect.resolve(events.get(0))).toString(); | |
1633ee0d | 187 | String expected = "/home/simark/src/babeltrace/tests/debug-info-data/libhello_so+0x14d4"; |
0b49411f | 188 | assertEquals(expected, actual); |
1633ee0d | 189 | } |
0b49411f | 190 | |
1633ee0d SM |
191 | /** |
192 | * Test the analysis with a test trace doing an "exec" system call. | |
193 | */ | |
194 | @Test | |
195 | public void testExec() { | |
196 | UstDebugInfoLoadedBinaryFile matchingFile, expected; | |
0b49411f | 197 | |
1633ee0d SM |
198 | int vpid = 1337; |
199 | ||
200 | setupTrace(SYNTH_EXEC_TRACE); | |
201 | executeModule(); | |
202 | ||
203 | expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo", null, null, false); | |
204 | matchingFile = fModule.getMatchingFile(4000000, vpid, 0x400100); | |
205 | assertEquals(expected, matchingFile); | |
206 | ||
207 | expected = null; | |
208 | matchingFile = fModule.getMatchingFile(8000000, vpid, 0x400100); | |
209 | assertEquals(expected, matchingFile); | |
210 | ||
211 | expected = new UstDebugInfoLoadedBinaryFile(0x500000, "/tmp/bar", null, null, false); | |
212 | matchingFile = fModule.getMatchingFile(9000000, vpid, 0x500100); | |
213 | assertEquals(expected, matchingFile); | |
214 | } | |
215 | ||
216 | /** | |
217 | * Test the analysis with a test trace with two processes doing a statedump | |
218 | * simultaneously. | |
219 | */ | |
220 | @Test | |
221 | public void testTwoProcesses() { | |
222 | UstDebugInfoLoadedBinaryFile matchingFile, expected; | |
223 | int vpid1 = 1337; | |
224 | int vpid2 = 2001; | |
225 | ||
226 | setupTrace(SYNTH_TWO_PROCESSES_TRACE); | |
227 | executeModule(); | |
228 | ||
229 | expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "/tmp/debuglink1", false); | |
230 | matchingFile = fModule.getMatchingFile(11000000, vpid1, 0x400100); | |
231 | assertEquals(expected, matchingFile); | |
232 | ||
233 | expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/bar", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "/tmp/debuglink2", false); | |
234 | matchingFile = fModule.getMatchingFile(12000000, vpid2, 0x400100); | |
235 | assertEquals(expected, matchingFile); | |
236 | } | |
237 | ||
238 | ||
239 | /** | |
240 | * Test the analysis with a trace with debug_link information. | |
241 | */ | |
242 | @Test | |
243 | public void testBuildIDDebugLink() { | |
244 | UstDebugInfoLoadedBinaryFile matchingFile, expected; | |
245 | ||
246 | setupTrace(SYNTH_BUILDID_DEBUGLINK_TRACE); | |
247 | executeModule(); | |
248 | ||
249 | expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_nn", null, null, false); | |
250 | matchingFile = fModule.getMatchingFile(17000000, 1337, 0x400100); | |
251 | assertEquals(expected, matchingFile); | |
252 | ||
253 | expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_yn", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", null, false); | |
254 | matchingFile = fModule.getMatchingFile(18000000, 1338, 0x400100); | |
255 | assertEquals(expected, matchingFile); | |
256 | ||
257 | expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_ny", null, "/tmp/debug_link1", false); | |
258 | matchingFile = fModule.getMatchingFile(19000000, 1339, 0x400100); | |
259 | assertEquals(expected, matchingFile); | |
260 | ||
261 | expected = new UstDebugInfoLoadedBinaryFile(0x400000, "/tmp/foo_yy", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "/tmp/debug_link2", false); | |
262 | matchingFile = fModule.getMatchingFile(20000000, 1340, 0x400100); | |
263 | assertEquals(expected, matchingFile); | |
0b49411f AM |
264 | } |
265 | ||
eb65ae32 AM |
266 | /** |
267 | * Test the {@link UstDebugInfoAnalysisModule#getAllBinaries} method. | |
268 | */ | |
269 | @Test | |
270 | public void testGetAllBinaries() { | |
1633ee0d | 271 | setupTrace(REAL_TEST_TRACE); |
eb65ae32 | 272 | executeModule(); |
1633ee0d | 273 | |
d89151ba AM |
274 | List<UstDebugInfoBinaryFile> actualBinaries = Lists.newArrayList(fModule.getAllBinaries()); |
275 | List<UstDebugInfoBinaryFile> expectedBinaries = Lists.newArrayList( | |
1633ee0d SM |
276 | new UstDebugInfoBinaryFile("/home/simark/src/babeltrace/tests/debug-info-data/libhello_so", |
277 | "cdd98cdd87f7fe64c13b6daad553987eafd40cbb", null, true), | |
278 | new UstDebugInfoBinaryFile("/home/simark/src/babeltrace/tests/debug-info-data/test", | |
279 | "0683255d2cf219c33cc0efd6039db09ccc4416d7", null, false), | |
280 | new UstDebugInfoBinaryFile("[linux-vdso.so.1]", null, null, false), | |
281 | new UstDebugInfoBinaryFile("/usr/local/lib/liblttng-ust-dl.so.0.0.0", | |
282 | "39c035014cc02008d6884fcb1be4e020cc820366", null, true), | |
283 | new UstDebugInfoBinaryFile("/usr/lib/libdl-2.23.so", | |
284 | "db3f9be9f4ebe9e2a21e4ae0b4ef7165d40fdfef", null, true), | |
285 | new UstDebugInfoBinaryFile("/usr/lib/libc-2.23.so", | |
286 | "946025a5cad7b5f2dfbaebc6ebd1fcc004349b48", null, true), | |
287 | new UstDebugInfoBinaryFile("/usr/local/lib/liblttng-ust.so.0.0.0", | |
288 | "405b0b15daa73eccb88076247ba30356c00d3b92", null, true), | |
289 | new UstDebugInfoBinaryFile("/usr/local/lib/liblttng-ust-tracepoint.so.0.0.0", | |
290 | "62c028aad38adb5e0910c527d522e8c86a0a3344", null, true), | |
291 | new UstDebugInfoBinaryFile("/usr/lib/librt-2.23.so", | |
292 | "aba676bda7fb6adb71e100159915504e1a0c17e6", null, true), | |
293 | new UstDebugInfoBinaryFile("/usr/lib/liburcu-bp.so.4.0.0", | |
294 | "b9dfadea234107f8453bc636fc160047e0c01b7a", null, true), | |
295 | new UstDebugInfoBinaryFile("/usr/lib/liburcu-cds.so.4.0.0", | |
296 | "420527f6dacc762378d9fa7def54d91c80a6c87e", null, true), | |
297 | new UstDebugInfoBinaryFile("/usr/lib/libpthread-2.23.so", | |
298 | "d91ed99c8425b7ce5da5bb750662a91038e02a78", null, true), | |
299 | new UstDebugInfoBinaryFile("/usr/lib/ld-2.23.so", | |
300 | "524eff0527e923e4adc4be9db1ef7475607b92e8", null, true), | |
301 | new UstDebugInfoBinaryFile("/usr/lib/liburcu-common.so.4.0.0", | |
302 | "f279a6d46a2b846e15e7abd99cfe9fbe8d7f8295", null, true)); | |
eb65ae32 | 303 | |
d89151ba AM |
304 | Comparator<UstDebugInfoBinaryFile> comparator = Comparator.comparing(UstDebugInfoBinaryFile::getFilePath); |
305 | actualBinaries.sort(comparator); | |
306 | expectedBinaries.sort(comparator); | |
307 | ||
308 | /* Highlights failures more easily */ | |
309 | for (int i = 0; i < expectedBinaries.size(); i++) { | |
310 | assertEquals(expectedBinaries.get(i), actualBinaries.get(i)); | |
311 | } | |
312 | ||
313 | assertEquals(actualBinaries, expectedBinaries); | |
eb65ae32 AM |
314 | } |
315 | ||
316 | } |