1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson, EfficiOS Inc. and others
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
;
12 import java
.io
.IOException
;
13 import java
.util
.HashMap
;
16 import org
.eclipse
.core
.runtime
.FileLocator
;
17 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
18 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.LttngKernelTraceGenerator
;
19 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
21 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
22 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.stubs
.CtfTmfTraceStub
;
23 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
26 * Wrapper for the CTF test traces, instantiating {@link CtfTmfTrace} objects
29 * @author Alexandre Montplaisir
32 public final class CtfTmfTestTraceUtils
{
34 private static final Map
<CtfTestTrace
, CtfTmfTrace
> CTF_TMF_TRACES
= new HashMap
<>();
36 private CtfTmfTestTraceUtils() {}
39 * Return a CtfTmfTraceStub object of this test trace. It will be already
42 * After being used by unit tests, traces should be properly disposed by
43 * calling the {@link #dispose(CtfTestTrace)} method.
46 * The test trace to initialize
47 * @return A CtfTmfTrace reference to this trace
49 public static synchronized CtfTmfTrace
getTrace(CtfTestTrace ctfTrace
) {
52 tracePath
= FileLocator
.toFileURL(ctfTrace
.getTraceURL()).getPath();
53 } catch (IOException e
) {
54 throw new IllegalStateException();
58 CtfTmfTrace trace
= new CtfTmfTraceStub();
60 trace
.initTrace(null, tracePath
, CtfTmfEvent
.class);
61 } catch (TmfTraceException e
) {
62 /* Should not happen if tracesExist() passed */
63 throw new RuntimeException(e
);
65 CTF_TMF_TRACES
.put(ctfTrace
, trace
);
70 * Dispose of the trace
75 public static synchronized void dispose(CtfTestTrace ctfTrace
) {
76 CtfTmfTrace trace
= CTF_TMF_TRACES
.remove(ctfTrace
);
83 * Get an initialized version of the synthetic trace.
85 * @return A reference to the synthetic trace
87 public static CtfTmfTrace
getSyntheticTrace() {
88 CtfTmfTrace trace
= new CtfTmfTrace();
90 trace
.initTrace(null, LttngKernelTraceGenerator
.getPath(), CtfTmfEvent
.class);
91 } catch (TmfTraceException e
) {
92 throw new IllegalStateException();