1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.lttng2
.ust
.ui
.tests
.analysis
.callstack
;
12 import static org
.junit
.Assert
.assertFalse
;
13 import static org
.junit
.Assert
.assertTrue
;
15 import java
.util
.Collection
;
16 import java
.util
.Collections
;
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
;
28 import com
.google
.common
.collect
.ImmutableSet
;
31 * Test the {@link LttngUstCallStackAnalysisRequirement} class
33 * @author Bernd Hufmann
35 public class LTTngUstCallStackAnalysisRequirementTest
{
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";
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";
47 /* A trace class with pre-defined events with valid events and fields */
48 private static class TraceWithValidEvents
extends LttngUstTrace
{
50 public @NonNull Set
<@NonNull CtfTmfEventType
> getContainedEventTypes() {
51 return ImmutableSet
.of(
52 new CtfTmfEventType(FUNC_ENTRY
, null) {
55 public @NonNull String
getName() {
60 public ITmfEventField
getRootField() {
65 public Collection
<String
> getFieldNames() {
66 return ImmutableSet
.of(CONTEXT_VTID
, CONTEXT_PROCNAME
);
69 new CtfTmfEventType(FUNC_EXIT
, null) {
71 public @NonNull String
getName() {
76 public ITmfEventField
getRootField() {
81 public Collection
<String
> getFieldNames() {
82 return ImmutableSet
.of(CONTEXT_VTID
, CONTEXT_PROCNAME
);
88 /* A trace class with pre-defined events with valid events and fields */
89 private static class TraceWithValidEventsFast
extends LttngUstTrace
{
91 public @NonNull Set
<@NonNull CtfTmfEventType
> getContainedEventTypes() {
92 return ImmutableSet
.of(
93 new CtfTmfEventType(FUNC_ENTRY_FAST
, null) {
96 public @NonNull String
getName() {
97 return FUNC_ENTRY_FAST
;
101 public ITmfEventField
getRootField() {
106 public Collection
<String
> getFieldNames() {
107 return ImmutableSet
.of(CONTEXT_VTID
, CONTEXT_PROCNAME
);
110 new CtfTmfEventType(FUNC_EXIT_FAST
, null) {
112 public @NonNull String
getName() {
113 return FUNC_EXIT_FAST
;
117 public ITmfEventField
getRootField() {
122 public Collection
<String
> getFieldNames() {
123 return ImmutableSet
.of(CONTEXT_VTID
, CONTEXT_PROCNAME
);
130 * A trace class with pre-defined events with valid events but missing
133 private static class TraceWithValidEventsMissingFields
extends LttngUstTrace
{
135 public @NonNull Set
<@NonNull CtfTmfEventType
> getContainedEventTypes() {
136 return ImmutableSet
.of(
137 new CtfTmfEventType(FUNC_ENTRY
, null) {
139 public @NonNull String
getName() {
144 public ITmfEventField
getRootField() {
149 public Collection
<String
> getFieldNames() {
150 return Collections
.EMPTY_LIST
;
153 new CtfTmfEventType(FUNC_EXIT
, null) {
155 public @NonNull String
getName() {
160 public ITmfEventField
getRootField() {
165 public Collection
<String
> getFieldNames() {
166 return ImmutableSet
.of(CONTEXT_VTID
, CONTEXT_PROCNAME
);
173 * A trace class with pre-defined events with valid events but missing
176 private static class TraceWithValidEventsMissingFieldsFast
extends LttngUstTrace
{
178 public @NonNull Set
<@NonNull CtfTmfEventType
> getContainedEventTypes() {
179 return ImmutableSet
.of(
180 new CtfTmfEventType(FUNC_ENTRY_FAST
, null) {
182 public @NonNull String
getName() {
183 return FUNC_ENTRY_FAST
;
187 public ITmfEventField
getRootField() {
192 public Collection
<String
> getFieldNames() {
193 return ImmutableSet
.of(CONTEXT_VTID
, CONTEXT_PROCNAME
);
196 new CtfTmfEventType(FUNC_EXIT_FAST
, null) {
198 public @NonNull String
getName() {
199 return FUNC_EXIT_FAST
;
203 public ITmfEventField
getRootField() {
208 public Collection
<String
> getFieldNames() {
209 return Collections
.EMPTY_LIST
;
216 * A trace class with pre-defined events with valid events but missing
217 * fields and other fields
219 private static class TraceWithValidEventsWrongFields
extends LttngUstTrace
{
221 public @NonNull Set
<@NonNull CtfTmfEventType
> getContainedEventTypes() {
222 return ImmutableSet
.of(
223 new CtfTmfEventType(FUNC_ENTRY
, null) {
225 public @NonNull String
getName() {
230 public ITmfEventField
getRootField() {
235 public Collection
<String
> getFieldNames() {
236 return ImmutableSet
.of(CONTEXT_OTHER
, CONTEXT_PROCNAME
);
239 new CtfTmfEventType(FUNC_EXIT
, null) {
241 public @NonNull String
getName() {
246 public ITmfEventField
getRootField() {
251 public Collection
<String
> getFieldNames() {
252 return ImmutableSet
.of(CONTEXT_OTHER
, CONTEXT_PROCNAME
);
258 /* A trace class with pre-defined events with missing events */
259 private static class TraceWithMissingEvents
extends LttngUstTrace
{
261 public @NonNull Set
<@NonNull CtfTmfEventType
> getContainedEventTypes() {
262 return ImmutableSet
.of(
263 new CtfTmfEventType(OTHER_EVENT
, null) {
265 public @NonNull String
getName() {
270 public ITmfEventField
getRootField() {
275 public Collection
<String
> getFieldNames() {
276 return ImmutableSet
.of(CONTEXT_VTID
, CONTEXT_PROCNAME
);
279 new CtfTmfEventType(FUNC_EXIT_FAST
, null) {
281 public @NonNull String
getName() {
282 return FUNC_EXIT_FAST
;
286 public ITmfEventField
getRootField() {
291 public Collection
<String
> getFieldNames() {
292 return ImmutableSet
.of(CONTEXT_VTID
, CONTEXT_PROCNAME
);
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();
306 * Test with optional requirements
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
));