ctf: Re-enable the CTF parser unit tests
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 12 Feb 2013 22:46:11 +0000 (17:46 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 13 Feb 2013 19:13:34 +0000 (14:13 -0500)
but skip them, via assumeTrue(), if the test traces cannot be
found.

Right now Eclipse would show skipped tests as "passed" (see
bug 359944), but Maven should report skipped tests correctly.

Change-Id: Ia3a3451d5b5e5999afcbf9dea416ce0e45c9c9ad
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/10329
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>
Tested-by: Bernd Hufmann <bhufmann@gmail.com>
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/AllCtfCoreTests.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/TestParams.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceCallsitePerformanceTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EventDeclarationTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDeclarationTest.java

index 2ce65a2810e05b782ccc86edee97cf47db73ca3b..7217a264f2049982c8007151d46b345fe4756e3b 100644 (file)
@@ -14,11 +14,10 @@ import org.junit.runners.Suite;
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
     CtfCorePluginTest.class,
-    /* All the tests below depend on the CTF tests traces */
-//    org.eclipse.linuxtools.ctf.core.tests.event.TestAll.class,
-//    org.eclipse.linuxtools.ctf.core.tests.io.TestAll.class,
-//    org.eclipse.linuxtools.ctf.core.tests.trace.TestAll.class,
-//    org.eclipse.linuxtools.ctf.core.tests.types.TestAll.class
+    org.eclipse.linuxtools.ctf.core.tests.event.TestAll.class,
+    org.eclipse.linuxtools.ctf.core.tests.io.TestAll.class,
+    org.eclipse.linuxtools.ctf.core.tests.trace.TestAll.class,
+    org.eclipse.linuxtools.ctf.core.tests.types.TestAll.class
 })
 public class AllCtfCoreTests {
 
index bdf39f92412bb8cc324ac5a546e242c9a2518655..167796a4810f6ed5d48c0d4f7402bc3647635c96 100644 (file)
@@ -9,42 +9,68 @@ import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
  * Here are the definitions common to all the CTF parser tests.
  *
  * @author alexmont
- *
  */
-@SuppressWarnings("javadoc")
+@SuppressWarnings("nls")
 public abstract class TestParams {
 
     /*
      * Path to test traces. Make sure you run the traces/get-traces.sh script
      * first!
      */
-    private static final String testTracePath1 = "traces/kernel"; //$NON-NLS-1$
+    private static final String testTracePath1 = "traces/kernel";
     private static CTFTrace testTrace1 = null;
     private static CTFTrace testTraceFromFile1 = null;
-    private static final File testTraceFile1 = new File(testTracePath1+"/channel0_0"); //$NON-NLS-1$
+    private static final File testTraceFile1 = new File(testTracePath1 + "/channel0_0");
 
-    private static final File emptyFile = new File(""); //$NON-NLS-1$
+    private static final File emptyFile = new File("");
     private static CTFTrace emptyTrace = null;
 
+    /**
+     * Return an empty file (new File("");)
+     *
+     * @return An empty file
+     */
     public static File getEmptyFile() {
         return emptyFile;
     }
 
+    /**
+     * Return a file in test trace #1 (channel0_0).
+     *
+     * Make sure {@link #tracesExist()} before calling this!
+     *
+     * @return A file in a test trace
+     */
     public static File getTraceFile(){
         return testTraceFile1;
     }
+
+    /**
+     * Return a trace out of an empty file (new CTFTrace("");)
+     *
+     * @return An empty trace
+     */
     public static CTFTrace getEmptyTrace() {
         if (emptyTrace == null) {
             try {
-                emptyTrace = new CTFTrace(""); //$NON-NLS-1$
+                emptyTrace = new CTFTrace("");
             } catch (CTFReaderException e) {
-                /* We know this trace should exist */
+                /* Should always work... */
                 throw new RuntimeException(e);
             }
         }
         return emptyTrace;
     }
 
+    /**
+     * Get a CTFTrace reference to test trace #1.
+     *
+     * Make sure {@link #tracesExist()} before calling this!
+     *
+     * @return Reference to test trace #1
+     * @throws CTFReaderException
+     *             If the trace cannot be found
+     */
     public static CTFTrace createTrace() throws CTFReaderException {
         if (testTrace1 == null) {
             testTrace1 = new CTFTrace(testTracePath1);
@@ -52,15 +78,41 @@ public abstract class TestParams {
         return testTrace1;
     }
 
+    /**
+     * Same as {@link #createTrace()}, except the CTFTrace is create from the
+     * File object and not the path.
+     *
+     * Make sure {@link #tracesExist()} before calling this!
+     *
+     * @return Reference to test trace #1
+     */
     public static CTFTrace createTraceFromFile() {
         if (testTraceFromFile1 == null) {
             try {
                 testTraceFromFile1 = new CTFTrace(new File(testTracePath1));
             } catch (CTFReaderException e) {
-                /* We know this trace should exist */
+                /* This trace should exist */
                 throw new RuntimeException(e);
             }
         }
         return testTraceFromFile1;
     }
+
+    /**
+     * Check if the test traces are present in the tree. If not, you can get
+     * them by running traces/get-traces.sh or traces/get-traces.xml
+     *
+     * @return True if *all* the test files could be found, false otherwise.
+     */
+    public static boolean tracesExist() {
+        if (testTrace1 != null) {
+            return true;
+        }
+        try {
+            createTrace();
+        } catch (CTFReaderException e) {
+            return false;
+        }
+        return true;
+    }
 }
index 49927a3639d61356499b83373a7f590d414d8103..ec33dd4fb7bd57c5125400f5b5ef59bce126ebf4 100644 (file)
@@ -2,6 +2,7 @@ package org.eclipse.linuxtools.ctf.core.tests.trace;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
 
 import java.util.List;
 import java.util.Random;
@@ -64,6 +65,7 @@ public class CTFTraceCallsitePerformanceTest {
     @Before
     public void setup() throws CTFReaderException, SecurityException,
             IllegalArgumentException {
+        assumeTrue(TestParams.tracesExist());
         fTrace = new CTFTrace(TestParams.getTraceFile().getParentFile());
     }
 
index f78bb027019efd64c0d3457c58b5a8dd5edb330e..49c57d1f359684e755fca4e034436c67b691e6e2 100644 (file)
@@ -4,6 +4,7 @@ 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.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
@@ -43,6 +44,7 @@ public class CTFTraceReaderTest {
      */
     @Before
     public void setUp() throws CTFReaderException {
+        assumeTrue(TestParams.tracesExist());
         fixture = new CTFTraceReader(TestParams.createTrace());
     }
 
index 72ddeca81534f9597932d8703f12f2e525a010d2..5aaffbbf46a976129094e16c8441711204fa898e 100644 (file)
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertFalse;
 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 java.io.File;
 import java.nio.ByteOrder;
@@ -50,6 +51,7 @@ public class CTFTraceTest {
      */
     @Before
     public void setUp() {
+        assumeTrue(TestParams.tracesExist());
         fixture = TestParams.createTraceFromFile();
         fixture.setMinor(1L);
         fixture.setUUID(UUID.randomUUID());
index b939ca04c8225b93ff4b4a47b73b94ab46dbc587..dee91f0bc1799c4423a4085fe4fb01398b949b41 100644 (file)
@@ -2,6 +2,7 @@ package org.eclipse.linuxtools.ctf.core.tests.trace;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assume.assumeTrue;
 
 import java.nio.ByteOrder;
 
@@ -41,6 +42,7 @@ public class MetadataTest {
      */
     @Before
     public void setUp() throws CTFReaderException {
+        assumeTrue(TestParams.tracesExist());
         fixture = new Metadata(TestParams.createTrace());
     }
 
index d906f52870388b4b9285c2d11c089db525697f76..9e2f30888fe34afc1064d6002c2c2471125f2db9 100644 (file)
@@ -3,6 +3,7 @@ package org.eclipse.linuxtools.ctf.core.tests.trace;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
 
 import java.nio.channels.FileChannel;
 import java.util.Set;
@@ -64,6 +65,7 @@ public class StreamInputReaderTest {
     }
 
     private static StreamInputReader getStreamInputReader() throws CTFReaderException {
+        assumeTrue(TestParams.tracesExist());
         CTFTrace trace = TestParams.createTrace();
         Stream s = trace.getStream((long) 0);
         Set<StreamInput> streamInput = s.getStreamInputs();
index 9a1e75ab641d9b0f8fc5cb05712c7812f72b5578..08604286996358054f738349b44c1b7bb5b280d2 100644 (file)
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertFalse;
 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 java.io.File;
 import java.io.IOException;
@@ -48,6 +49,7 @@ public class StreamInputTest {
      */
     @Before
     public void setUp() throws CTFReaderException {
+        assumeTrue(TestParams.tracesExist());
         fixture = new StreamInput(new Stream(TestParams.createTrace()),
                 (FileChannel) null, createFile());
         fixture.setTimestampEnd(1L);
index 9dcf010855bd93089a56cd20fc68ff8ca54ad2aa..802c9953e0cdb31bc8a7b440eb4f5a9533e0f0c2 100644 (file)
@@ -2,6 +2,7 @@ package org.eclipse.linuxtools.ctf.core.tests.trace;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
 
 import java.nio.channels.FileChannel;
 import java.util.HashMap;
@@ -49,6 +50,7 @@ public class StreamTest {
      */
     @Before
     public void setUp() throws CTFReaderException {
+        assumeTrue(TestParams.tracesExist());
         fixture = new Stream(TestParams.createTrace());
         fixture.setEventContext(new StructDeclaration(1L));
         fixture.setPacketContext(new StructDeclaration(1L));
index 3b680003842759a7dfdadcfe393f6296a0d2e4d1..ed8f70ee15b4a0e80821f9d174fe6b0d2b40fa87 100644 (file)
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertFalse;
 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.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
@@ -47,6 +48,7 @@ public class EventDeclarationTest {
      */
     @Before
     public void setUp() throws CTFReaderException {
+        assumeTrue(TestParams.tracesExist());
         fixture = new EventDeclaration();
         fixture.setContext(new StructDeclaration(1L));
         fixture.setId(1L);
index 6ce0d4df3be9be04a8f94f6ad5f16979bc448e00..7d937cc3531bbd1ecdcfa002eebc95f02a4c36f1 100644 (file)
@@ -2,6 +2,7 @@ package org.eclipse.linuxtools.ctf.core.tests.types;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assume.assumeTrue;
 
 import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
@@ -93,6 +94,7 @@ public class VariantDeclarationTest {
     }
 
     private static IDefinitionScope createDefinitionScope() throws CTFReaderException {
+        assumeTrue(TestParams.tracesExist());
         VariantDeclaration declaration = new VariantDeclaration();
         declaration.setTag(""); //$NON-NLS-1$
         VariantDeclaration variantDeclaration = new VariantDeclaration();
This page took 0.030286 seconds and 5 git commands to generate.