* @author Alexandre Montplaisir
*/
@NonNullByDefault
-public final class CtfTmfTestTraceUtils {
+public class CtfTmfTestTraceUtils {
private static final Map<CtfTestTrace, CtfTmfTrace> CTF_TMF_TRACES = new HashMap<>();
- private CtfTmfTestTraceUtils() {}
+ /**
+ * Constructor
+ */
+ protected CtfTmfTestTraceUtils() {}
/**
* Return a CtfTmfTraceStub object of this test trace. It will be already
* @return A CtfTmfTrace reference to this trace
*/
public static synchronized CtfTmfTrace getTrace(CtfTestTrace ctfTrace) {
+ return new CtfTmfTestTraceUtils().internalGetTrace(ctfTrace, CTF_TMF_TRACES, new CtfTmfTraceStub());
+ }
+
+ /**
+ * Return a CtfTmfTraceStub object of this test trace. It will be already
+ * initTrace()'ed.
+ *
+ * After being used by unit tests, traces should be properly disposed by
+ * calling the {@link #dispose(CtfTestTrace)} method.
+ *
+ * @param ctfTrace
+ * The test trace to initialize
+ * @param map
+ * the trace map
+ * @param trace
+ * the trace stub instance
+ * @return A CtfTmfTrace reference to this trace
+ */
+ protected synchronized CtfTmfTrace internalGetTrace(CtfTestTrace ctfTrace, Map<CtfTestTrace, CtfTmfTrace> map, CtfTmfTrace trace) {
String tracePath;
try {
tracePath = FileLocator.toFileURL(ctfTrace.getTraceURL()).getPath();
throw new IllegalStateException();
}
- dispose(ctfTrace);
- CtfTmfTrace trace = new CtfTmfTraceStub();
+ internalDispose(ctfTrace, map);
try {
trace.initTrace(null, tracePath, CtfTmfEvent.class);
} catch (TmfTraceException e) {
/* Should not happen if tracesExist() passed */
throw new RuntimeException(e);
}
- CTF_TMF_TRACES.put(ctfTrace, trace);
+ map.put(ctfTrace, trace);
return trace;
}
* Trace to dispose
*/
public static synchronized void dispose(CtfTestTrace ctfTrace) {
- CtfTmfTrace trace = CTF_TMF_TRACES.remove(ctfTrace);
+ new CtfTmfTestTraceUtils().internalDispose(ctfTrace, CTF_TMF_TRACES);
+ }
+
+ /**
+ * Dispose of the trace
+ *
+ * @param ctfTrace
+ * Trace to dispose
+ * @param map
+ * the trace map
+ */
+ protected synchronized void internalDispose(CtfTestTrace ctfTrace, Map<CtfTestTrace, CtfTmfTrace> map) {
+ CtfTmfTrace trace = map.remove(ctfTrace);
if (trace != null) {
trace.dispose();
}
/*******************************************************************************
- * Copyright (c) 2013, 2014 École Polytechnique de Montréal
+ * Copyright (c) 2013, 2016 École Polytechnique de Montréal and others
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.tracecompass.tmf.ctf.core.tests.stubs;
-import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
/**
- * Dummy test ctf trace
+ * Generic CTF trace stub
*/
-public class CtfTmfTraceStub extends CtfTmfTrace {
-
- /**
- * Simulate trace opening, to be called by tests who need an actively opened
- * trace
- */
- public void openTrace() {
- TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, this, null));
- selectTrace();
- }
-
- /**
- * Simulate selecting the trace
- */
- public void selectTrace() {
- TmfSignalManager.dispatchSignal(new TmfTraceSelectedSignal(this, this));
- }
-
+public class CtfTmfTraceStub extends CtfTmfTrace implements ITmfTraceStub {
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013, 2016 École Polytechnique de Montréal and others
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.stubs;
+
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+
+/**
+ * Interface for trace stubs
+ */
+public interface ITmfTraceStub extends ITmfTrace {
+
+ /**
+ * Simulate trace opening, to be called by tests who need an actively opened
+ * trace
+ */
+ default void openTrace() {
+ TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, this, null));
+ selectTrace();
+ }
+
+ /**
+ * Simulate selecting the trace
+ */
+ default void selectTrace() {
+ TmfSignalManager.dispatchSignal(new TmfTraceSelectedSignal(this, this));
+ }
+}
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="perf"/>
<classpathentry kind="src" path="shared"/>
+ <classpathentry kind="src" path="stubs"/>
<classpathentry kind="output" path="bin"/>
</classpath>
org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.analysis.syscall,
org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.analysis.tid,
org.eclipse.tracecompass.lttng2.kernel.core.tests.perf.event.matching,
+ org.eclipse.tracecompass.lttng2.kernel.core.tests.stubs,
org.eclipse.tracecompass.lttng2.lttng.kernel.core.tests.shared.vm
Import-Package: com.google.common.collect,
org.eclipse.test.performance,
###############################################################################
-# Copyright (c) 2013, 2015 Ericsson
+# Copyright (c) 2013, 2016 Ericsson
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
source.. = src/,\
perf/,\
- shared/
+ shared/,\
+ stubs/
output.. = bin/
bin.includes = META-INF/,\
.,\
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.lttng.kernel.core.tests.shared;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.tracecompass.lttng2.kernel.core.tests.stubs.LttngKernelTraceStub;
+import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * Wrapper for the LTTng Kernel test traces, instantiating
+ * {@link LttngKernelTrace} objects from them.
+ */
+@NonNullByDefault
+public final class LttngKernelTestTraceUtils extends CtfTmfTestTraceUtils {
+
+ private static final Map<CtfTestTrace, CtfTmfTrace> LTTNG_KERNEL_TRACES = new HashMap<>();
+
+ private LttngKernelTestTraceUtils() {
+ super();
+ }
+
+ /**
+ * Return a LttngKernelTraceStub object of this test trace. It will be
+ * already initTrace()'ed.
+ *
+ * After being used by unit tests, traces should be properly disposed by
+ * calling the {@link #dispose(CtfTestTrace)} method.
+ *
+ * @param ctfTrace
+ * The test trace to initialize
+ * @return A LttngKernelTrace reference to this trace
+ */
+ public static synchronized LttngKernelTrace getTrace(CtfTestTrace ctfTrace) {
+ return (LttngKernelTrace) new LttngKernelTestTraceUtils().internalGetTrace(ctfTrace, LTTNG_KERNEL_TRACES, new LttngKernelTraceStub());
+ }
+
+ /**
+ * Dispose of the trace
+ *
+ * @param ctfTrace
+ * Trace to dispose
+ */
+ public static synchronized void dispose(CtfTestTrace ctfTrace) {
+ new LttngKernelTestTraceUtils().internalDispose(ctfTrace, LTTNG_KERNEL_TRACES);
+ }
+}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelThreadInformationProvider;
-import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
+import org.eclipse.tracecompass.lttng2.lttng.kernel.core.tests.shared.LttngKernelTestTraceUtils;
import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
private static final @NonNull CtfTestTrace UST_TRACE = CtfTestTrace.CONTEXT_SWITCHES_UST;
private TmfExperiment fExperiment;
- private ITmfTrace fKernelTrace;
private ITmfTrace fUstTrace;
private KernelAnalysisModule fKernelModule;
@Before
public void setup() {
ITmfTrace ustTrace = CtfTmfTestTraceUtils.getTrace(UST_TRACE);
-
- /*
- * We need to initialize the kernel trace to the "LttngKernelTrace"
- * type ourselves, so the kernel analysis can run on it.
- */
- String kernelTracePath = CtfTmfTestTraceUtils.getTrace(KERNEL_TRACE).getPath();
- ITmfTrace kernelTrace = new LttngKernelTrace();
-
- try {
- kernelTrace.initTrace(null, kernelTracePath, CtfTmfEvent.class);
- } catch (TmfTraceException e) {
- fail(e.getMessage());
- }
+ ITmfTrace kernelTrace = LttngKernelTestTraceUtils.getTrace(KERNEL_TRACE);
TmfExperiment experiment = new TmfExperiment(CtfTmfEvent.class,
"test-exp",
null);
/* Simulate experiment being opened */
- // We have to "open" the sub-traces too, or their analyses are
- // never initialized. Is that on purpose?
- TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, ustTrace, null));
- TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, kernelTrace, null));
TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, experiment, null));
TmfSignalManager.dispatchSignal(new TmfTraceSelectedSignal(this, experiment));
module.waitForCompletion();
fExperiment = experiment;
- fKernelTrace = kernelTrace;
fUstTrace = ustTrace;
fKernelModule = module;
}
if (fExperiment != null) {
fExperiment.dispose();
}
- if (fKernelTrace != null) {
- fKernelTrace.dispose();
- }
-
- CtfTmfTestTraceUtils.dispose(KERNEL_TRACE);
CtfTmfTestTraceUtils.dispose(UST_TRACE);
+ LttngKernelTestTraceUtils.dispose(KERNEL_TRACE);
}
/**
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.kernel.core.tests.stubs;
+
+import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.stubs.ITmfTraceStub;
+
+/**
+ * LTTng Kernel trace stub
+ */
+public class LttngKernelTraceStub extends LttngKernelTrace implements ITmfTraceStub {
+}
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="shared"/>
+ <classpathentry kind="src" path="stubs"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Export-Package: org.eclipse.tracecompass.lttng2.ust.core.tests,
org.eclipse.tracecompass.lttng2.ust.core.tests.analysis.debuginfo,
org.eclipse.tracecompass.lttng2.ust.core.tests.analysis.memory,
- org.eclipse.tracecompass.lttng2.ust.core.tests.callstack
+ org.eclipse.tracecompass.lttng2.ust.core.tests.callstack,
+ org.eclipse.tracecompass.lttng2.ust.core.tests.shared,
+ org.eclipse.tracecompass.lttng2.ust.core.tests.stubs
Import-Package: com.google.common.collect,
org.eclipse.tracecompass.testtraces.ctf;version="1.0.0"
###############################################################################
-# Copyright (c) 2013, 2014 Ericsson
+# Copyright (c) 2013, 2016 Ericsson
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# Ericsson - Initial API and implementation
###############################################################################
-source.. = src/
+source.. = src/,\
+ stubs/,\
+ shared/
output.. = bin/
bin.includes = META-INF/,\
.,\
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.tests.shared;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.tracecompass.lttng2.ust.core.tests.stubs.LttngUstTraceStub;
+import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+
+/**
+ * Wrapper for the LTTng UST test traces, instantiating
+ * {@link LttngUstTrace} objects from them.
+ */
+@NonNullByDefault
+public final class LttngUstTestTraceUtils extends CtfTmfTestTraceUtils {
+
+ private static final Map<CtfTestTrace, CtfTmfTrace> LTTNG_UST_TRACES = new HashMap<>();
+
+ private LttngUstTestTraceUtils() {
+ super();
+ }
+
+ /**
+ * Return a LttngUstTraceStub object of this test trace. It will be
+ * already initTrace()'ed.
+ *
+ * After being used by unit tests, traces should be properly disposed by
+ * calling the {@link #dispose(CtfTestTrace)} method.
+ *
+ * @param ctfTrace
+ * The test trace to initialize
+ * @return A LttngUstTrace reference to this trace
+ */
+ public static synchronized LttngUstTrace getTrace(CtfTestTrace ctfTrace) {
+ return (LttngUstTrace) new LttngUstTestTraceUtils().internalGetTrace(ctfTrace, LTTNG_UST_TRACES, new LttngUstTraceStub());
+ }
+
+ /**
+ * Dispose of the trace
+ *
+ * @param ctfTrace
+ * Trace to dispose
+ */
+ public static synchronized void dispose(CtfTestTrace ctfTrace) {
+ new LttngUstTestTraceUtils().internalDispose(ctfTrace, LTTNG_UST_TRACES);
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.tests.stubs;
+
+import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.stubs.ITmfTraceStub;
+
+/**
+ * LTTng UST trace stub
+ */
+public class LttngUstTraceStub extends LttngUstTrace implements ITmfTraceStub {
+}