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 | ||
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; | |
a6366b8b | 23 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
03722d5b GB |
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 | */ | |
a6366b8b | 61 | public synchronized TmfExperiment getExperiment(boolean deleteSuppFiles) { |
aa353506 | 62 | Set<@NonNull ITmfTrace> traces = new HashSet<>(); |
03722d5b | 63 | for (VmTraces trace : fTraces) { |
aa353506 AM |
64 | ITmfTrace tmfTrace = trace.getTrace(); |
65 | if (tmfTrace != null) { | |
66 | traces.add(tmfTrace); | |
67 | } | |
03722d5b | 68 | } |
0e4f957e | 69 | String expName = name(); |
03722d5b GB |
70 | VirtualMachineExperiment experiment = new VirtualMachineExperiment(expName, traces); |
71 | if (deleteSuppFiles) { | |
72 | /* | |
73 | * Delete the supplementary files, so that the next iteration | |
74 | * rebuilds the state system. | |
75 | */ | |
76 | File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(experiment)); | |
77 | for (File file : suppDir.listFiles()) { | |
78 | file.delete(); | |
79 | } | |
80 | } | |
81 | return experiment; | |
82 | } | |
83 | ||
84 | /** | |
85 | * Check if all the traces actually exist on disk or not. | |
86 | * | |
87 | * @return If all traces for this experiment are present | |
88 | */ | |
89 | public boolean exists() { | |
90 | boolean exists = true; | |
91 | for (VmTraces trace : fTraces) { | |
92 | exists &= trace.exists(); | |
93 | } | |
94 | return exists; | |
95 | } | |
96 | ||
97 | } |