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
.ctf
.core
.event
.CtfTmfEvent
;
35 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
36 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
37 import org
.junit
.After
;
38 import org
.junit
.Before
;
39 import org
.junit
.BeforeClass
;
40 import org
.junit
.Test
;
42 import com
.google
.common
.collect
.ImmutableSet
;
45 * Test the {@link LttngKernelAnalysis} class
47 * @author Geneviève Bastien
49 public class LttngKernelAnalysisTest
{
51 private LttngKernelTrace fTrace
;
52 private LttngKernelAnalysis fKernelAnalysisModule
;
58 public static void setUpClass() {
59 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
67 fKernelAnalysisModule
= new LttngKernelAnalysis();
68 fTrace
= new LttngKernelTrace();
70 fTrace
.initTrace(null, CtfTmfTestTrace
.KERNEL
.getPath(), CtfTmfEvent
.class);
71 } catch (TmfTraceException e
) {
72 /* Should not happen if tracesExist() passed */
73 throw new RuntimeException(e
);
78 * Dispose test objects
81 public void tearDown() {
83 fKernelAnalysisModule
.dispose();
85 fKernelAnalysisModule
= null;
89 * Test the LTTng kernel analysis execution
92 public void testAnalysisExecution() {
93 fKernelAnalysisModule
.setId("test");
95 fKernelAnalysisModule
.setTrace(fTrace
);
96 } catch (TmfAnalysisException e
) {
99 // Assert the state system has not been initialized yet
100 ITmfStateSystem ss
= fKernelAnalysisModule
.getStateSystem();
103 assertTrue(TmfTestHelper
.executeAnalysis(fKernelAnalysisModule
));
105 ss
= fKernelAnalysisModule
.getStateSystem();
108 List
<Integer
> quarks
= ss
.getQuarks("*");
109 assertFalse(quarks
.isEmpty());
113 * Test the canExecute method on valid and invalid traces
116 public void testCanExecute() {
117 /* Test with a valid kernel trace */
118 assertNotNull(fTrace
);
119 assertTrue(fKernelAnalysisModule
.canExecute(fTrace
));
121 /* Test with a CTF trace that does not have required events */
122 assumeTrue(CtfTmfTestTrace
.CYG_PROFILE
.exists());
123 try (CtfTmfTrace trace
= CtfTmfTestTrace
.CYG_PROFILE
.getTrace();) {
125 * TODO: This should be false, but for now there is no mandatory
126 * events in the kernel analysis so it will return true.
128 assertTrue(fKernelAnalysisModule
.canExecute(trace
));
133 * Test for {@link LttngKernelAnalysis#getAnalysisRequirements()}
136 public void testGetAnalysisRequirements() {
137 Iterable
<TmfAnalysisRequirement
> requirements
= fKernelAnalysisModule
.getAnalysisRequirements();
138 assertNotNull(requirements
);
140 /* There should be the event and domain type */
141 TmfAnalysisRequirement eventReq
= null;
142 TmfAnalysisRequirement domainReq
= null;
143 int numberOfRequirement
= 0;
144 for (TmfAnalysisRequirement requirement
: requirements
) {
145 ++numberOfRequirement
;
146 if (requirement
.getType().equals(SessionConfigStrings
.CONFIG_ELEMENT_EVENT
)) {
147 eventReq
= requirement
;
148 } else if (requirement
.getType().equals(SessionConfigStrings
.CONFIG_ELEMENT_DOMAIN
)) {
149 domainReq
= requirement
;
152 assertNotNull(eventReq
);
153 assertNotNull(domainReq
);
155 /* There should be two requirements */
156 assertEquals(2, numberOfRequirement
);
158 /* Verify the content of the requirements themselves */
159 /* Domain should be kernel */
160 assertEquals(1, domainReq
.getValues().size());
161 for (String domain
: domainReq
.getValues()) {
162 assertEquals(SessionConfigStrings
.CONFIG_DOMAIN_TYPE_KERNEL
, domain
);
166 Set
<String
> expectedEvents
= ImmutableSet
.of(
167 // LttngStrings.EXIT_SYSCALL,
168 // LttngStrings.IRQ_HANDLER_ENTRY,
169 // LttngStrings.IRQ_HANDLER_EXIT,
170 // LttngStrings.SOFTIRQ_ENTRY,
171 // LttngStrings.SOFTIRQ_EXIT,
172 // LttngStrings.SOFTIRQ_RAISE,
173 // LttngStrings.SCHED_SWITCH,
174 // LttngStrings.SCHED_PROCESS_FORK,
175 // LttngStrings.SCHED_PROCESS_EXIT,
176 // LttngStrings.SCHED_PROCESS_FREE,
177 // LttngStrings.STATEDUMP_PROCESS_STATE,
178 // LttngStrings.SCHED_WAKEUP,
179 // LttngStrings.SCHED_WAKEUP_NEW,
180 // /* Add the prefix for syscalls */
181 // LttngStrings.SYSCALL_PREFIX
184 assertEquals(0, eventReq
.getValues().size());
185 for (String event
: eventReq
.getValues()) {
186 assertTrue("Unexpected event " + event
, expectedEvents
.contains(event
));