ctf: Add advanced trace tests
[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
20 /**
21 * Available CTF TMF test traces. Kind-of-extends {@link CtfTestTrace}.
22 *
23 * To run tests using these, you first need to run the "get-traces.[xml|sh]"
24 * script located under lttng/org.eclipse.linuxtools.ctf.core.tests/traces/ .
25 *
26 * @author Alexandre Montplaisir
27 */
28 public enum CtfTmfTestTrace {
29 /** Example kernel trace */
30 KERNEL,
31 /** Another kernel trace */
32 TRACE2,
33 /** Kernel trace with event contexts */
34 KERNEL_VM,
35 /** UST trace with lots of lost events */
36 HELLO_LOST,
37 /** Autogenerated Syntetic trace */
38 SYNTHETIC_TRACE,
39 /** Trace with non-standard field sizes */
40 FUNKY_TRACE;
41
42
43 private final String fPath;
44 private CtfTmfTrace fTrace = null;
45
46 private CtfTmfTestTrace() {
47 /* This makes my head spin */
48 fPath = CtfTestTrace.valueOf(this.name()).getPath();
49 }
50
51 /**
52 * @return The path of this trace
53 */
54 public String getPath() {
55 return fPath;
56 }
57
58 /**
59 * Return a CtfTmfTrace object of this test trace. It will be already
60 * initTrace()'ed. You do not have to .dispose() the trace after use (the
61 * old one is disposed automatically when this method is called again).
62 *
63 * Make sure you call {@link #exists()} before calling this!
64 *
65 * @return A CtfTmfTrace reference to this trace
66 */
67 public synchronized CtfTmfTrace getTrace() {
68 if (fTrace != null) {
69 fTrace.dispose();
70 }
71 fTrace = new CtfTmfTrace();
72 try {
73 fTrace.initTrace(null, fPath, CtfTmfEvent.class);
74 } catch (TmfTraceException e) {
75 /* Should not happen if tracesExist() passed */
76 throw new RuntimeException(e);
77 }
78 return fTrace;
79 }
80
81 /**
82 * Check if the trace actually exists on disk or not.
83 *
84 * @return If the trace is present
85 */
86 public boolean exists() {
87 return CtfTestTrace.valueOf(this.name()).exists();
88 }
89 }
This page took 0.031813 seconds and 5 git commands to generate.