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