1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.analysis
.kernel
;
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
;
22 import java
.util
.List
;
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
.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
;
43 import com
.google
.common
.collect
.ImmutableSet
;
46 * Test the {@link KernelAnalysisModule} class
48 * @author Geneviève Bastien
50 public class LttngKernelAnalysisTest
{
52 private LttngKernelTrace fTrace
;
53 private KernelAnalysisModule fKernelAnalysisModule
;
60 fKernelAnalysisModule
= new KernelAnalysisModule();
61 // Rework the utils to allow creating a sub-type directly.
62 String path
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.KERNEL
).getPath();
64 fTrace
= new LttngKernelTrace();
66 fTrace
.initTrace(null, path
, CtfTmfEvent
.class);
67 } catch (TmfTraceException e
) {
68 /* Should not happen if tracesExist() passed */
69 throw new RuntimeException(e
);
74 * Dispose test objects
77 public void tearDown() {
79 fKernelAnalysisModule
.dispose();
81 fKernelAnalysisModule
= null;
85 * Test the LTTng kernel analysis execution
88 public void testAnalysisExecution() {
89 fKernelAnalysisModule
.setId("test");
90 ITmfTrace trace
= fTrace
;
93 assertTrue(fKernelAnalysisModule
.setTrace(trace
));
94 } catch (TmfAnalysisException e
) {
97 // Assert the state system has not been initialized yet
98 ITmfStateSystem ss
= fKernelAnalysisModule
.getStateSystem();
101 assertTrue(TmfTestHelper
.executeAnalysis(fKernelAnalysisModule
));
103 ss
= fKernelAnalysisModule
.getStateSystem();
106 List
<Integer
> quarks
= ss
.getQuarks("*");
107 assertFalse(quarks
.isEmpty());
111 * Test the canExecute method on valid and invalid traces
114 public void testCanExecute() {
115 /* Test with a valid kernel trace */
116 assertNotNull(fTrace
);
117 assertTrue(fKernelAnalysisModule
.canExecute(fTrace
));
119 /* Test with a CTF trace that does not have required events */
120 CtfTmfTrace trace
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.CYG_PROFILE
);
122 * TODO: This should be false, but for now there is no mandatory events
123 * in the kernel analysis so it will return true.
125 assertTrue(fKernelAnalysisModule
.canExecute(trace
));
130 * Test for {@link KernelAnalysisModule#getAnalysisRequirements()}
132 * FIXME Ignored for now because the analysis does not provide any
133 * requirements (it doesn't look for particular event names anymore).
137 public void testGetAnalysisRequirements() {
138 Iterable
<TmfAnalysisRequirement
> requirements
= fKernelAnalysisModule
.getAnalysisRequirements();
139 assertNotNull(requirements
);
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
;
153 assertNotNull(eventReq
);
154 assertNotNull(domainReq
);
156 /* There should be two requirements */
157 assertEquals(2, numberOfRequirement
);
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
);
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
185 assertEquals(0, eventReq
.getValues().size());
186 for (String event
: eventReq
.getValues()) {
187 assertTrue("Unexpected event " + event
, expectedEvents
.contains(event
));