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