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