tmf/ust: deprecate AbstractCallStackAnalysis and move the UST module to core
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core.tests / src / org / eclipse / tracecompass / lttng2 / ust / core / tests / 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.core.tests.callstack;
11
12 import static org.junit.Assert.assertEquals;
13
14 import java.util.Collection;
15 import java.util.Set;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.tracecompass.internal.lttng2.ust.core.callstack.LttngUstCallStackAnalysisRequirement;
19 import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
20 import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
21 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType;
22 import org.junit.Test;
23
24 import com.google.common.collect.ImmutableSet;
25
26 /**
27 * Test the {@link LttngUstCallStackAnalysisRequirement} class
28 *
29 * @author Bernd Hufmann
30 */
31 public class LTTngUstCallStackAnalysisRequirementTest {
32
33 private static final @NonNull String FUNC_EXIT_FAST = "lttng_ust_cyg_profile_fast:func_exit";
34 private static final @NonNull String FUNC_EXIT = "lttng_ust_cyg_profile:func_exit";
35 private static final @NonNull String FUNC_ENTRY_FAST = "lttng_ust_cyg_profile_fast:func_entry";
36 private static final @NonNull String FUNC_ENTRY = "lttng_ust_cyg_profile:func_entry";
37 private static final @NonNull String OTHER_EVENT = "OTHER";
38
39 private static final @NonNull String CONTEXT_VTID = "context._vtid";
40 private static final @NonNull String CONTEXT_PROCNAME = "context._procname";
41 private static final @NonNull String CONTEXT_OTHER = "context._other";
42
43 private static final @NonNull Collection<String> validFields = ImmutableSet.of(CONTEXT_VTID, CONTEXT_PROCNAME);
44 private static final @NonNull Collection<String> badFields = ImmutableSet.of(CONTEXT_OTHER, CONTEXT_PROCNAME);
45
46 enum EventType {
47 EVT_EXIT_FAST (FUNC_EXIT_FAST, validFields),
48 EVT_EXIT (FUNC_EXIT, validFields),
49 EVT_ENTRY_FAST (FUNC_ENTRY_FAST, validFields),
50 EVT_ENTRY (FUNC_ENTRY, validFields),
51 EVT_OTHER (OTHER_EVENT, validFields),
52 EVT_ENTRY_BAD_FIELDS (FUNC_ENTRY, badFields),
53 EVT_ENTRY_FAST_BAD_FIELDS (FUNC_ENTRY_FAST, badFields),
54 EVT_ENTRY_FAST_EMPTY_FIELDS (FUNC_ENTRY_FAST, ImmutableSet.of());
55
56 private final @NonNull CtfTmfEventType fType;
57
58 EventType(@NonNull String name, @NonNull Collection<String> fields) {
59 fType = new CtfTmfEventType(name, null) {
60 @Override
61 public String getName() {
62 return name;
63 }
64 @Override
65 public @NonNull Collection<String> getFieldNames() {
66 return fields;
67 }
68 };
69 }
70
71 @NonNull CtfTmfEventType getEventType() {
72 return fType;
73 }
74 }
75
76 enum TestData {
77 TRACE_WITH_VALID_EVENTS(EventType.EVT_ENTRY, EventType.EVT_EXIT, true),
78 TRACE_WITH_VALID_EVENTS_FAST(EventType.EVT_ENTRY_FAST, EventType.EVT_EXIT_FAST, true),
79 TRACE_WITH_VALID_EVENTS_MISSING_FIELDS(EventType.EVT_ENTRY_BAD_FIELDS,
80 EventType.EVT_EXIT, false),
81 TRACE_WITH_VALID_EVENTS_MISSING_FIELDS_FAST(EventType.EVT_ENTRY_FAST_BAD_FIELDS,
82 EventType.EVT_EXIT_FAST, false),
83 TRACE_WITH_VALID_EVENTS_WRONG_FIELDS(EventType.EVT_ENTRY_FAST_EMPTY_FIELDS,
84 EventType.EVT_EXIT_FAST, false),
85 TRACE_WITH_MISSING_EVENTS(EventType.EVT_OTHER,
86 EventType.EVT_EXIT_FAST, false),
87 TRACE_MISMATCH_EVENTS(EventType.EVT_ENTRY_FAST, EventType.EVT_EXIT, false);
88
89 private final @NonNull LttngUstTrace fTrace;
90 private final boolean fIsValid;
91
92 TestData(EventType first, EventType second, boolean isValid) {
93 fTrace = new LttngUstTrace() {
94 @Override
95 public Set<CtfTmfEventType> getContainedEventTypes() {
96 return ImmutableSet.of(first.getEventType(), second.getEventType());
97 }
98 };
99 fIsValid = isValid;
100 }
101
102 @NonNull LttngUstTrace getTrace() {
103 return fTrace;
104 }
105
106 boolean isValid() {
107 return fIsValid;
108 }
109
110 }
111
112 /**
113 * Test Call Stack Analysis requirements
114 */
115 @Test
116 public void testCallStackRequirements() {
117 LttngUstCallStackAnalysisRequirement req = new LttngUstCallStackAnalysisRequirement(ILttngUstEventLayout.DEFAULT_LAYOUT);
118 for (TestData item: TestData.values()) {
119 assertEquals(item.name(), item.isValid(), req.test(item.getTrace()));
120 }
121 }
122 }
This page took 0.048187 seconds and 5 git commands to generate.