analysis.io: Unit tests for the I/O analysis
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core.tests / src / org / eclipse / tracecompass / analysis / os / linux / core / tests / inputoutput / AbstractTestInputOutput.java
1 /*******************************************************************************
2 * Copyright (c) 2016 É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
10 package org.eclipse.tracecompass.analysis.os.linux.core.tests.inputoutput;
11
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.fail;
14
15 import java.io.File;
16
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.tracecompass.analysis.os.linux.core.inputoutput.InputOutputAnalysisModule;
22 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
23 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelTidAspect;
24 import org.eclipse.tracecompass.analysis.os.linux.core.tests.Activator;
25 import org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.KernelEventLayoutStub;
26 import org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace.TmfXmlKernelTraceStub;
27 import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
28 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
29 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
30 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
31 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
32 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
33 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
34 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
35
36 /**
37 * Abstract for InputOuput test classes with utility methods to setup and tear
38 * down the tests
39 *
40 * @author Geneviève Bastien
41 */
42 public class AbstractTestInputOutput {
43
44 private static final String IO_FILE_PATH = "testfiles/io_analysis/";
45
46 private static class IOKernelEventLayout extends KernelEventLayoutStub {
47 @Override
48 public @NonNull String eventBlockRqMerge() {
49 return "addons_elv_merge_requests";
50 }
51
52 @Override
53 public @Nullable String eventStatedumpBlockDevice() {
54 return "statedump_block_device";
55 }
56
57 @Override
58 public @NonNull String eventSyscallEntryPrefix() {
59 return "syscall_entry";
60 }
61
62 @Override
63 public @NonNull String eventCompatSyscallEntryPrefix() {
64 return "syscall_compat_entry";
65 }
66
67 @Override
68 public @NonNull String eventSyscallExitPrefix() {
69 return "syscall_exit";
70 }
71
72 @Override
73 public @NonNull String eventCompatSyscallExitPrefix() {
74 return "syscall_compat_exit";
75 }
76 }
77
78 private static final @NonNull IKernelAnalysisEventLayout EVENT_LAYOUT = new IOKernelEventLayout();
79
80 private ITmfTrace fTrace;
81
82 private static void deleteSuppFiles(ITmfTrace trace) {
83 /* Remove supplementary files */
84 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
85 for (File file : suppDir.listFiles()) {
86 file.delete();
87 }
88 }
89
90 /**
91 * Constructor
92 */
93 public AbstractTestInputOutput() {
94
95 }
96
97 /**
98 * Clean up
99 */
100 protected void deleteTrace() {
101 ITmfTrace trace = fTrace;
102 if (trace != null) {
103 deleteSuppFiles(fTrace);
104 fTrace.dispose();
105 }
106 }
107
108 /**
109 * Setup the trace for the tests and return the InputOutputAnalysisModule,
110 * not executed.
111 *
112 * @param fileName
113 * The file name of the trace to open
114 * @return The input output analysis module
115 */
116 protected @NonNull InputOutputAnalysisModule setUp(String fileName) {
117 TmfXmlKernelTraceStub trace = new TmfXmlKernelTraceStub();
118 trace.addEventAspect(KernelTidAspect.INSTANCE);
119 trace.setKernelEventLayout(EVENT_LAYOUT);
120 IPath filePath = Activator.getAbsoluteFilePath(IO_FILE_PATH + fileName);
121 IStatus status = trace.validate(null, filePath.toOSString());
122 if (!status.isOK()) {
123 fail(status.getException().getMessage());
124 }
125 try {
126 trace.initTrace(null, filePath.toOSString(), TmfEvent.class);
127 } catch (TmfTraceException e) {
128 fail(e.getMessage());
129 }
130
131 deleteSuppFiles(trace);
132 ((TmfTrace) trace).traceOpened(new TmfTraceOpenedSignal(this, trace, null));
133 fTrace = trace;
134
135 /* Start the kernel analysis module */
136 KernelAnalysisModule kernelMod = TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID);
137 assertNotNull(kernelMod);
138 kernelMod.schedule();
139 kernelMod.waitForCompletion();
140
141 InputOutputAnalysisModule module = TmfTraceUtils.getAnalysisModuleOfClass(trace, InputOutputAnalysisModule.class, InputOutputAnalysisModule.ID);
142 assertNotNull(module);
143 return module;
144 }
145 }
This page took 0.041185 seconds and 5 git commands to generate.