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