Commit | Line | Data |
---|---|---|
1887c91b | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2014, 2015 École Polytechnique de Montréal |
1887c91b GB |
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 | ||
42d5b5f2 | 13 | package org.eclipse.tracecompass.lttng2.kernel.core.tests.analysis.kernel; |
1887c91b | 14 | |
52cb603c | 15 | import static org.junit.Assert.assertEquals; |
1887c91b GB |
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; | |
1887c91b GB |
21 | |
22 | import java.util.List; | |
52cb603c | 23 | import java.util.Set; |
1887c91b | 24 | |
0f7a12d3 | 25 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule; |
9bc60be7 | 26 | import org.eclipse.tracecompass.lttng2.control.core.session.SessionConfigStrings; |
7411cd67 | 27 | import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace; |
e894a508 | 28 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
c4d57ac1 | 29 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
2bdf0193 AM |
30 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement; |
31 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException; | |
7411cd67 | 32 | import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; |
2bdf0193 | 33 | import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper; |
ba27dd38 | 34 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
7411cd67 | 35 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; |
c4d57ac1 | 36 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils; |
9722e5d7 | 37 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
1887c91b GB |
38 | import org.junit.After; |
39 | import org.junit.Before; | |
e363eae1 | 40 | import org.junit.Ignore; |
1887c91b GB |
41 | import org.junit.Test; |
42 | ||
52cb603c GM |
43 | import com.google.common.collect.ImmutableSet; |
44 | ||
1887c91b | 45 | /** |
6d16f5a9 | 46 | * Test the {@link KernelAnalysisModule} class |
1887c91b GB |
47 | * |
48 | * @author Geneviève Bastien | |
49 | */ | |
50 | public class LttngKernelAnalysisTest { | |
51 | ||
7411cd67 | 52 | private LttngKernelTrace fTrace; |
6d16f5a9 | 53 | private KernelAnalysisModule fKernelAnalysisModule; |
1887c91b GB |
54 | |
55 | /** | |
56 | * Set-up the test | |
57 | */ | |
58 | @Before | |
59 | public void setUp() { | |
6d16f5a9 | 60 | fKernelAnalysisModule = new KernelAnalysisModule(); |
c4d57ac1 AM |
61 | // Rework the utils to allow creating a sub-type directly. |
62 | String path = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.KERNEL).getPath(); | |
63 | ||
7411cd67 AM |
64 | fTrace = new LttngKernelTrace(); |
65 | try { | |
c4d57ac1 | 66 | fTrace.initTrace(null, path, CtfTmfEvent.class); |
7411cd67 AM |
67 | } catch (TmfTraceException e) { |
68 | /* Should not happen if tracesExist() passed */ | |
69 | throw new RuntimeException(e); | |
70 | } | |
1887c91b GB |
71 | } |
72 | ||
73 | /** | |
74 | * Dispose test objects | |
75 | */ | |
76 | @After | |
77 | public void tearDown() { | |
78 | fTrace.dispose(); | |
52cb603c | 79 | fKernelAnalysisModule.dispose(); |
7411cd67 AM |
80 | fTrace = null; |
81 | fKernelAnalysisModule = null; | |
1887c91b GB |
82 | } |
83 | ||
84 | /** | |
85 | * Test the LTTng kernel analysis execution | |
86 | */ | |
87 | @Test | |
88 | public void testAnalysisExecution() { | |
52cb603c | 89 | fKernelAnalysisModule.setId("test"); |
ba27dd38 GB |
90 | ITmfTrace trace = fTrace; |
91 | assertNotNull(trace); | |
1887c91b | 92 | try { |
f479550c | 93 | assertTrue(fKernelAnalysisModule.setTrace(trace)); |
1887c91b GB |
94 | } catch (TmfAnalysisException e) { |
95 | fail(e.getMessage()); | |
96 | } | |
97 | // Assert the state system has not been initialized yet | |
52cb603c | 98 | ITmfStateSystem ss = fKernelAnalysisModule.getStateSystem(); |
1887c91b GB |
99 | assertNull(ss); |
100 | ||
52cb603c | 101 | assertTrue(TmfTestHelper.executeAnalysis(fKernelAnalysisModule)); |
1887c91b | 102 | |
52cb603c | 103 | ss = fKernelAnalysisModule.getStateSystem(); |
1887c91b GB |
104 | assertNotNull(ss); |
105 | ||
106 | List<Integer> quarks = ss.getQuarks("*"); | |
107 | assertFalse(quarks.isEmpty()); | |
108 | } | |
52cb603c | 109 | |
26683871 GB |
110 | /** |
111 | * Test the canExecute method on valid and invalid traces | |
112 | */ | |
113 | @Test | |
114 | public void testCanExecute() { | |
115 | /* Test with a valid kernel trace */ | |
a63890ce | 116 | assertNotNull(fTrace); |
26683871 GB |
117 | assertTrue(fKernelAnalysisModule.canExecute(fTrace)); |
118 | ||
119 | /* Test with a CTF trace that does not have required events */ | |
c4d57ac1 | 120 | CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.CYG_PROFILE); |
0ff9e595 AM |
121 | /* |
122 | * TODO: This should be false, but for now there is no mandatory events | |
123 | * in the kernel analysis so it will return true. | |
124 | */ | |
125 | assertTrue(fKernelAnalysisModule.canExecute(trace)); | |
126 | trace.dispose(); | |
26683871 GB |
127 | } |
128 | ||
52cb603c | 129 | /** |
6d16f5a9 | 130 | * Test for {@link KernelAnalysisModule#getAnalysisRequirements()} |
e363eae1 AM |
131 | * |
132 | * FIXME Ignored for now because the analysis does not provide any | |
133 | * requirements (it doesn't look for particular event names anymore). | |
52cb603c GM |
134 | */ |
135 | @Test | |
e363eae1 | 136 | @Ignore |
52cb603c GM |
137 | public void testGetAnalysisRequirements() { |
138 | Iterable<TmfAnalysisRequirement> requirements = fKernelAnalysisModule.getAnalysisRequirements(); | |
139 | assertNotNull(requirements); | |
140 | ||
141 | /* There should be the event and domain type */ | |
142 | TmfAnalysisRequirement eventReq = null; | |
143 | TmfAnalysisRequirement domainReq = null; | |
144 | int numberOfRequirement = 0; | |
145 | for (TmfAnalysisRequirement requirement : requirements) { | |
146 | ++numberOfRequirement; | |
147 | if (requirement.getType().equals(SessionConfigStrings.CONFIG_ELEMENT_EVENT)) { | |
148 | eventReq = requirement; | |
149 | } else if (requirement.getType().equals(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN)) { | |
150 | domainReq = requirement; | |
151 | } | |
152 | } | |
153 | assertNotNull(eventReq); | |
154 | assertNotNull(domainReq); | |
155 | ||
156 | /* There should be two requirements */ | |
157 | assertEquals(2, numberOfRequirement); | |
158 | ||
159 | /* Verify the content of the requirements themselves */ | |
160 | /* Domain should be kernel */ | |
161 | assertEquals(1, domainReq.getValues().size()); | |
162 | for (String domain : domainReq.getValues()) { | |
163 | assertEquals(SessionConfigStrings.CONFIG_DOMAIN_TYPE_KERNEL, domain); | |
164 | } | |
165 | ||
166 | /* Events */ | |
167 | Set<String> expectedEvents = ImmutableSet.of( | |
7411cd67 AM |
168 | // LttngStrings.EXIT_SYSCALL, |
169 | // LttngStrings.IRQ_HANDLER_ENTRY, | |
170 | // LttngStrings.IRQ_HANDLER_EXIT, | |
171 | // LttngStrings.SOFTIRQ_ENTRY, | |
172 | // LttngStrings.SOFTIRQ_EXIT, | |
173 | // LttngStrings.SOFTIRQ_RAISE, | |
174 | // LttngStrings.SCHED_SWITCH, | |
175 | // LttngStrings.SCHED_PROCESS_FORK, | |
176 | // LttngStrings.SCHED_PROCESS_EXIT, | |
177 | // LttngStrings.SCHED_PROCESS_FREE, | |
178 | // LttngStrings.STATEDUMP_PROCESS_STATE, | |
179 | // LttngStrings.SCHED_WAKEUP, | |
180 | // LttngStrings.SCHED_WAKEUP_NEW, | |
181 | // /* Add the prefix for syscalls */ | |
182 | // LttngStrings.SYSCALL_PREFIX | |
52cb603c GM |
183 | ); |
184 | ||
7411cd67 | 185 | assertEquals(0, eventReq.getValues().size()); |
52cb603c GM |
186 | for (String event : eventReq.getValues()) { |
187 | assertTrue("Unexpected event " + event, expectedEvents.contains(event)); | |
188 | } | |
189 | } | |
1887c91b | 190 | } |