Tmf: Trace synchronization using network events
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / shared / org / eclipse / linuxtools / ctf / core / tests / shared / CtfTestTraces.java
CommitLineData
4bd7f2db
AM
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Alexandre Montplaisir - Initial API and implementation
10 *******************************************************************************/
11
32bf80d2 12package org.eclipse.linuxtools.ctf.core.tests.shared;
866e5b51
FC
13
14import java.io.File;
15
16import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
17import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
18
19/**
20 * Here are the definitions common to all the CTF parser tests.
ce2388e0 21 *
866e5b51 22 * @author alexmont
866e5b51 23 */
32bf80d2 24public abstract class CtfTestTraces {
ce2388e0 25
813ecc8e
AM
26 /*
27 * Path to test traces. Make sure you run the traces/get-traces.sh script
28 * first!
29 */
32bf80d2
AM
30 private static final String[] testTracePaths = {
31 "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel",
9824473b 32 "../org.eclipse.linuxtools.ctf.core.tests/traces/trace2",
e73a4ba5
GB
33 "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel_vm",
34 "../org.eclipse.linuxtools.ctf.core.tests/traces/synctraces/scp_src",
35 "../org.eclipse.linuxtools.ctf.core.tests/traces/synctraces/scp_dest"
32bf80d2
AM
36 };
37
38 private static CTFTrace[] testTraces = new CTFTrace[testTracePaths.length];
39 private static CTFTrace[] testTracesFromFile = new CTFTrace[testTracePaths.length];
40
41 private static final File testTraceFile1 = new File(testTracePaths[0] + "/channel0_0");
ce2388e0 42
e5acb357 43 private static final File emptyFile = new File("");
866e5b51 44 private static CTFTrace emptyTrace = null;
ce2388e0 45
e5acb357
AM
46 /**
47 * Return an empty file (new File("");)
48 *
49 * @return An empty file
50 */
866e5b51
FC
51 public static File getEmptyFile() {
52 return emptyFile;
53 }
ce2388e0 54
e5acb357
AM
55 /**
56 * Return a file in test trace #1 (channel0_0).
57 *
58 * Make sure {@link #tracesExist()} before calling this!
59 *
60 * @return A file in a test trace
61 */
024373d7
MK
62 public static File getTraceFile(){
63 return testTraceFile1;
64 }
e5acb357
AM
65
66 /**
67 * Return a trace out of an empty file (new CTFTrace("");)
68 *
69 * @return An empty trace
70 */
866e5b51
FC
71 public static CTFTrace getEmptyTrace() {
72 if (emptyTrace == null) {
73 try {
e5acb357 74 emptyTrace = new CTFTrace("");
866e5b51 75 } catch (CTFReaderException e) {
e5acb357 76 /* Should always work... */
866e5b51 77 throw new RuntimeException(e);
ce2388e0 78 }
866e5b51
FC
79 }
80 return emptyTrace;
81 }
ce2388e0 82
e5acb357 83 /**
32bf80d2 84 * Get a CTFTrace reference to the given test trace.
e5acb357
AM
85 *
86 * Make sure {@link #tracesExist()} before calling this!
87 *
32bf80d2
AM
88 * @param idx
89 * The index of the trace among all the available ones
e5acb357
AM
90 * @return Reference to test trace #1
91 * @throws CTFReaderException
92 * If the trace cannot be found
93 */
32bf80d2
AM
94 public static CTFTrace getTestTrace(int idx) throws CTFReaderException {
95 if (testTraces[idx] == null) {
96 testTraces[idx] = new CTFTrace(testTracePaths[idx]);
866e5b51 97 }
32bf80d2 98 return testTraces[idx];
866e5b51
FC
99 }
100
e5acb357 101 /**
32bf80d2
AM
102 * Get the (string) path to a given test trace.
103 *
104 * You should call {@link #tracesExist()} before calling this if you are
105 * going to use this trace for real.
106 *
107 * @param idx
108 * The index of the trace among all the available ones
109 * @return The path to the test trace
110 */
111 public static String getTestTracePath(int idx) {
112 return testTracePaths[idx];
113 }
114
115 /**
116 * Same as {@link #getTestTrace}, except the CTFTrace is create from the
e5acb357
AM
117 * File object and not the path.
118 *
119 * Make sure {@link #tracesExist()} before calling this!
120 *
32bf80d2
AM
121 * @param idx
122 * The index of the trace among all the available ones
e5acb357
AM
123 * @return Reference to test trace #1
124 */
32bf80d2
AM
125 public static CTFTrace getTestTraceFromFile(int idx) {
126 if (testTracesFromFile[idx] == null) {
866e5b51 127 try {
32bf80d2 128 testTracesFromFile[idx] = new CTFTrace(new File(testTracePaths[idx]));
866e5b51 129 } catch (CTFReaderException e) {
e5acb357 130 /* This trace should exist */
866e5b51
FC
131 throw new RuntimeException(e);
132 }
133 }
32bf80d2 134 return testTracesFromFile[idx];
866e5b51 135 }
e5acb357
AM
136
137 /**
138 * Check if the test traces are present in the tree. If not, you can get
139 * them by running traces/get-traces.sh or traces/get-traces.xml
140 *
141 * @return True if *all* the test files could be found, false otherwise.
142 */
143 public static boolean tracesExist() {
32bf80d2
AM
144 for (int i = 0; i < testTracePaths.length; i++) {
145 if (!traceExists(i)) {
146 return false;
147 }
148 }
149 return true;
150 }
151
152 private static boolean traceExists(int idx) {
153 if (testTraces[idx] != null) {
e5acb357
AM
154 return true;
155 }
156 try {
32bf80d2 157 getTestTrace(idx);
e5acb357
AM
158 } catch (CTFReaderException e) {
159 return false;
160 }
161 return true;
162 }
866e5b51 163}
This page took 0.040551 seconds and 5 git commands to generate.