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
;
21 import static org
.junit
.Assume
.assumeTrue
;
23 import java
.util
.List
;
26 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.KernelAnalysis
;
27 import org
.eclipse
.tracecompass
.lttng2
.control
.core
.session
.SessionConfigStrings
;
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
.Ignore
;
42 import org
.junit
.Test
;
44 import com
.google
.common
.collect
.ImmutableSet
;
47 * Test the {@link KernelAnalysis} class
49 * @author Geneviève Bastien
51 public class LttngKernelAnalysisTest
{
53 private LttngKernelTrace fTrace
;
54 private KernelAnalysis fKernelAnalysisModule
;
60 public static void setUpClass() {
61 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
69 fKernelAnalysisModule
= new KernelAnalysis();
70 fTrace
= new LttngKernelTrace();
72 fTrace
.initTrace(null, CtfTmfTestTrace
.KERNEL
.getPath(), CtfTmfEvent
.class);
73 } catch (TmfTraceException e
) {
74 /* Should not happen if tracesExist() passed */
75 throw new RuntimeException(e
);
80 * Dispose test objects
83 public void tearDown() {
85 fKernelAnalysisModule
.dispose();
87 fKernelAnalysisModule
= null;
91 * Test the LTTng kernel analysis execution
94 public void testAnalysisExecution() {
95 fKernelAnalysisModule
.setId("test");
96 ITmfTrace trace
= fTrace
;
99 fKernelAnalysisModule
.setTrace(trace
);
100 } catch (TmfAnalysisException e
) {
101 fail(e
.getMessage());
103 // Assert the state system has not been initialized yet
104 ITmfStateSystem ss
= fKernelAnalysisModule
.getStateSystem();
107 assertTrue(TmfTestHelper
.executeAnalysis(fKernelAnalysisModule
));
109 ss
= fKernelAnalysisModule
.getStateSystem();
112 List
<Integer
> quarks
= ss
.getQuarks("*");
113 assertFalse(quarks
.isEmpty());
117 * Test the canExecute method on valid and invalid traces
120 public void testCanExecute() {
121 /* Test with a valid kernel trace */
122 assertNotNull(fTrace
);
123 assertTrue(fKernelAnalysisModule
.canExecute(fTrace
));
125 /* Test with a CTF trace that does not have required events */
126 assumeTrue(CtfTmfTestTrace
.CYG_PROFILE
.exists());
127 try (CtfTmfTrace trace
= CtfTmfTestTrace
.CYG_PROFILE
.getTrace();) {
129 * TODO: This should be false, but for now there is no mandatory
130 * events in the kernel analysis so it will return true.
132 assertTrue(fKernelAnalysisModule
.canExecute(trace
));
137 * Test for {@link KernelAnalysis#getAnalysisRequirements()}
139 * FIXME Ignored for now because the analysis does not provide any
140 * requirements (it doesn't look for particular event names anymore).
144 public void testGetAnalysisRequirements() {
145 Iterable
<TmfAnalysisRequirement
> requirements
= fKernelAnalysisModule
.getAnalysisRequirements();
146 assertNotNull(requirements
);
148 /* There should be the event and domain type */
149 TmfAnalysisRequirement eventReq
= null;
150 TmfAnalysisRequirement domainReq
= null;
151 int numberOfRequirement
= 0;
152 for (TmfAnalysisRequirement requirement
: requirements
) {
153 ++numberOfRequirement
;
154 if (requirement
.getType().equals(SessionConfigStrings
.CONFIG_ELEMENT_EVENT
)) {
155 eventReq
= requirement
;
156 } else if (requirement
.getType().equals(SessionConfigStrings
.CONFIG_ELEMENT_DOMAIN
)) {
157 domainReq
= requirement
;
160 assertNotNull(eventReq
);
161 assertNotNull(domainReq
);
163 /* There should be two requirements */
164 assertEquals(2, numberOfRequirement
);
166 /* Verify the content of the requirements themselves */
167 /* Domain should be kernel */
168 assertEquals(1, domainReq
.getValues().size());
169 for (String domain
: domainReq
.getValues()) {
170 assertEquals(SessionConfigStrings
.CONFIG_DOMAIN_TYPE_KERNEL
, domain
);
174 Set
<String
> expectedEvents
= ImmutableSet
.of(
175 // LttngStrings.EXIT_SYSCALL,
176 // LttngStrings.IRQ_HANDLER_ENTRY,
177 // LttngStrings.IRQ_HANDLER_EXIT,
178 // LttngStrings.SOFTIRQ_ENTRY,
179 // LttngStrings.SOFTIRQ_EXIT,
180 // LttngStrings.SOFTIRQ_RAISE,
181 // LttngStrings.SCHED_SWITCH,
182 // LttngStrings.SCHED_PROCESS_FORK,
183 // LttngStrings.SCHED_PROCESS_EXIT,
184 // LttngStrings.SCHED_PROCESS_FREE,
185 // LttngStrings.STATEDUMP_PROCESS_STATE,
186 // LttngStrings.SCHED_WAKEUP,
187 // LttngStrings.SCHED_WAKEUP_NEW,
188 // /* Add the prefix for syscalls */
189 // LttngStrings.SYSCALL_PREFIX
192 assertEquals(0, eventReq
.getValues().size());
193 for (String event
: eventReq
.getValues()) {
194 assertTrue("Unexpected event " + event
, expectedEvents
.contains(event
));