tmf: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / analysis / LttngKernelAnalysisTest.java
CommitLineData
1887c91b
GB
1/*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
3 *
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
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.lttng2.kernel.core.tests.analysis;
14
52cb603c 15import static org.junit.Assert.assertEquals;
1887c91b
GB
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.assertNull;
19import static org.junit.Assert.assertTrue;
20import static org.junit.Assert.fail;
21import static org.junit.Assume.assumeTrue;
22
23import java.util.List;
52cb603c 24import java.util.Set;
1887c91b 25
52cb603c
GM
26import org.eclipse.linuxtools.internal.lttng2.kernel.core.LttngStrings;
27import org.eclipse.linuxtools.lttng2.control.core.session.SessionConfigStrings;
1887c91b
GB
28import org.eclipse.linuxtools.lttng2.kernel.core.analysis.LttngKernelAnalysisModule;
29import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
2bdf0193
AM
30import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement;
31import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
32import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
33import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
34import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
35import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
1887c91b
GB
36import org.junit.After;
37import org.junit.Before;
58ba027e 38import org.junit.BeforeClass;
1887c91b
GB
39import org.junit.Test;
40
52cb603c
GM
41import com.google.common.collect.ImmutableSet;
42
1887c91b
GB
43/**
44 * Test the {@link LttngKernelAnalysisModule} class
45 *
46 * @author Geneviève Bastien
47 */
48public class LttngKernelAnalysisTest {
49
50 private ITmfTrace fTrace;
52cb603c 51 private LttngKernelAnalysisModule fKernelAnalysisModule;
1887c91b 52
58ba027e
AM
53 /**
54 * Class setup
55 */
56 @BeforeClass
57 public static void setUpClass() {
58 assumeTrue(CtfTmfTestTrace.KERNEL.exists());
59 }
60
1887c91b
GB
61 /**
62 * Set-up the test
63 */
64 @Before
65 public void setUp() {
52cb603c 66 fKernelAnalysisModule = new LttngKernelAnalysisModule();
1887c91b
GB
67 fTrace = CtfTmfTestTrace.KERNEL.getTrace();
68 }
69
70 /**
71 * Dispose test objects
72 */
73 @After
74 public void tearDown() {
75 fTrace.dispose();
52cb603c 76 fKernelAnalysisModule.dispose();
1887c91b
GB
77 }
78
79 /**
80 * Test the LTTng kernel analysis execution
81 */
82 @Test
83 public void testAnalysisExecution() {
52cb603c 84 fKernelAnalysisModule.setId("test");
1887c91b 85 try {
52cb603c 86 fKernelAnalysisModule.setTrace(fTrace);
1887c91b
GB
87 } catch (TmfAnalysisException e) {
88 fail(e.getMessage());
89 }
90 // Assert the state system has not been initialized yet
52cb603c 91 ITmfStateSystem ss = fKernelAnalysisModule.getStateSystem();
1887c91b
GB
92 assertNull(ss);
93
52cb603c 94 assertTrue(TmfTestHelper.executeAnalysis(fKernelAnalysisModule));
1887c91b 95
52cb603c 96 ss = fKernelAnalysisModule.getStateSystem();
1887c91b
GB
97 assertNotNull(ss);
98
99 List<Integer> quarks = ss.getQuarks("*");
100 assertFalse(quarks.isEmpty());
101 }
52cb603c 102
26683871
GB
103 /**
104 * Test the canExecute method on valid and invalid traces
105 */
106 @Test
107 public void testCanExecute() {
108 /* Test with a valid kernel trace */
a63890ce 109 assertNotNull(fTrace);
26683871
GB
110 assertTrue(fKernelAnalysisModule.canExecute(fTrace));
111
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();) {
eb00d54d
MK
115 /*
116 * TODO: This should be false, but for now there is no mandatory
117 * events in the kernel analysis so it will return true.
118 */
119 assertTrue(fKernelAnalysisModule.canExecute(trace));
26683871
GB
120 }
121 }
122
52cb603c
GM
123 /**
124 * Test for {@link LttngKernelAnalysisModule#getAnalysisRequirements()}
125 */
126 @Test
127 public void testGetAnalysisRequirements() {
128 Iterable<TmfAnalysisRequirement> requirements = fKernelAnalysisModule.getAnalysisRequirements();
129 assertNotNull(requirements);
130
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;
141 }
142 }
143 assertNotNull(eventReq);
144 assertNotNull(domainReq);
145
146 /* There should be two requirements */
147 assertEquals(2, numberOfRequirement);
148
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);
154 }
155
156 /* Events */
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
173 );
174
175 assertEquals(14, eventReq.getValues().size());
176 for (String event : eventReq.getValues()) {
177 assertTrue("Unexpected event " + event, expectedEvents.contains(event));
178 }
179 }
1887c91b 180}
This page took 0.048103 seconds and 5 git commands to generate.