1 /*******************************************************************************
2 * Copyright (c) 2014 É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
.linuxtools
.lttng2
.kernel
.core
.tests
.analysis
;
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
;
23 import java
.util
.List
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.LttngStrings
;
27 import org
.eclipse
.linuxtools
.lttng2
.control
.core
.session
.SessionConfigStrings
;
28 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.analysis
.LttngKernelAnalysisModule
;
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
.tests
.shared
.TmfTestHelper
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
34 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.CtfTmfTrace
;
35 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
36 import org
.junit
.After
;
37 import org
.junit
.Before
;
38 import org
.junit
.BeforeClass
;
39 import org
.junit
.Test
;
41 import com
.google
.common
.collect
.ImmutableSet
;
44 * Test the {@link LttngKernelAnalysisModule} class
46 * @author Geneviève Bastien
48 public class LttngKernelAnalysisTest
{
50 private ITmfTrace fTrace
;
51 private LttngKernelAnalysisModule fKernelAnalysisModule
;
57 public static void setUpClass() {
58 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
66 fKernelAnalysisModule
= new LttngKernelAnalysisModule();
67 fTrace
= CtfTmfTestTrace
.KERNEL
.getTrace();
71 * Dispose test objects
74 public void tearDown() {
76 fKernelAnalysisModule
.dispose();
80 * Test the LTTng kernel analysis execution
83 public void testAnalysisExecution() {
84 fKernelAnalysisModule
.setId("test");
86 fKernelAnalysisModule
.setTrace(fTrace
);
87 } catch (TmfAnalysisException e
) {
90 // Assert the state system has not been initialized yet
91 ITmfStateSystem ss
= fKernelAnalysisModule
.getStateSystem();
94 assertTrue(TmfTestHelper
.executeAnalysis(fKernelAnalysisModule
));
96 ss
= fKernelAnalysisModule
.getStateSystem();
99 List
<Integer
> quarks
= ss
.getQuarks("*");
100 assertFalse(quarks
.isEmpty());
104 * Test the canExecute method on valid and invalid traces
107 public void testCanExecute() {
108 /* Test with a valid kernel trace */
109 assertNotNull(fTrace
);
110 assertTrue(fKernelAnalysisModule
.canExecute(fTrace
));
112 /* Test with a CTF trace that does not have required events */
113 assumeTrue(CtfTmfTestTrace
.CYG_PROFILE
.exists());
114 try (CtfTmfTrace trace
= CtfTmfTestTrace
.CYG_PROFILE
.getTrace();) {
116 * TODO: This should be false, but for now there is no mandatory
117 * events in the kernel analysis so it will return true.
119 assertTrue(fKernelAnalysisModule
.canExecute(trace
));
124 * Test for {@link LttngKernelAnalysisModule#getAnalysisRequirements()}
127 public void testGetAnalysisRequirements() {
128 Iterable
<TmfAnalysisRequirement
> requirements
= fKernelAnalysisModule
.getAnalysisRequirements();
129 assertNotNull(requirements
);
131 /* There should be the event and domain type */
132 TmfAnalysisRequirement eventReq
= null;
133 TmfAnalysisRequirement domainReq
= null;
134 int numberOfRequirement
= 0;
135 for (TmfAnalysisRequirement requirement
: requirements
) {
136 ++numberOfRequirement
;
137 if (requirement
.getType().equals(SessionConfigStrings
.CONFIG_ELEMENT_EVENT
)) {
138 eventReq
= requirement
;
139 } else if (requirement
.getType().equals(SessionConfigStrings
.CONFIG_ELEMENT_DOMAIN
)) {
140 domainReq
= requirement
;
143 assertNotNull(eventReq
);
144 assertNotNull(domainReq
);
146 /* There should be two requirements */
147 assertEquals(2, numberOfRequirement
);
149 /* Verify the content of the requirements themselves */
150 /* Domain should be kernel */
151 assertEquals(1, domainReq
.getValues().size());
152 for (String domain
: domainReq
.getValues()) {
153 assertEquals(SessionConfigStrings
.CONFIG_DOMAIN_TYPE_KERNEL
, domain
);
157 Set
<String
> expectedEvents
= ImmutableSet
.of(
158 LttngStrings
.EXIT_SYSCALL
,
159 LttngStrings
.IRQ_HANDLER_ENTRY
,
160 LttngStrings
.IRQ_HANDLER_EXIT
,
161 LttngStrings
.SOFTIRQ_ENTRY
,
162 LttngStrings
.SOFTIRQ_EXIT
,
163 LttngStrings
.SOFTIRQ_RAISE
,
164 LttngStrings
.SCHED_SWITCH
,
165 LttngStrings
.SCHED_PROCESS_FORK
,
166 LttngStrings
.SCHED_PROCESS_EXIT
,
167 LttngStrings
.SCHED_PROCESS_FREE
,
168 LttngStrings
.STATEDUMP_PROCESS_STATE
,
169 LttngStrings
.SCHED_WAKEUP
,
170 LttngStrings
.SCHED_WAKEUP_NEW
,
171 /* Add the prefix for syscalls */
172 LttngStrings
.SYSCALL_PREFIX
175 assertEquals(14, eventReq
.getValues().size());
176 for (String event
: eventReq
.getValues()) {
177 assertTrue("Unexpected event " + event
, expectedEvents
.contains(event
));