From 5dd1fa65a4f173d4b91e7e4a4a3e52428382b8a5 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Wed, 13 Feb 2013 15:37:37 -0500 Subject: [PATCH] tmf: Re-enable the unit tests depending on CTF traces 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 Reviewed-on: https://git.eclipse.org/r/10354 Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann Tested-by: Hudson CI --- .../.classpath | 1 + .../META-INF/MANIFEST.MF | 6 +- .../build.properties | 1 + .../core/tests/shared/CtfTmfTestTraces.java | 112 ++++++++++++++++++ .../tmf/core/tests/AllTmfCoreTests.java | 4 +- .../tests/ctfadaptor/CtfIteratorTest.java | 57 ++++----- .../tests/ctfadaptor/CtfTmfContextTest.java | 10 +- .../tests/ctfadaptor/CtfTmfEventTest.java | 23 ++-- .../tests/ctfadaptor/CtfTmfTraceTest.java | 10 +- .../tmf/core/tests/ctfadaptor/TestParams.java | 52 -------- .../tmf/core/tests/statistics/TestParams.java | 36 ------ .../statistics/TmfEventsStatisticsTest.java | 11 +- .../statistics/TmfStateStatisticsTest.java | 8 +- .../tests/statistics/TmfStatisticsTest.java | 3 + 14 files changed, 184 insertions(+), 150 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTraces.java delete mode 100644 org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/TestParams.java delete mode 100644 org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TestParams.java diff --git a/org.eclipse.linuxtools.tmf.core.tests/.classpath b/org.eclipse.linuxtools.tmf.core.tests/.classpath index 2a987e2854..36ec9cee4a 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/.classpath +++ b/org.eclipse.linuxtools.tmf.core.tests/.classpath @@ -4,5 +4,6 @@ + diff --git a/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF index d5a373c233..3c3d300d32 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.core.tests/META-INF/MANIFEST.MF @@ -12,5 +12,7 @@ Require-Bundle: org.junit;bundle-version="4.0.0", 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" diff --git a/org.eclipse.linuxtools.tmf.core.tests/build.properties b/org.eclipse.linuxtools.tmf.core.tests/build.properties index 3bbef16a18..61f533e67f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/build.properties +++ b/org.eclipse.linuxtools.tmf.core.tests/build.properties @@ -1,4 +1,5 @@ source.. = stubs/,\ + shared/,\ src/ output.. = bin/ bin.includes = META-INF/,\ diff --git a/org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTraces.java b/org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTraces.java new file mode 100644 index 0000000000..d99ae7bae3 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core.tests/shared/org/eclipse/linuxtools/tmf/core/tests/shared/CtfTmfTestTraces.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * 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(); + } + +} diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/AllTmfCoreTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/AllTmfCoreTests.java index 8993a6aa4a..db2363f761 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/AllTmfCoreTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/AllTmfCoreTests.java @@ -23,11 +23,11 @@ import org.junit.runners.Suite; @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 diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java index cb35f29012..0c621c7248 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java @@ -17,13 +17,14 @@ import static org.junit.Assert.assertEquals; 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; @@ -37,17 +38,17 @@ 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(); @@ -58,36 +59,31 @@ public class CtfIteratorTest { */ @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); @@ -97,13 +93,10 @@ public class CtfIteratorTest { /** * 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); @@ -132,13 +125,10 @@ public class CtfIteratorTest { /** * 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); @@ -147,13 +137,10 @@ public class CtfIteratorTest { /** * 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(); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java index d95217398b..c75d733b81 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java @@ -16,14 +16,16 @@ package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor; 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; @@ -35,7 +37,7 @@ 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 */ @@ -57,8 +59,10 @@ public class CtfTmfContextTest { */ @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); } /** diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java index 0118247aaa..1e55fedaf1 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; 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; @@ -27,7 +28,7 @@ import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory; 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; @@ -42,6 +43,8 @@ import org.junit.Test; */ public class CtfTmfEventTest { + private static final int TRACE_INDEX = 0; + private static CtfTmfEvent nullEvent; private CtfTmfEvent fixture; @@ -55,13 +58,11 @@ public class CtfTmfEventTest { /** * 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(); @@ -152,11 +153,11 @@ public class CtfTmfEventTest { 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$ } /** diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java index b6ad8e77f1..5a179ff9cc 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java @@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals; 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; @@ -32,6 +33,7 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; 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; @@ -46,7 +48,8 @@ import org.junit.Test; */ 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; @@ -58,6 +61,7 @@ public class CtfTmfTraceTest { */ @Before public void setUp() throws TmfTraceException { + assumeTrue(CtfTmfTestTraces.tracesExist()); fixture = new CtfTmfTrace(); fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class); } @@ -67,7 +71,9 @@ public class CtfTmfTraceTest { */ @After public void tearDown() { - fixture.dispose(); + if (fixture != null) { + fixture.dispose(); + } } /** diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/TestParams.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/TestParams.java deleted file mode 100644 index c2bf932672..0000000000 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/TestParams.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * 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; - } -} diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TestParams.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TestParams.java deleted file mode 100644 index f8f6c5d303..0000000000 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TestParams.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * 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; - } -} diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfEventsStatisticsTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfEventsStatisticsTest.java index fc01970a71..0aebb5e51a 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfEventsStatisticsTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfEventsStatisticsTest.java @@ -12,8 +12,10 @@ 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; /** @@ -28,10 +30,7 @@ public class TmfEventsStatisticsTest extends TmfStatisticsTest { */ @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)); } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStateStatisticsTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStateStatisticsTest.java index 9c4df93013..1b3c104aaa 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStateStatisticsTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStateStatisticsTest.java @@ -12,11 +12,15 @@ 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; /** @@ -31,10 +35,12 @@ public class TmfStateStatisticsTest extends TmfStatisticsTest { */ @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) { diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java index 3c2d28aefb..b60a71caed 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java @@ -28,6 +28,9 @@ import org.junit.Test; */ 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; -- 2.34.1