lttng: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / shared / org / eclipse / tracecompass / lttng2 / lttng / kernel / core / tests / shared / vm / VmTraces.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.io.IOException;
17 import java.net.URL;
18
19 import org.eclipse.core.runtime.FileLocator;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Path;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.tracecompass.lttng2.kernel.core.tests.Activator;
25 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
26 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
27 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
28 import org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub;
29
30 /**
31 * List the available virtual machine host and guest traces
32 *
33 * @author Geneviève Bastien
34 */
35 public enum VmTraces {
36
37 /** Host from simple QEMU/KVM experiment */
38 HOST_ONE_QEMUKVM("vm/OneQemuKvm/host.xml"),
39 /** Guest from simple QEMU/KVM experiment */
40 GUEST_ONE_QEMUKVM("vm/OneQemuKvm/guest.xml");
41
42 private static final @NonNull String filePath = "testfiles";
43
44 private final IPath fPath;
45
46 VmTraces(String path) {
47 IPath relativePath = new Path(filePath + File.separator + path);
48 Activator plugin = Activator.getDefault();
49 if (plugin == null) {
50 /*
51 * Shouldn't happen but at least throw something to get the test to
52 * fail early
53 */
54 throw new IllegalStateException();
55 }
56 URL location = FileLocator.find(plugin.getBundle(), relativePath, null);
57 try {
58 fPath = new Path(FileLocator.toFileURL(location).getPath());
59 } catch (IOException e) {
60 throw new IllegalStateException();
61 }
62 }
63
64 /**
65 * Return a TmfXmlTraceStub object of this test trace. It will be already
66 * initTrace()'ed.
67 *
68 * Make sure you call {@link #exists()} before calling this!
69 *
70 * @return A TmfXmlTraceStub reference to this trace
71 */
72 public ITmfTrace getTrace() {
73 ITmfTrace trace = new TmfXmlTraceStub();
74 IStatus status = trace.validate(null, fPath.toOSString());
75 if (!status.isOK()) {
76 return null;
77 }
78 try {
79 trace.initTrace(null, fPath.toOSString(), TmfEvent.class);
80 } catch (TmfTraceException e) {
81 return null;
82 }
83 return trace;
84 }
85
86 /**
87 * Check if the trace actually exists on disk or not.
88 *
89 * @return If the trace is present
90 */
91 public boolean exists() {
92 return fPath.toFile().exists();
93 }
94 }
This page took 0.041982 seconds and 5 git commands to generate.