1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.tests
.inputoutput
;
12 import static org
.junit
.Assert
.assertNotNull
;
13 import static org
.junit
.Assert
.fail
;
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
;
37 * Abstract for InputOuput test classes with utility methods to setup and tear
40 * @author Geneviève Bastien
42 public class AbstractTestInputOutput
{
44 private static final String IO_FILE_PATH
= "testfiles/io_analysis/";
46 private static class IOKernelEventLayout
extends KernelEventLayoutStub
{
48 public @NonNull String
eventBlockRqMerge() {
49 return "addons_elv_merge_requests";
53 public @Nullable String
eventStatedumpBlockDevice() {
54 return "statedump_block_device";
58 public @NonNull String
eventSyscallEntryPrefix() {
59 return "syscall_entry";
63 public @NonNull String
eventCompatSyscallEntryPrefix() {
64 return "syscall_compat_entry";
68 public @NonNull String
eventSyscallExitPrefix() {
69 return "syscall_exit";
73 public @NonNull String
eventCompatSyscallExitPrefix() {
74 return "syscall_compat_exit";
78 private static final @NonNull IKernelAnalysisEventLayout EVENT_LAYOUT
= new IOKernelEventLayout();
80 private ITmfTrace fTrace
;
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()) {
93 public AbstractTestInputOutput() {
100 protected void deleteTrace() {
101 ITmfTrace trace
= fTrace
;
103 deleteSuppFiles(fTrace
);
109 * Setup the trace for the tests and return the InputOutputAnalysisModule,
113 * The file name of the trace to open
114 * @return The input output analysis module
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());
126 trace
.initTrace(null, filePath
.toOSString(), TmfEvent
.class);
127 } catch (TmfTraceException e
) {
128 fail(e
.getMessage());
131 deleteSuppFiles(trace
);
132 ((TmfTrace
) trace
).traceOpened(new TmfTraceOpenedSignal(this, trace
, null));
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();
141 InputOutputAnalysisModule module
= TmfTraceUtils
.getAnalysisModuleOfClass(trace
, InputOutputAnalysisModule
.class, InputOutputAnalysisModule
.ID
);
142 assertNotNull(module
);