Commit | Line | Data |
---|---|---|
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 | ||
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; | |
21 | import static org.junit.Assume.assumeTrue; | |
22 | ||
23 | import java.util.List; | |
52cb603c | 24 | import java.util.Set; |
1887c91b | 25 | |
e363eae1 | 26 | import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysis; |
9bc60be7 | 27 | import org.eclipse.tracecompass.lttng2.control.core.session.SessionConfigStrings; |
7411cd67 | 28 | import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace; |
e894a508 | 29 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
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; |
2bdf0193 | 36 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
9722e5d7 | 37 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
1887c91b GB |
38 | import org.junit.After; |
39 | import org.junit.Before; | |
58ba027e | 40 | import org.junit.BeforeClass; |
e363eae1 | 41 | import org.junit.Ignore; |
1887c91b GB |
42 | import org.junit.Test; |
43 | ||
52cb603c GM |
44 | import com.google.common.collect.ImmutableSet; |
45 | ||
1887c91b | 46 | /** |
e363eae1 | 47 | * Test the {@link KernelAnalysis} class |
1887c91b GB |
48 | * |
49 | * @author Geneviève Bastien | |
50 | */ | |
51 | public class LttngKernelAnalysisTest { | |
52 | ||
7411cd67 | 53 | private LttngKernelTrace fTrace; |
e363eae1 | 54 | private KernelAnalysis fKernelAnalysisModule; |
1887c91b | 55 | |
58ba027e AM |
56 | /** |
57 | * Class setup | |
58 | */ | |
59 | @BeforeClass | |
60 | public static void setUpClass() { | |
61 | assumeTrue(CtfTmfTestTrace.KERNEL.exists()); | |
62 | } | |
63 | ||
1887c91b GB |
64 | /** |
65 | * Set-up the test | |
66 | */ | |
67 | @Before | |
68 | public void setUp() { | |
e363eae1 | 69 | fKernelAnalysisModule = new KernelAnalysis(); |
7411cd67 AM |
70 | fTrace = new LttngKernelTrace(); |
71 | try { | |
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); | |
76 | } | |
1887c91b GB |
77 | } |
78 | ||
79 | /** | |
80 | * Dispose test objects | |
81 | */ | |
82 | @After | |
83 | public void tearDown() { | |
84 | fTrace.dispose(); | |
52cb603c | 85 | fKernelAnalysisModule.dispose(); |
7411cd67 AM |
86 | fTrace = null; |
87 | fKernelAnalysisModule = null; | |
1887c91b GB |
88 | } |
89 | ||
90 | /** | |
91 | * Test the LTTng kernel analysis execution | |
92 | */ | |
93 | @Test | |
94 | public void testAnalysisExecution() { | |
52cb603c | 95 | fKernelAnalysisModule.setId("test"); |
ba27dd38 GB |
96 | ITmfTrace trace = fTrace; |
97 | assertNotNull(trace); | |
1887c91b | 98 | try { |
ba27dd38 | 99 | fKernelAnalysisModule.setTrace(trace); |
1887c91b GB |
100 | } catch (TmfAnalysisException e) { |
101 | fail(e.getMessage()); | |
102 | } | |
103 | // Assert the state system has not been initialized yet | |
52cb603c | 104 | ITmfStateSystem ss = fKernelAnalysisModule.getStateSystem(); |
1887c91b GB |
105 | assertNull(ss); |
106 | ||
52cb603c | 107 | assertTrue(TmfTestHelper.executeAnalysis(fKernelAnalysisModule)); |
1887c91b | 108 | |
52cb603c | 109 | ss = fKernelAnalysisModule.getStateSystem(); |
1887c91b GB |
110 | assertNotNull(ss); |
111 | ||
112 | List<Integer> quarks = ss.getQuarks("*"); | |
113 | assertFalse(quarks.isEmpty()); | |
114 | } | |
52cb603c | 115 | |
26683871 GB |
116 | /** |
117 | * Test the canExecute method on valid and invalid traces | |
118 | */ | |
119 | @Test | |
120 | public void testCanExecute() { | |
121 | /* Test with a valid kernel trace */ | |
a63890ce | 122 | assertNotNull(fTrace); |
26683871 GB |
123 | assertTrue(fKernelAnalysisModule.canExecute(fTrace)); |
124 | ||
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();) { | |
eb00d54d MK |
128 | /* |
129 | * TODO: This should be false, but for now there is no mandatory | |
130 | * events in the kernel analysis so it will return true. | |
131 | */ | |
132 | assertTrue(fKernelAnalysisModule.canExecute(trace)); | |
26683871 GB |
133 | } |
134 | } | |
135 | ||
52cb603c | 136 | /** |
e363eae1 AM |
137 | * Test for {@link KernelAnalysis#getAnalysisRequirements()} |
138 | * | |
139 | * FIXME Ignored for now because the analysis does not provide any | |
140 | * requirements (it doesn't look for particular event names anymore). | |
52cb603c GM |
141 | */ |
142 | @Test | |
e363eae1 | 143 | @Ignore |
52cb603c GM |
144 | public void testGetAnalysisRequirements() { |
145 | Iterable<TmfAnalysisRequirement> requirements = fKernelAnalysisModule.getAnalysisRequirements(); | |
146 | assertNotNull(requirements); | |
147 | ||
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; | |
158 | } | |
159 | } | |
160 | assertNotNull(eventReq); | |
161 | assertNotNull(domainReq); | |
162 | ||
163 | /* There should be two requirements */ | |
164 | assertEquals(2, numberOfRequirement); | |
165 | ||
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); | |
171 | } | |
172 | ||
173 | /* Events */ | |
174 | Set<String> expectedEvents = ImmutableSet.of( | |
7411cd67 AM |
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 | |
52cb603c GM |
190 | ); |
191 | ||
7411cd67 | 192 | assertEquals(0, eventReq.getValues().size()); |
52cb603c GM |
193 | for (String event : eventReq.getValues()) { |
194 | assertTrue("Unexpected event " + event, expectedEvents.contains(event)); | |
195 | } | |
196 | } | |
1887c91b | 197 | } |