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
.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
;
21 import static org
.junit
.Assume
.assumeTrue
;
23 import java
.util
.List
;
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
;
43 import com
.google
.common
.collect
.ImmutableSet
;
46 * Test the {@link LttngKernelAnalysis} class
48 * @author Geneviève Bastien
50 public class LttngKernelAnalysisTest
{
52 private LttngKernelTrace fTrace
;
53 private LttngKernelAnalysis fKernelAnalysisModule
;
59 public static void setUpClass() {
60 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
68 fKernelAnalysisModule
= new LttngKernelAnalysis();
69 fTrace
= new LttngKernelTrace();
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
);
79 * Dispose test objects
82 public void tearDown() {
84 fKernelAnalysisModule
.dispose();
86 fKernelAnalysisModule
= null;
90 * Test the LTTng kernel analysis execution
93 public void testAnalysisExecution() {
94 fKernelAnalysisModule
.setId("test");
95 ITmfTrace trace
= fTrace
;
98 fKernelAnalysisModule
.setTrace(trace
);
99 } catch (TmfAnalysisException e
) {
100 fail(e
.getMessage());
102 // Assert the state system has not been initialized yet
103 ITmfStateSystem ss
= fKernelAnalysisModule
.getStateSystem();
106 assertTrue(TmfTestHelper
.executeAnalysis(fKernelAnalysisModule
));
108 ss
= fKernelAnalysisModule
.getStateSystem();
111 List
<Integer
> quarks
= ss
.getQuarks("*");
112 assertFalse(quarks
.isEmpty());
116 * Test the canExecute method on valid and invalid traces
119 public void testCanExecute() {
120 /* Test with a valid kernel trace */
121 assertNotNull(fTrace
);
122 assertTrue(fKernelAnalysisModule
.canExecute(fTrace
));
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();) {
128 * TODO: This should be false, but for now there is no mandatory
129 * events in the kernel analysis so it will return true.
131 assertTrue(fKernelAnalysisModule
.canExecute(trace
));
136 * Test for {@link LttngKernelAnalysis#getAnalysisRequirements()}
139 public void testGetAnalysisRequirements() {
140 Iterable
<TmfAnalysisRequirement
> requirements
= fKernelAnalysisModule
.getAnalysisRequirements();
141 assertNotNull(requirements
);
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
;
155 assertNotNull(eventReq
);
156 assertNotNull(domainReq
);
158 /* There should be two requirements */
159 assertEquals(2, numberOfRequirement
);
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
);
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
187 assertEquals(0, eventReq
.getValues().size());
188 for (String event
: eventReq
.getValues()) {
189 assertTrue("Unexpected event " + event
, expectedEvents
.contains(event
));