And skip them if the traces are not available.
Also added a new exported test file manager, so that other
plugin tests (like the lttng2 ones) can re-use it.
Change-Id: I71cffad8f68089f3e88582e436a74bb2ec57c897
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/10354
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>
Tested-by: Bernd Hufmann <bhufmann@gmail.com>
Tested-by: Hudson CI
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="stubs"/>
+ <classpathentry kind="src" path="shared"/>
<classpathentry kind="output" path="bin"/>
</classpath>
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.linuxtools.tmf.core;bundle-version="2.0.0",
- org.eclipse.linuxtools.ctf.core;bundle-version="1.0.0"
-Export-Package: org.eclipse.linuxtools.tmf.tests.stubs.trace;x-friends:="org.eclipse.linuxtools.tmf.ui.tests"
+ org.eclipse.linuxtools.ctf.core;bundle-version="1.0.0",
+ org.eclipse.linuxtools.ctf.core.tests;bundle-version="1.0.0"
+Export-Package: org.eclipse.linuxtools.tmf.core.tests.shared,
+ org.eclipse.linuxtools.tmf.tests.stubs.trace;x-friends:="org.eclipse.linuxtools.tmf.ui.tests"
source.. = stubs/,\
+ shared/,\
src/
output.. = bin/
bin.includes = META-INF/,\
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.shared;
+
+import java.io.File;
+
+import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTraces;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+
+/**
+ * Definitions used by all tests using CTF-TMF trace files.
+ *
+ * To run these tests, you will first need to run the "get-traces.sh" script
+ * located under lttng/org.eclipse.linuxtools.ctf.core.tests/traces/ .
+ *
+ * @author Alexandre Montplaisir
+ */
+public final class CtfTmfTestTraces {
+
+ private CtfTmfTestTraces() {}
+
+ private static final File emptyFile = new File(""); //$NON-NLS-1$
+ private static CtfTmfTrace emptyTrace = new CtfTmfTrace();
+
+ private static CtfTmfTrace[] testTraces = new CtfTmfTrace[2];
+
+ /**
+ * Get an empty File (new File("");)
+ *
+ * @return An empty file
+ */
+ public static File getEmptyFile() {
+ return emptyFile;
+ }
+
+ /**
+ * Get an empty CtfTmfTrace (new CtfTmfTrace();)
+ *
+ * @return An empty trace
+ */
+ public static CtfTmfTrace getEmptyTrace() {
+ return emptyTrace;
+ }
+
+ /**
+ * Get a reference to the test trace used for the kernel event handler unit
+ * tests.
+ *
+ * Make sure you call {@link #tracesExist()} before calling this!
+ *
+ * @param idx
+ * The index of the test trace you want
+ * @return A CtfTmfTrace reference to the test trace
+ */
+ public synchronized static CtfTmfTrace getTestTrace(int idx) {
+ if (testTraces[idx] == null) {
+ String tracePath = CtfTestTraces.getTestTracePath(idx);
+ testTraces[idx] = new CtfTmfTrace();
+ try {
+ testTraces[idx].initTrace(null, tracePath, CtfTmfEvent.class);
+ } catch (TmfTraceException e) {
+ /* Should not happen if tracesExist() passed */
+ testTraces[idx] = null;
+ throw new RuntimeException(e);
+ }
+ }
+ return testTraces[idx];
+ }
+
+ // ------------------------------------------------------------------------
+ // Wrappers around direct CtfTestTraces methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get the (string) path to a given test trace.
+ *
+ * You should call {@link #tracesExist()} before calling this if you are
+ * going to use this trace for real.
+ *
+ * @param idx
+ * The index of the trace among all the available ones
+ * @return The path to the test trace
+ */
+ public static String getTestTracePath(int idx) {
+ return CtfTestTraces.getTestTracePath(idx);
+ }
+
+ /**
+ * Check if the test traces are present before trying to open them.
+ *
+ * This should be called in unit tests within a asssumeTrue() call, to skip
+ * the test/test-class if the traces are not available.
+ *
+ * @return True if the trace is available, false if not
+ */
+ public static boolean tracesExist() {
+ return CtfTestTraces.tracesExist();
+ }
+
+}
@Suite.SuiteClasses({
TmfCorePluginTest.class,
org.eclipse.linuxtools.tmf.core.tests.component.AllTests.class,
-// org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.AllTests.class, // Depends on the CTF traces
+ org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.AllTests.class,
org.eclipse.linuxtools.tmf.core.tests.event.AllTests.class,
org.eclipse.linuxtools.tmf.core.tests.request.AllTests.class,
org.eclipse.linuxtools.tmf.core.tests.statesystem.AllTests.class,
-// org.eclipse.linuxtools.tmf.core.tests.statistics.AllTests.class, // Depends on the CTF traces
+ org.eclipse.linuxtools.tmf.core.tests.statistics.AllTests.class,
org.eclipse.linuxtools.tmf.core.tests.trace.AllTests.class,
org.eclipse.linuxtools.tmf.core.tests.uml2sd.AllTests.class,
org.eclipse.linuxtools.tmf.core.tests.util.AllTests.class
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
*/
public class CtfIteratorTest {
+ private static final int TRACE_INDEX = 0;
+
private CtfIterator fixture;
/**
* Perform pre-test initialization.
- *
- * @throws TmfTraceException
- * If the test trace is not found
*/
@Before
- public void setUp() throws TmfTraceException {
- fixture = new CtfIterator(createTrace());
+ public void setUp() {
+ assumeTrue(CtfTmfTestTraces.tracesExist());
+ fixture = new CtfIterator(getTrace());
CtfLocation ctfLocation = new CtfLocation(new CtfLocationInfo(1, 0));
fixture.setLocation(ctfLocation);
fixture.increaseRank();
*/
@After
public void tearDown() {
- fixture.dispose();
+ if (fixture != null) {
+ fixture.dispose();
+ }
}
-
- private static CtfTmfTrace createTrace() throws TmfTraceException {
- return TestParams.createTrace();
+ private static CtfTmfTrace getTrace() {
+ return CtfTmfTestTraces.getTestTrace(TRACE_INDEX);
}
/**
* Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
- *
- * @throws TmfTraceException
- * If the test trace is not found
*/
@Test
- public void testCtfIterator_noinit() throws TmfTraceException {
- CtfTmfTrace trace = createTrace();
+ public void testCtfIterator_noinit() {
+ CtfTmfTrace trace = getTrace();
CtfIterator result = new CtfIterator(trace);
assertNotNull(result);
}
/**
* Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
- *
- * @throws TmfTraceException
- * If the test trace is not found
*/
@Test
- public void testCtfIterator_init() throws TmfTraceException {
- CtfTmfTrace trace = createTrace();
+ public void testCtfIterator_init() {
+ CtfTmfTrace trace = getTrace();
trace.init("test"); //$NON-NLS-1$
CtfIterator result = new CtfIterator(trace);
/**
* Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
* specifies an initial position for the iterator.
- *
- * @throws TmfTraceException
- * If the test trace is not found
*/
@Test
- public void testCtfIterator_position() throws TmfTraceException {
- CtfTmfTrace trace = createTrace();
+ public void testCtfIterator_position() {
+ CtfTmfTrace trace = getTrace();
long timestampValue = 1L;
long rank = 1L;
CtfIterator result = new CtfIterator(trace, new CtfLocationInfo(timestampValue, 0), rank);
/**
* Run the int compareTo(CtfIterator) method test.
- *
- * @throws TmfTraceException
- * If the test trace is not found
*/
@Test
- public void testCompareTo() throws TmfTraceException {
- CtfIterator o = new CtfIterator(createTrace());
+ public void testCompareTo() {
+ CtfIterator o = new CtfIterator(getTrace());
int result = fixture.compareTo(o);
assertEquals(1L, result);
/**
* Run the boolean equals(Object) method test. Compare with another iterator
* on the same trace.
- *
- * @throws TmfTraceException
- * If the test trace is not found
*/
@Test
- public void testEquals_other() throws TmfTraceException {
- CtfIterator obj = new CtfIterator(createTrace());
+ public void testEquals_other() {
+ CtfIterator obj = new CtfIterator(getTrace());
CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
obj.setLocation(ctfLocation1);
obj.increaseRank();
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
import java.util.ArrayList;
import org.eclipse.core.resources.IResource;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfContext;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
import org.junit.Before;
import org.junit.Test;
*/
public class CtfTmfContextTest {
- private static final String PATH = TestParams.getPath();
+ private static final int TRACE_INDEX = 0;
private static final long begin = 1332170682440133097L; /* Trace start time */
private static final long end = 1332170692664579801L; /* Trace end time */
*/
@Before
public void setUp() throws TmfTraceException {
+ assumeTrue(CtfTmfTestTraces.tracesExist());
trace = new CtfTmfTrace();
- trace.initTrace((IResource) null, PATH, CtfTmfEvent.class);
+ String path = CtfTmfTestTraces.getTestTracePath(TRACE_INDEX);
+ trace.initTrace((IResource) null, path, CtfTmfEvent.class);
}
/**
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assume.assumeTrue;
import java.util.Set;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.junit.Before;
import org.junit.BeforeClass;
*/
public class CtfTmfEventTest {
+ private static final int TRACE_INDEX = 0;
+
private static CtfTmfEvent nullEvent;
private CtfTmfEvent fixture;
/**
* Perform pre-test initialization.
- *
- * @throws TmfTraceException
- * If the test trace is not found
*/
@Before
- public void setUp() throws TmfTraceException {
- CtfTmfTrace trace = TestParams.createTrace();
+ public void setUp() {
+ assumeTrue(CtfTmfTestTraces.tracesExist());
+ CtfTmfTrace trace = CtfTmfTestTraces.getTestTrace(TRACE_INDEX);
CtfIterator tr = new CtfIterator(trace);
tr.advance();
fixture = tr.getCurrentEvent();
String reference = fixture.getReference();
String source = fixture.getSource();
ITmfEventType type = fixture.getType();
- assertEquals(rank, ITmfContext.UNKNOWN_RANK);
- assertEquals(trace.getName(), "test"); //$NON-NLS-1$
- assertEquals(reference,"channel0_1"); //$NON-NLS-1$
- assertEquals(source, "1"); //$NON-NLS-1$
- assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
+ assertEquals(ITmfContext.UNKNOWN_RANK, rank);
+ assertEquals("test", trace.getName()); //$NON-NLS-1$
+ assertEquals("channel0_1", reference); //$NON-NLS-1$
+ assertEquals("1", source); //$NON-NLS-1$
+ assertEquals("lttng_statedump_vm_map", type.toString()); //$NON-NLS-1$
}
/**
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.junit.After;
import org.junit.Before;
*/
public class CtfTmfTraceTest {
- private static final String PATH = TestParams.getPath();
+ private static final int TRACE_INDEX = 0;
+ private static final String PATH = CtfTmfTestTraces.getTestTracePath(TRACE_INDEX);
private CtfTmfTrace fixture;
*/
@Before
public void setUp() throws TmfTraceException {
+ assumeTrue(CtfTmfTestTraces.tracesExist());
fixture = new CtfTmfTrace();
fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class);
}
*/
@After
public void tearDown() {
- fixture.dispose();
+ if (fixture != null) {
+ fixture.dispose();
+ }
}
/**
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012 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
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
-
-import java.io.File;
-
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-
-/**
- * This is the set up for the trace files to be used with the ctfAdaptor tests.
- */
-abstract class TestParams {
-
- /* Path to test traces */
- private static final String testTracePath1 = "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel"; //$NON-NLS-1$
- private static CtfTmfTrace testTrace1 = null;
-
- private static final File emptyFile = new File(""); //$NON-NLS-1$
- private static CtfTmfTrace emptyTrace = new CtfTmfTrace();
-
- public static File getEmptyFile() {
- return emptyFile;
- }
-
- public static CtfTmfTrace getEmptyTrace() {
- return emptyTrace;
- }
-
- public static String getPath(){
- return testTracePath1;
- }
-
- public synchronized static CtfTmfTrace createTrace() throws TmfTraceException {
- if (testTrace1 == null) {
- testTrace1 = new CtfTmfTrace();
- testTrace1.initTrace(null, testTracePath1, CtfTmfEvent.class);
- }
- return testTrace1;
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2012 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
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.statistics;
-
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-
-/**
- * This is the set up for the trace files to be used with the TmfStatistics
- * tests.
- */
-abstract class TestParams {
-
- /* Path to test traces */
- private static final String testTracePath1 = "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel"; //$NON-NLS-1$
- private static CtfTmfTrace testTrace1 = null;
-
- public synchronized static CtfTmfTrace createTrace() throws TmfTraceException {
- if (testTrace1 == null) {
- testTrace1 = new CtfTmfTrace();
- testTrace1.initTrace(null, testTracePath1, CtfTmfEvent.class);
- }
- return testTrace1;
- }
-}
package org.eclipse.linuxtools.tmf.core.tests.statistics;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import static org.junit.Assume.assumeTrue;
+
import org.eclipse.linuxtools.tmf.core.statistics.TmfEventsStatistics;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
import org.junit.BeforeClass;
/**
*/
@BeforeClass
public static void setUpClass() {
- try {
- backend = new TmfEventsStatistics(TestParams.createTrace());
- } catch (TmfTraceException e) {
- e.printStackTrace();
- }
+ assumeTrue(CtfTmfTestTraces.tracesExist());
+ backend = new TmfEventsStatistics(CtfTmfTestTraces.getTestTrace(TRACE_INDEX));
}
}
package org.eclipse.linuxtools.tmf.core.tests.statistics;
+import static org.junit.Assume.assumeTrue;
+
import java.io.File;
import java.io.IOException;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
+import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
import org.junit.BeforeClass;
/**
*/
@BeforeClass
public static void setUpClass() {
+ assumeTrue(CtfTmfTestTraces.tracesExist());
try {
File htFile = File.createTempFile("stats-test", ".ht"); //$NON-NLS-1$ //$NON-NLS-2$
htFile.deleteOnExit();
- backend = new TmfStateStatistics(TestParams.createTrace(), htFile);
+ CtfTmfTrace trace = CtfTmfTestTraces.getTestTrace(TRACE_INDEX);
+ backend = new TmfStateStatistics(trace, htFile);
} catch (TmfTraceException e) {
e.printStackTrace();
} catch (IOException e) {
*/
public abstract class TmfStatisticsTest {
+ /** The index of the test trace used for these tests */
+ protected static final int TRACE_INDEX = 0;
+
/** The statistics back-end object */
protected static ITmfStatistics backend;