b7404783ab0030fc17359e420af8875d407d5824
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / shared / org / eclipse / linuxtools / tmf / core / tests / shared / CtfTmfTestTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.tests.shared;
14
15 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
16 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
17 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
18 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
19 import org.eclipse.linuxtools.tmf.tests.stubs.ctf.CtfTmfTraceStub;
20
21 /**
22 * Available CTF TMF test traces. Kind-of-extends {@link CtfTestTrace}.
23 *
24 * To run tests using these, you first need to run the "get-traces.[xml|sh]"
25 * script located under lttng/org.eclipse.linuxtools.ctf.core.tests/traces/ .
26 *
27 * @author Alexandre Montplaisir
28 */
29 public enum CtfTmfTestTrace {
30 /** Example kernel trace */
31 KERNEL,
32 /** Another kernel trace */
33 TRACE2,
34 /** Kernel trace with event contexts */
35 KERNEL_VM,
36 /** Trace synchronization: source trace */
37 SYNC_SRC,
38 /** Trace synchronization: destination trace */
39 SYNC_DEST,
40 /** UST trace with lots of lost events */
41 HELLO_LOST,
42 /** UST trace with lttng-ust-cyg-profile events (aka -finstrument-functions) */
43 CYG_PROFILE,
44 /** UST trace with lttng-ust-cyg-profile-fast events (no address in func_exit) */
45 CYG_PROFILE_FAST,
46 /** Autogenerated Syntetic trace */
47 SYNTHETIC_TRACE,
48 /** Trace with non-standard field sizes */
49 FUNKY_TRACE;
50
51
52 private final String fPath;
53 private CtfTmfTraceStub fTrace = null;
54
55 private CtfTmfTestTrace() {
56 /* This makes my head spin */
57 fPath = CtfTestTrace.valueOf(this.name()).getPath();
58 }
59
60 /**
61 * @return The path of this trace
62 */
63 public String getPath() {
64 return fPath;
65 }
66
67 /**
68 * Return a CtfTmfTraceStub object of this test trace. It will be already
69 * initTrace()'ed.
70 *
71 * Make sure you call {@link #exists()} before calling this!
72 *
73 * After being used by unit tests, traces must be properly disposed of by
74 * calling the {@link CtfTmfTestTrace#dispose()} method.
75 *
76 * @return A CtfTmfTrace reference to this trace
77 */
78 public synchronized CtfTmfTrace getTrace() {
79 if (fTrace != null) {
80 fTrace.dispose();
81 }
82 fTrace = new CtfTmfTraceStub();
83 try {
84 fTrace.initTrace(null, fPath, CtfTmfEvent.class);
85 } catch (TmfTraceException e) {
86 /* Should not happen if tracesExist() passed */
87 throw new RuntimeException(e);
88 }
89 return fTrace;
90 }
91
92 /**
93 * Check if the trace actually exists on disk or not.
94 *
95 * @return If the trace is present
96 */
97 public boolean exists() {
98 return CtfTestTrace.valueOf(this.name()).exists();
99 }
100
101 /**
102 * Dispose of the trace
103 */
104 public void dispose() {
105 if (fTrace != null) {
106 fTrace.dispose();
107 fTrace = null;
108 }
109 }
110 }
This page took 0.034754 seconds and 4 git commands to generate.