8fe186971cf5629f098a52dd254499677f4027ff
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / shared / org / eclipse / tracecompass / lttng2 / lttng / kernel / core / tests / shared / vm / VmTestExperiment.java
1 /*******************************************************************************
2 * Copyright (c) 2014 É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.lttng.kernel.core.tests.shared.vm;
14
15 import java.io.File;
16 import java.util.HashSet;
17 import java.util.Set;
18
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.vm.trace.VirtualMachineExperiment;
21 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
23 import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
24
25 /**
26 * List virtual machine experiments that can be used in unit tests
27 *
28 * @author Geneviève Bastien
29 */
30 public enum VmTestExperiment {
31
32 /**
33 * Virtual machine experiment: 1 guest, 1 host, using QEMU/KVM model
34 */
35 ONE_QEMUKVM(VmTraces.HOST_ONE_QEMUKVM, VmTraces.GUEST_ONE_QEMUKVM);
36
37 private Set<VmTraces> fTraces = new HashSet<>();
38
39 private VmTestExperiment(VmTraces... traces) {
40 for (VmTraces trace : traces) {
41 fTraces.add(trace);
42 }
43 }
44
45 /**
46 * Return a VirtualMachineExperiment object for this experiment with all its
47 * traces. It will be already initTrace()'ed.
48 *
49 * Make sure you call {@link #exists()} before calling this! This will make
50 * sure all traces in the experiment are available
51 *
52 * After being used by unit tests, the experiment must be properly disposed
53 * of by calling the {@link VirtualMachineExperiment#dispose()} method on
54 * the object returned by this method.
55 *
56 * @param deleteSuppFiles
57 * Indicate whether to make sure supplementary files are deleted
58 * @return A VirtualMachineExperiment object corresponding to this
59 * experiment
60 */
61 public synchronized TmfExperiment getExperiment(boolean deleteSuppFiles) {
62 Set<ITmfTrace> traces = new HashSet<>();
63 for (VmTraces trace : fTraces) {
64 traces.add(trace.getTrace());
65 }
66 @SuppressWarnings("null")
67 @NonNull String expName = this.name();
68 VirtualMachineExperiment experiment = new VirtualMachineExperiment(expName, traces);
69 if (deleteSuppFiles) {
70 /*
71 * Delete the supplementary files, so that the next iteration
72 * rebuilds the state system.
73 */
74 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(experiment));
75 for (File file : suppDir.listFiles()) {
76 file.delete();
77 }
78 }
79 return experiment;
80 }
81
82 /**
83 * Check if all the traces actually exist on disk or not.
84 *
85 * @return If all traces for this experiment are present
86 */
87 public boolean exists() {
88 boolean exists = true;
89 for (VmTraces trace : fTraces) {
90 exists &= trace.exists();
91 }
92 return exists;
93 }
94
95 }
This page took 0.035074 seconds and 4 git commands to generate.