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