6ed0d35835ab95dea7dff37eb54578ea2f7de007
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / tracecompass / lttng2 / kernel / core / tests / analysis / kernel / LttngKernelAnalysisTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 É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.tracecompass.lttng2.kernel.core.tests.analysis.kernel;
14
15 import static org.junit.Assert.assertFalse;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertNull;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20
21 import java.util.List;
22
23 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
24 import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
25 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
26 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
27 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
28 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
29 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestHelper;
30 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
31 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
32 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
33 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37
38 /**
39 * Test the {@link KernelAnalysisModule} class
40 *
41 * @author Geneviève Bastien
42 */
43 public class LttngKernelAnalysisTest {
44
45 private LttngKernelTrace fTrace;
46 private KernelAnalysisModule fKernelAnalysisModule;
47
48 /**
49 * Set-up the test
50 */
51 @Before
52 public void setUp() {
53 fKernelAnalysisModule = new KernelAnalysisModule();
54 // Rework the utils to allow creating a sub-type directly.
55 String path = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.KERNEL).getPath();
56
57 fTrace = new LttngKernelTrace();
58 try {
59 fTrace.initTrace(null, path, CtfTmfEvent.class);
60 } catch (TmfTraceException e) {
61 /* Should not happen if tracesExist() passed */
62 throw new RuntimeException(e);
63 }
64 }
65
66 /**
67 * Dispose test objects
68 */
69 @After
70 public void tearDown() {
71 fTrace.dispose();
72 fKernelAnalysisModule.dispose();
73 fTrace = null;
74 fKernelAnalysisModule = null;
75 }
76
77 /**
78 * Test the LTTng kernel analysis execution
79 */
80 @Test
81 public void testAnalysisExecution() {
82 fKernelAnalysisModule.setId("test");
83 ITmfTrace trace = fTrace;
84 assertNotNull(trace);
85 try {
86 assertTrue(fKernelAnalysisModule.setTrace(trace));
87 } catch (TmfAnalysisException e) {
88 fail(e.getMessage());
89 }
90 // Assert the state system has not been initialized yet
91 ITmfStateSystem ss = fKernelAnalysisModule.getStateSystem();
92 assertNull(ss);
93
94 assertTrue(TmfTestHelper.executeAnalysis(fKernelAnalysisModule));
95
96 ss = fKernelAnalysisModule.getStateSystem();
97 assertNotNull(ss);
98
99 List<Integer> quarks = ss.getQuarks("*");
100 assertFalse(quarks.isEmpty());
101 }
102
103 /**
104 * Test the canExecute method on valid and invalid traces
105 */
106 @Test
107 public void testCanExecute() {
108 /* Test with a valid kernel trace */
109 assertNotNull(fTrace);
110 assertTrue(fKernelAnalysisModule.canExecute(fTrace));
111
112 /* Test with a CTF trace that does not have required events */
113 CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.CYG_PROFILE);
114 /*
115 * TODO: This should be false, but for now there is no mandatory events
116 * in the kernel analysis so it will return true.
117 */
118 assertTrue(fKernelAnalysisModule.canExecute(trace));
119 trace.dispose();
120 }
121
122 }
This page took 0.035252 seconds and 4 git commands to generate.