Commit | Line | Data |
---|---|---|
03722d5b GB |
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 | ||
aa353506 AM |
15 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
16 | ||
03722d5b GB |
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; | |
a6366b8b | 25 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
03722d5b GB |
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 | */ | |
a6366b8b | 63 | public synchronized TmfExperiment getExperiment(boolean deleteSuppFiles) { |
aa353506 | 64 | Set<@NonNull ITmfTrace> traces = new HashSet<>(); |
03722d5b | 65 | for (VmTraces trace : fTraces) { |
aa353506 AM |
66 | ITmfTrace tmfTrace = trace.getTrace(); |
67 | if (tmfTrace != null) { | |
68 | traces.add(tmfTrace); | |
69 | } | |
03722d5b | 70 | } |
aa353506 | 71 | String expName = checkNotNull(this.name()); |
03722d5b GB |
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 | } |