Commit | Line | Data |
---|---|---|
312f397a GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 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 | |
312f397a GB |
8 | *******************************************************************************/ |
9 | ||
10 | package org.eclipse.tracecompass.analysis.os.linux.core.tests.kernelanalysis; | |
11 | ||
12 | import static org.junit.Assert.assertEquals; | |
13 | import static org.junit.Assert.assertNotNull; | |
14 | import static org.junit.Assert.assertNull; | |
312f397a GB |
15 | |
16 | import java.io.File; | |
17 | ||
312f397a | 18 | import org.eclipse.jdt.annotation.NonNull; |
6d16f5a9 | 19 | import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule; |
312f397a | 20 | import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelTidAspect; |
0783ea52 GB |
21 | import org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.LinuxTestCase; |
22 | import org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.kernel.KernelAnalysisTestFactory; | |
312f397a GB |
23 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; |
24 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; | |
312f397a GB |
25 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; |
26 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
27 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
28 | import org.eclipse.tracecompass.tmf.core.trace.TmfTrace; | |
29 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; | |
30 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; | |
312f397a GB |
31 | import org.junit.After; |
32 | import org.junit.Before; | |
33 | import org.junit.Test; | |
34 | ||
312f397a GB |
35 | /** |
36 | * Test the {@link KernelTidAspect} class | |
37 | * | |
38 | * @author Geneviève Bastien | |
39 | */ | |
40 | public class KernelTidAspectTest { | |
41 | ||
0783ea52 | 42 | private static final @NonNull LinuxTestCase KERNEL_TEST_CASE = KernelAnalysisTestFactory.KERNEL_SCHED; |
312f397a GB |
43 | |
44 | // ------------------------------------------------------------------------ | |
45 | // Test trace class definition | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
312f397a GB |
48 | private ITmfTrace fTrace; |
49 | ||
50 | private static void deleteSuppFiles(ITmfTrace trace) { | |
51 | /* Remove supplementary files */ | |
52 | File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace)); | |
53 | for (File file : suppDir.listFiles()) { | |
54 | file.delete(); | |
55 | } | |
56 | } | |
57 | ||
58 | /** | |
59 | * Test setup | |
60 | */ | |
61 | @Before | |
62 | public void setUp() { | |
0783ea52 | 63 | ITmfTrace trace = KERNEL_TEST_CASE.getKernelTrace(); |
1d83ed07 | 64 | deleteSuppFiles(trace); |
312f397a | 65 | /* Make sure the Kernel analysis has run */ |
1d83ed07 | 66 | ((TmfTrace) trace).traceOpened(new TmfTraceOpenedSignal(this, trace, null)); |
312f397a | 67 | IAnalysisModule module = null; |
6d16f5a9 | 68 | for (IAnalysisModule mod : TmfTraceUtils.getAnalysisModulesOfClass(trace, KernelAnalysisModule.class)) { |
312f397a GB |
69 | module = mod; |
70 | } | |
71 | assertNotNull(module); | |
72 | module.schedule(); | |
73 | module.waitForCompletion(); | |
1d83ed07 | 74 | fTrace = trace; |
312f397a GB |
75 | } |
76 | ||
77 | /** | |
78 | * Test clean up | |
79 | */ | |
80 | @After | |
81 | public void tearDown() { | |
82 | fTrace.dispose(); | |
83 | } | |
84 | ||
85 | private void resolveNextEvent(ITmfContext context, Integer tid) { | |
1d83ed07 AM |
86 | ITmfTrace trace = fTrace; |
87 | ITmfEvent event = trace.getNext(context); | |
312f397a GB |
88 | assertNotNull(event); |
89 | ||
1d83ed07 | 90 | Object tidObj = TmfTraceUtils.resolveEventAspectOfClassForEvent(trace, KernelTidAspect.class, event); |
312f397a GB |
91 | if (tid == null) { |
92 | assertNull(tidObj); | |
93 | } else { | |
94 | assertNotNull(tidObj); | |
95 | assertEquals(tid, tidObj); | |
96 | } | |
97 | } | |
98 | ||
99 | /** | |
100 | * Test the {@link KernelTidAspect#resolve(ITmfEvent)} method method | |
101 | */ | |
102 | @Test | |
103 | public void testResolveTidAspect() { | |
104 | ||
105 | ITmfContext context = fTrace.seekEvent(0L); | |
106 | resolveNextEvent(context, null); | |
107 | resolveNextEvent(context, null); | |
108 | resolveNextEvent(context, null); | |
109 | resolveNextEvent(context, 11); | |
110 | resolveNextEvent(context, null); | |
111 | resolveNextEvent(context, null); | |
112 | resolveNextEvent(context, 20); | |
113 | resolveNextEvent(context, 20); | |
114 | resolveNextEvent(context, 21); | |
115 | resolveNextEvent(context, 11); | |
116 | resolveNextEvent(context, 30); | |
117 | resolveNextEvent(context, 21); | |
118 | resolveNextEvent(context, 20); | |
119 | } | |
120 | ||
121 | } |