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