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 | ||
13 | package org.eclipse.linuxtools.lttng2.kernel.core.tests.analysis; | |
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 | |
52cb603c GM |
26 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.LttngStrings; |
27 | import org.eclipse.linuxtools.lttng2.control.core.session.SessionConfigStrings; | |
1887c91b GB |
28 | import org.eclipse.linuxtools.lttng2.kernel.core.analysis.LttngKernelAnalysisModule; |
29 | import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem; | |
52cb603c | 30 | import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement; |
1887c91b GB |
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; | |
26683871 | 34 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace; |
1887c91b GB |
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.Test; | |
39 | ||
52cb603c GM |
40 | import com.google.common.collect.ImmutableSet; |
41 | ||
1887c91b GB |
42 | /** |
43 | * Test the {@link LttngKernelAnalysisModule} class | |
44 | * | |
45 | * @author Geneviève Bastien | |
46 | */ | |
47 | public class LttngKernelAnalysisTest { | |
48 | ||
49 | private ITmfTrace fTrace; | |
52cb603c | 50 | private LttngKernelAnalysisModule fKernelAnalysisModule; |
1887c91b GB |
51 | |
52 | /** | |
53 | * Set-up the test | |
54 | */ | |
55 | @Before | |
56 | public void setUp() { | |
52cb603c | 57 | fKernelAnalysisModule = new LttngKernelAnalysisModule(); |
1887c91b GB |
58 | assumeTrue(CtfTmfTestTrace.KERNEL.exists()); |
59 | fTrace = CtfTmfTestTrace.KERNEL.getTrace(); | |
60 | } | |
61 | ||
62 | /** | |
63 | * Dispose test objects | |
64 | */ | |
65 | @After | |
66 | public void tearDown() { | |
67 | fTrace.dispose(); | |
52cb603c | 68 | fKernelAnalysisModule.dispose(); |
1887c91b GB |
69 | } |
70 | ||
71 | /** | |
72 | * Test the LTTng kernel analysis execution | |
73 | */ | |
74 | @Test | |
75 | public void testAnalysisExecution() { | |
52cb603c | 76 | fKernelAnalysisModule.setId("test"); |
1887c91b | 77 | try { |
52cb603c | 78 | fKernelAnalysisModule.setTrace(fTrace); |
1887c91b GB |
79 | } catch (TmfAnalysisException e) { |
80 | fail(e.getMessage()); | |
81 | } | |
82 | // Assert the state system has not been initialized yet | |
52cb603c | 83 | ITmfStateSystem ss = fKernelAnalysisModule.getStateSystem(); |
1887c91b GB |
84 | assertNull(ss); |
85 | ||
52cb603c | 86 | assertTrue(TmfTestHelper.executeAnalysis(fKernelAnalysisModule)); |
1887c91b | 87 | |
52cb603c | 88 | ss = fKernelAnalysisModule.getStateSystem(); |
1887c91b GB |
89 | assertNotNull(ss); |
90 | ||
91 | List<Integer> quarks = ss.getQuarks("*"); | |
92 | assertFalse(quarks.isEmpty()); | |
93 | } | |
52cb603c | 94 | |
26683871 GB |
95 | /** |
96 | * Test the canExecute method on valid and invalid traces | |
97 | */ | |
98 | @Test | |
99 | public void testCanExecute() { | |
100 | /* Test with a valid kernel trace */ | |
101 | assertTrue(fKernelAnalysisModule.canExecute(fTrace)); | |
102 | ||
103 | /* Test with a CTF trace that does not have required events */ | |
104 | assumeTrue(CtfTmfTestTrace.CYG_PROFILE.exists()); | |
105 | try (CtfTmfTrace trace = CtfTmfTestTrace.CYG_PROFILE.getTrace();) { | |
106 | assertFalse(fKernelAnalysisModule.canExecute(trace)); | |
107 | } | |
108 | } | |
109 | ||
52cb603c GM |
110 | /** |
111 | * Test for {@link LttngKernelAnalysisModule#getAnalysisRequirements()} | |
112 | */ | |
113 | @Test | |
114 | public void testGetAnalysisRequirements() { | |
115 | Iterable<TmfAnalysisRequirement> requirements = fKernelAnalysisModule.getAnalysisRequirements(); | |
116 | assertNotNull(requirements); | |
117 | ||
118 | /* There should be the event and domain type */ | |
119 | TmfAnalysisRequirement eventReq = null; | |
120 | TmfAnalysisRequirement domainReq = null; | |
121 | int numberOfRequirement = 0; | |
122 | for (TmfAnalysisRequirement requirement : requirements) { | |
123 | ++numberOfRequirement; | |
124 | if (requirement.getType().equals(SessionConfigStrings.CONFIG_ELEMENT_EVENT)) { | |
125 | eventReq = requirement; | |
126 | } else if (requirement.getType().equals(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN)) { | |
127 | domainReq = requirement; | |
128 | } | |
129 | } | |
130 | assertNotNull(eventReq); | |
131 | assertNotNull(domainReq); | |
132 | ||
133 | /* There should be two requirements */ | |
134 | assertEquals(2, numberOfRequirement); | |
135 | ||
136 | /* Verify the content of the requirements themselves */ | |
137 | /* Domain should be kernel */ | |
138 | assertEquals(1, domainReq.getValues().size()); | |
139 | for (String domain : domainReq.getValues()) { | |
140 | assertEquals(SessionConfigStrings.CONFIG_DOMAIN_TYPE_KERNEL, domain); | |
141 | } | |
142 | ||
143 | /* Events */ | |
144 | Set<String> expectedEvents = ImmutableSet.of( | |
145 | LttngStrings.EXIT_SYSCALL, | |
146 | LttngStrings.IRQ_HANDLER_ENTRY, | |
147 | LttngStrings.IRQ_HANDLER_EXIT, | |
148 | LttngStrings.SOFTIRQ_ENTRY, | |
149 | LttngStrings.SOFTIRQ_EXIT, | |
150 | LttngStrings.SOFTIRQ_RAISE, | |
151 | LttngStrings.SCHED_SWITCH, | |
152 | LttngStrings.SCHED_PROCESS_FORK, | |
153 | LttngStrings.SCHED_PROCESS_EXIT, | |
154 | LttngStrings.SCHED_PROCESS_FREE, | |
155 | LttngStrings.STATEDUMP_PROCESS_STATE, | |
156 | LttngStrings.SCHED_WAKEUP, | |
157 | LttngStrings.SCHED_WAKEUP_NEW, | |
158 | /* Add the prefix for syscalls */ | |
159 | LttngStrings.SYSCALL_PREFIX | |
160 | ); | |
161 | ||
162 | assertEquals(14, eventReq.getValues().size()); | |
163 | for (String event : eventReq.getValues()) { | |
164 | assertTrue("Unexpected event " + event, expectedEvents.contains(event)); | |
165 | } | |
166 | } | |
1887c91b | 167 | } |