e1b68396206c4c74b6b06d6a0ecdcd1b79ecb59f
[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.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.ui.analysis.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
88 private final @NonNull LttngUstTrace fTrace;
89 private final boolean fIsValid;
90
91 TestData(EventType first, EventType second, boolean isValid) {
92 fTrace = new LttngUstTrace() {
93 @Override
94 public Set<CtfTmfEventType> getContainedEventTypes() {
95 return ImmutableSet.of(first.getEventType(), second.getEventType());
96 }
97 };
98 fIsValid = isValid;
99 }
100
101 @NonNull LttngUstTrace getTrace() {
102 return fTrace;
103 }
104
105 boolean isValid() {
106 return fIsValid;
107 }
108
109 }
110
111 /**
112 * Test Call Stack Analysis requirements
113 */
114 @Test
115 public void testCallStackRequirements() {
116 LttngUstCallStackAnalysisRequirement req = new LttngUstCallStackAnalysisRequirement(ILttngUstEventLayout.DEFAULT_LAYOUT);
117 for (TestData item: TestData.values()) {
118 assertEquals(item.name(), item.isValid(), req.test(item.getTrace()));
119 }
120 }
121 }
This page took 0.034432 seconds and 5 git commands to generate.