analysis: test System call analysis
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core.tests / src / org / eclipse / tracecompass / analysis / os / linux / core / tests / latency / SyscallAnalysisTest.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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
10 package org.eclipse.tracecompass.analysis.os.linux.core.tests.latency;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14
15 import java.io.IOException;
16
17 import org.eclipse.core.runtime.FileLocator;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCallLatencyAnalysis;
20 import org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.KernelEventLayoutStub;
21 import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
22 import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace;
23 import org.eclipse.tracecompass.segmentstore.core.ISegment;
24 import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
25 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
26 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
27 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
28 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
29 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
30 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
31 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
32 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
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 * Tests for the system call analysis
40 *
41 * @author Matthew Khouzam
42 */
43 public class SyscallAnalysisTest {
44
45 private static class KernelStubTrace extends CtfTmfTrace implements IKernelTrace {
46 public KernelStubTrace() {
47 super();
48 }
49
50 public static synchronized KernelStubTrace getTrace(CtfTestTrace ctfTrace) {
51 String tracePath;
52 try {
53 tracePath = FileLocator.toFileURL(ctfTrace.getTraceURL()).getPath();
54 } catch (IOException e) {
55 throw new IllegalStateException();
56 }
57
58 KernelStubTrace trace = new KernelStubTrace();
59 try {
60 trace.initTrace(null, tracePath, CtfTmfEvent.class);
61 } catch (TmfTraceException e) {
62 /* Should not happen if tracesExist() passed */
63 throw new RuntimeException(e);
64 }
65 return trace;
66 }
67
68 @Override
69 public @NonNull IKernelAnalysisEventLayout getKernelEventLayout() {
70 return KernelEventLayoutStub.getInstance();
71 }
72 }
73
74 private SystemCallLatencyAnalysis fSyscallModule;
75
76 /**
77 * Test setup
78 */
79 @Before
80 public void setUp() {
81 ITmfTrace trace = KernelStubTrace.getTrace(CtfTestTrace.ARM_64_BIT_HEADER);
82 /* Make sure the Kernel analysis has run */
83 ((TmfTrace) trace).traceOpened(new TmfTraceOpenedSignal(this, trace, null));
84 for (IAnalysisModule mod : TmfTraceUtils.getAnalysisModulesOfClass(trace, SystemCallLatencyAnalysis.class)) {
85 fSyscallModule = (SystemCallLatencyAnalysis) mod;
86 }
87 assertNotNull(fSyscallModule);
88 fSyscallModule.schedule();
89 fSyscallModule.waitForCompletion();
90 }
91
92 /**
93 * Dispose everything
94 */
95 @After
96 public void cleanup() {
97 final SystemCallLatencyAnalysis syscallModule = fSyscallModule;
98 if( syscallModule != null) {
99 syscallModule.dispose();
100 }
101 }
102
103 /**
104 * This will load the analysis and test it. as it depends on Kernel, this
105 * test runs the kernel trace first then the analysis
106 */
107 @Test
108 public void testSmallTraceSequential() {
109 final SystemCallLatencyAnalysis syscallModule = fSyscallModule;
110 assertNotNull(syscallModule);
111 ISegmentStore<@NonNull ISegment> segmentStore = syscallModule.getSegmentStore();
112 assertNotNull(segmentStore);
113 assertEquals(1801, segmentStore.size());
114 }
115 }
This page took 0.033473 seconds and 5 git commands to generate.