gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core.tests / src / org / eclipse / linuxtools / lttng2 / kernel / core / tests / analysis / LttngKernelAnalysisTest.java
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
13 package org.eclipse.linuxtools.lttng2.kernel.core.tests.analysis;
14
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;
22
23 import java.util.List;
24 import java.util.Set;
25
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.linuxtools.statesystem.core.ITmfStateSystem;
30 import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
31 import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
32 import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestHelper;
33 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
34 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
35 import org.eclipse.linuxtools.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;
40
41 import com.google.common.collect.ImmutableSet;
42
43 /**
44 * Test the {@link LttngKernelAnalysisModule} class
45 *
46 * @author Geneviève Bastien
47 */
48 public class LttngKernelAnalysisTest {
49
50 private ITmfTrace fTrace;
51 private LttngKernelAnalysisModule fKernelAnalysisModule;
52
53 /**
54 * Class setup
55 */
56 @BeforeClass
57 public static void setUpClass() {
58 assumeTrue(CtfTmfTestTrace.KERNEL.exists());
59 }
60
61 /**
62 * Set-up the test
63 */
64 @Before
65 public void setUp() {
66 fKernelAnalysisModule = new LttngKernelAnalysisModule();
67 fTrace = CtfTmfTestTrace.KERNEL.getTrace();
68 }
69
70 /**
71 * Dispose test objects
72 */
73 @After
74 public void tearDown() {
75 fTrace.dispose();
76 fKernelAnalysisModule.dispose();
77 }
78
79 /**
80 * Test the LTTng kernel analysis execution
81 */
82 @Test
83 public void testAnalysisExecution() {
84 fKernelAnalysisModule.setId("test");
85 try {
86 fKernelAnalysisModule.setTrace(fTrace);
87 } catch (TmfAnalysisException e) {
88 fail(e.getMessage());
89 }
90 // Assert the state system has not been initialized yet
91 ITmfStateSystem ss = fKernelAnalysisModule.getStateSystem();
92 assertNull(ss);
93
94 assertTrue(TmfTestHelper.executeAnalysis(fKernelAnalysisModule));
95
96 ss = fKernelAnalysisModule.getStateSystem();
97 assertNotNull(ss);
98
99 List<Integer> quarks = ss.getQuarks("*");
100 assertFalse(quarks.isEmpty());
101 }
102
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 */
109 assertNotNull(fTrace);
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();) {
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));
120 }
121 }
122
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 }
180 }
This page took 0.054307 seconds and 5 git commands to generate.