lttng: Add interface to abstract the event layout away
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / tracecompass / lttng2 / kernel / core / tests / analysis / kernel / LttngKernelAnalysisTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.kernel;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertNull;
19 import static org.junit.Assert.assertTrue;
20 import static org.junit.Assert.fail;
21 import static org.junit.Assume.assumeTrue;
22
23 import java.util.List;
24 import java.util.Set;
25
26 import org.eclipse.tracecompass.lttng2.control.core.session.SessionConfigStrings;
27 import org.eclipse.tracecompass.lttng2.kernel.core.analysis.kernel.LttngKernelAnalysis;
28 import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
29 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
30 import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement;
31 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
32 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
33 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
34 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
35 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
36 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
37 import org.junit.After;
38 import org.junit.Before;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41
42 import com.google.common.collect.ImmutableSet;
43
44 /**
45 * Test the {@link LttngKernelAnalysis} class
46 *
47 * @author Geneviève Bastien
48 */
49 public class LttngKernelAnalysisTest {
50
51 private LttngKernelTrace fTrace;
52 private LttngKernelAnalysis fKernelAnalysisModule;
53
54 /**
55 * Class setup
56 */
57 @BeforeClass
58 public static void setUpClass() {
59 assumeTrue(CtfTmfTestTrace.KERNEL.exists());
60 }
61
62 /**
63 * Set-up the test
64 */
65 @Before
66 public void setUp() {
67 fKernelAnalysisModule = new LttngKernelAnalysis();
68 fTrace = new LttngKernelTrace();
69 try {
70 fTrace.initTrace(null, CtfTmfTestTrace.KERNEL.getPath(), CtfTmfEvent.class);
71 } catch (TmfTraceException e) {
72 /* Should not happen if tracesExist() passed */
73 throw new RuntimeException(e);
74 }
75 }
76
77 /**
78 * Dispose test objects
79 */
80 @After
81 public void tearDown() {
82 fTrace.dispose();
83 fKernelAnalysisModule.dispose();
84 fTrace = null;
85 fKernelAnalysisModule = null;
86 }
87
88 /**
89 * Test the LTTng kernel analysis execution
90 */
91 @Test
92 public void testAnalysisExecution() {
93 fKernelAnalysisModule.setId("test");
94 try {
95 fKernelAnalysisModule.setTrace(fTrace);
96 } catch (TmfAnalysisException e) {
97 fail(e.getMessage());
98 }
99 // Assert the state system has not been initialized yet
100 ITmfStateSystem ss = fKernelAnalysisModule.getStateSystem();
101 assertNull(ss);
102
103 assertTrue(TmfTestHelper.executeAnalysis(fKernelAnalysisModule));
104
105 ss = fKernelAnalysisModule.getStateSystem();
106 assertNotNull(ss);
107
108 List<Integer> quarks = ss.getQuarks("*");
109 assertFalse(quarks.isEmpty());
110 }
111
112 /**
113 * Test the canExecute method on valid and invalid traces
114 */
115 @Test
116 public void testCanExecute() {
117 /* Test with a valid kernel trace */
118 assertNotNull(fTrace);
119 assertTrue(fKernelAnalysisModule.canExecute(fTrace));
120
121 /* Test with a CTF trace that does not have required events */
122 assumeTrue(CtfTmfTestTrace.CYG_PROFILE.exists());
123 try (CtfTmfTrace trace = CtfTmfTestTrace.CYG_PROFILE.getTrace();) {
124 /*
125 * TODO: This should be false, but for now there is no mandatory
126 * events in the kernel analysis so it will return true.
127 */
128 assertTrue(fKernelAnalysisModule.canExecute(trace));
129 }
130 }
131
132 /**
133 * Test for {@link LttngKernelAnalysis#getAnalysisRequirements()}
134 */
135 @Test
136 public void testGetAnalysisRequirements() {
137 Iterable<TmfAnalysisRequirement> requirements = fKernelAnalysisModule.getAnalysisRequirements();
138 assertNotNull(requirements);
139
140 /* There should be the event and domain type */
141 TmfAnalysisRequirement eventReq = null;
142 TmfAnalysisRequirement domainReq = null;
143 int numberOfRequirement = 0;
144 for (TmfAnalysisRequirement requirement : requirements) {
145 ++numberOfRequirement;
146 if (requirement.getType().equals(SessionConfigStrings.CONFIG_ELEMENT_EVENT)) {
147 eventReq = requirement;
148 } else if (requirement.getType().equals(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN)) {
149 domainReq = requirement;
150 }
151 }
152 assertNotNull(eventReq);
153 assertNotNull(domainReq);
154
155 /* There should be two requirements */
156 assertEquals(2, numberOfRequirement);
157
158 /* Verify the content of the requirements themselves */
159 /* Domain should be kernel */
160 assertEquals(1, domainReq.getValues().size());
161 for (String domain : domainReq.getValues()) {
162 assertEquals(SessionConfigStrings.CONFIG_DOMAIN_TYPE_KERNEL, domain);
163 }
164
165 /* Events */
166 Set<String> expectedEvents = ImmutableSet.of(
167 // LttngStrings.EXIT_SYSCALL,
168 // LttngStrings.IRQ_HANDLER_ENTRY,
169 // LttngStrings.IRQ_HANDLER_EXIT,
170 // LttngStrings.SOFTIRQ_ENTRY,
171 // LttngStrings.SOFTIRQ_EXIT,
172 // LttngStrings.SOFTIRQ_RAISE,
173 // LttngStrings.SCHED_SWITCH,
174 // LttngStrings.SCHED_PROCESS_FORK,
175 // LttngStrings.SCHED_PROCESS_EXIT,
176 // LttngStrings.SCHED_PROCESS_FREE,
177 // LttngStrings.STATEDUMP_PROCESS_STATE,
178 // LttngStrings.SCHED_WAKEUP,
179 // LttngStrings.SCHED_WAKEUP_NEW,
180 // /* Add the prefix for syscalls */
181 // LttngStrings.SYSCALL_PREFIX
182 );
183
184 assertEquals(0, eventReq.getValues().size());
185 for (String event : eventReq.getValues()) {
186 assertTrue("Unexpected event " + event, expectedEvents.contains(event));
187 }
188 }
189 }
This page took 0.040634 seconds and 5 git commands to generate.