7d59f667bcdac48c7ddf13f632b46da02a8d954e
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.ui.tests / src / org / eclipse / tracecompass / lttng2 / ust / ui / tests / analysis / callstack / LTTngUstCallStackAnalysisRequirementTest.java
1 /*******************************************************************************
2 * Copyright (c) 2016 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
10 package org.eclipse.tracecompass.lttng2.ust.ui.tests.analysis.callstack;
11
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertTrue;
14
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Set;
18
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.tracecompass.internal.lttng2.ust.ui.analysis.callstack.LttngUstCallStackAnalysisRequirement;
21 import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
22 import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
23 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
24 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
25 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType;
26 import org.junit.Test;
27
28 import com.google.common.collect.ImmutableSet;
29
30 /**
31 * Test the {@link LttngUstCallStackAnalysisRequirement} class
32 *
33 * @author Bernd Hufmann
34 */
35 public class LTTngUstCallStackAnalysisRequirementTest {
36
37 private static final @NonNull String FUNC_EXIT_FAST = "lttng_ust_cyg_profile_fast:func_exit";
38 private static final @NonNull String FUNC_EXIT = "lttng_ust_cyg_profile:func_exit";
39 private static final @NonNull String FUNC_ENTRY_FAST = "lttng_ust_cyg_profile_fast:func_entry";
40 private static final @NonNull String FUNC_ENTRY = "lttng_ust_cyg_profile:func_entry";
41 private static final @NonNull String OTHER_EVENT = "OTHER";
42
43 private static final @NonNull String CONTEXT_VTID = "context._vtid";
44 private static final @NonNull String CONTEXT_PROCNAME = "context._procname";
45 private static final @NonNull String CONTEXT_OTHER = "context._other";
46
47 /* A trace class with pre-defined events with valid events and fields */
48 private static class TraceWithValidEvents extends LttngUstTrace {
49 @Override
50 public @NonNull Set<@NonNull CtfTmfEventType> getContainedEventTypes() {
51 return ImmutableSet.of(
52 new CtfTmfEventType(FUNC_ENTRY, null) {
53
54 @Override
55 public @NonNull String getName() {
56 return FUNC_ENTRY;
57 }
58
59 @Override
60 public ITmfEventField getRootField() {
61 return null;
62 }
63
64 @Override
65 public Collection<String> getFieldNames() {
66 return ImmutableSet.of(CONTEXT_VTID, CONTEXT_PROCNAME);
67 }
68 },
69 new CtfTmfEventType(FUNC_EXIT, null) {
70 @Override
71 public @NonNull String getName() {
72 return FUNC_EXIT;
73 }
74
75 @Override
76 public ITmfEventField getRootField() {
77 return null;
78 }
79
80 @Override
81 public Collection<String> getFieldNames() {
82 return ImmutableSet.of(CONTEXT_VTID, CONTEXT_PROCNAME);
83 }
84 });
85 }
86 }
87
88 /* A trace class with pre-defined events with valid events and fields */
89 private static class TraceWithValidEventsFast extends LttngUstTrace {
90 @Override
91 public @NonNull Set<@NonNull CtfTmfEventType> getContainedEventTypes() {
92 return ImmutableSet.of(
93 new CtfTmfEventType(FUNC_ENTRY_FAST, null) {
94
95 @Override
96 public @NonNull String getName() {
97 return FUNC_ENTRY_FAST;
98 }
99
100 @Override
101 public ITmfEventField getRootField() {
102 return null;
103 }
104
105 @Override
106 public Collection<String> getFieldNames() {
107 return ImmutableSet.of(CONTEXT_VTID, CONTEXT_PROCNAME);
108 }
109 },
110 new CtfTmfEventType(FUNC_EXIT_FAST, null) {
111 @Override
112 public @NonNull String getName() {
113 return FUNC_EXIT_FAST;
114 }
115
116 @Override
117 public ITmfEventField getRootField() {
118 return null;
119 }
120
121 @Override
122 public Collection<String> getFieldNames() {
123 return ImmutableSet.of(CONTEXT_VTID, CONTEXT_PROCNAME);
124 }
125 });
126 }
127 }
128
129 /*
130 * A trace class with pre-defined events with valid events but missing
131 * fields
132 */
133 private static class TraceWithValidEventsMissingFields extends LttngUstTrace {
134 @Override
135 public @NonNull Set<@NonNull CtfTmfEventType> getContainedEventTypes() {
136 return ImmutableSet.of(
137 new CtfTmfEventType(FUNC_ENTRY, null) {
138 @Override
139 public @NonNull String getName() {
140 return FUNC_ENTRY;
141 }
142
143 @Override
144 public ITmfEventField getRootField() {
145 return null;
146 }
147
148 @Override
149 public Collection<String> getFieldNames() {
150 return Collections.EMPTY_LIST;
151 }
152 },
153 new CtfTmfEventType(FUNC_EXIT, null) {
154 @Override
155 public @NonNull String getName() {
156 return FUNC_EXIT;
157 }
158
159 @Override
160 public ITmfEventField getRootField() {
161 return null;
162 }
163
164 @Override
165 public Collection<String> getFieldNames() {
166 return ImmutableSet.of(CONTEXT_VTID, CONTEXT_PROCNAME);
167 }
168 });
169 }
170 }
171
172 /*
173 * A trace class with pre-defined events with valid events but missing
174 * fields
175 */
176 private static class TraceWithValidEventsMissingFieldsFast extends LttngUstTrace {
177 @Override
178 public @NonNull Set<@NonNull CtfTmfEventType> getContainedEventTypes() {
179 return ImmutableSet.of(
180 new CtfTmfEventType(FUNC_ENTRY_FAST, null) {
181 @Override
182 public @NonNull String getName() {
183 return FUNC_ENTRY_FAST;
184 }
185
186 @Override
187 public ITmfEventField getRootField() {
188 return null;
189 }
190
191 @Override
192 public Collection<String> getFieldNames() {
193 return ImmutableSet.of(CONTEXT_VTID, CONTEXT_PROCNAME);
194 }
195 },
196 new CtfTmfEventType(FUNC_EXIT_FAST, null) {
197 @Override
198 public @NonNull String getName() {
199 return FUNC_EXIT_FAST;
200 }
201
202 @Override
203 public ITmfEventField getRootField() {
204 return null;
205 }
206
207 @Override
208 public Collection<String> getFieldNames() {
209 return Collections.EMPTY_LIST;
210 }
211 });
212 }
213 }
214
215 /*
216 * A trace class with pre-defined events with valid events but missing
217 * fields and other fields
218 */
219 private static class TraceWithValidEventsWrongFields extends LttngUstTrace {
220 @Override
221 public @NonNull Set<@NonNull CtfTmfEventType> getContainedEventTypes() {
222 return ImmutableSet.of(
223 new CtfTmfEventType(FUNC_ENTRY, null) {
224 @Override
225 public @NonNull String getName() {
226 return FUNC_ENTRY;
227 }
228
229 @Override
230 public ITmfEventField getRootField() {
231 return null;
232 }
233
234 @Override
235 public Collection<String> getFieldNames() {
236 return ImmutableSet.of(CONTEXT_OTHER, CONTEXT_PROCNAME);
237 }
238 },
239 new CtfTmfEventType(FUNC_EXIT, null) {
240 @Override
241 public @NonNull String getName() {
242 return FUNC_EXIT;
243 }
244
245 @Override
246 public ITmfEventField getRootField() {
247 return null;
248 }
249
250 @Override
251 public Collection<String> getFieldNames() {
252 return ImmutableSet.of(CONTEXT_OTHER, CONTEXT_PROCNAME);
253 }
254 });
255 }
256 }
257
258 /* A trace class with pre-defined events with missing events */
259 private static class TraceWithMissingEvents extends LttngUstTrace {
260 @Override
261 public @NonNull Set<@NonNull CtfTmfEventType> getContainedEventTypes() {
262 return ImmutableSet.of(
263 new CtfTmfEventType(OTHER_EVENT, null) {
264 @Override
265 public @NonNull String getName() {
266 return OTHER_EVENT;
267 }
268
269 @Override
270 public ITmfEventField getRootField() {
271 return null;
272 }
273
274 @Override
275 public Collection<String> getFieldNames() {
276 return ImmutableSet.of(CONTEXT_VTID, CONTEXT_PROCNAME);
277 }
278 },
279 new CtfTmfEventType(FUNC_EXIT_FAST, null) {
280 @Override
281 public @NonNull String getName() {
282 return FUNC_EXIT_FAST;
283 }
284
285 @Override
286 public ITmfEventField getRootField() {
287 return null;
288 }
289
290 @Override
291 public Collection<String> getFieldNames() {
292 return ImmutableSet.of(CONTEXT_VTID, CONTEXT_PROCNAME);
293 }
294 });
295 }
296 }
297
298 private final @NonNull TmfTrace traceValid = new TraceWithValidEvents();
299 private final @NonNull TmfTrace traceValidFast = new TraceWithValidEventsFast();
300 private final @NonNull TmfTrace traceValidMissingFields = new TraceWithValidEventsMissingFields();
301 private final @NonNull TmfTrace traceValidMissingFiledsFast = new TraceWithValidEventsMissingFieldsFast();
302 private final @NonNull TmfTrace traceValidEventsWrongFields = new TraceWithValidEventsWrongFields();
303 private final @NonNull TmfTrace traceMissingEvents = new TraceWithMissingEvents();
304
305 /**
306 * Test with optional requirements
307 */
308 @Test
309 public void testCallStackRequirements() {
310 /* Test optional requirement */
311 LttngUstCallStackAnalysisRequirement req = new LttngUstCallStackAnalysisRequirement(ILttngUstEventLayout.DEFAULT_LAYOUT);
312 assertTrue(req.test(traceValid));
313 assertTrue(req.test(traceValidFast));
314 assertFalse(req.test(traceValidMissingFields));
315 assertFalse(req.test(traceValidMissingFiledsFast));
316 assertFalse(req.test(traceValidEventsWrongFields));
317 assertFalse(req.test(traceMissingEvents));
318 }
319 }
This page took 0.039259 seconds and 4 git commands to generate.