Fix references to linuxtools in comments, examples and unused code
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.pcap.core.tests / shared / org / eclipse / tracecompass / tmf / pcap / core / tests / shared / PcapTmfTestTrace.java
CommitLineData
527c3a79 1/*******************************************************************************
2c7fb5af 2 * Copyright (c) 2014, 2015 Ericsson
527c3a79
VP
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 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
12
2bdf0193 13package org.eclipse.tracecompass.tmf.pcap.core.tests.shared;
527c3a79
VP
14
15import org.eclipse.jdt.annotation.NonNull;
16import org.eclipse.jdt.annotation.NonNullByDefault;
17import org.eclipse.jdt.annotation.Nullable;
2bdf0193
AM
18import org.eclipse.tracecompass.internal.tmf.pcap.core.event.PcapEvent;
19import org.eclipse.tracecompass.internal.tmf.pcap.core.trace.PcapTrace;
71f2817f 20import org.eclipse.tracecompass.pcap.core.tests.shared.PcapTestTrace;
2bdf0193
AM
21import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
22import org.eclipse.tracecompass.tmf.pcap.core.tests.stubs.PcapTmfTraceStub;
527c3a79
VP
23
24/**
25 * Available Pcap TMF test traces. Kind-of-extends {@link PcapTestTrace}.
26 *
27 * To run tests using these, you first need to run the "get-traces.[xml|sh]"
2c7fb5af 28 * script located under org.eclipse.tracecompass.pcap.core.tests/rsc/ .
527c3a79
VP
29 *
30 * @author Vincent Perot
31 */
32@NonNullByDefault
33public enum PcapTmfTestTrace {
34 /** A bad pcap file. */
35 BAD_PCAPFILE,
36
37 /** A Valid Pcap that is empty. */
38 EMPTY_PCAP,
39
40 /** A Pcap that mostly contains TCP packets. */
41 MOSTLY_TCP,
42
43 /** A Pcap that mostly contains UDP packets. */
44 MOSTLY_UDP,
45
46 /** A big-endian trace that contains two packets. */
47 SHORT_BIG_ENDIAN,
48
49 /** A little-endian trace that contains two packets. */
50 SHORT_LITTLE_ENDIAN,
51
52 /** A trace used for benchmarking. */
53 BENCHMARK_TRACE,
54
55 /** A Kernel trace directory. */
56 KERNEL_DIRECTORY,
57
58 /** A Kernel trace file. */
59 KERNEL_TRACE;
60
61 private final String fPath;
62 private @Nullable PcapTmfTraceStub fTrace = null;
63
64 private PcapTmfTestTrace() {
333a2acb
AM
65 @SuppressWarnings("null")
66 @NonNull String path = PcapTestTrace.valueOf(this.name()).getPath().toString();
527c3a79
VP
67 fPath = path;
68 }
69
70 /**
71 * @return The path of this trace
72 */
73 public String getPath() {
74 return fPath;
75 }
76
77 /**
78 * Return a PcapTmfTraceStub object of this test trace. It will be already
79 * initTrace()'ed.
80 *
81 * Make sure you call {@link #exists()} before calling this!
82 *
83 * After being used by unit tests, traces must be properly disposed of by
84 * calling the {@link PcapTmfTestTrace#dispose()} method.
85 *
86 * @return A PcapTmfTrace reference to this trace
87 */
88 public synchronized PcapTrace getTrace() {
89 PcapTmfTraceStub trace = fTrace;
90 if (trace != null) {
91 trace.dispose();
92 }
93 trace = new PcapTmfTraceStub();
94 try {
95 trace.initTrace(null, fPath, PcapEvent.class);
96 } catch (TmfTraceException e) {
97 /* Should not happen if tracesExist() passed */
98 throw new RuntimeException(e);
99 }
100 fTrace = trace;
101 return trace;
102 }
103
104 /**
105 * Check if the trace actually exists on disk or not.
106 *
107 * @return If the trace is present
108 */
109 public boolean exists() {
110 return PcapTestTrace.valueOf(this.name()).exists();
111 }
112
113 /**
114 * Dispose of the trace
115 */
116 public void dispose() {
117 if (fTrace != null) {
118 fTrace.dispose();
119 fTrace = null;
120 }
121 }
122}
This page took 0.04453 seconds and 5 git commands to generate.