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