Integrate Babeltrace CTF tests and fix parsing problems
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / CTFTraceTest.java
index 3eb133da5cc2969f0a917671b20855456ed5aa8c..fcf44a48dbaab2553a48a7e218b66ca84eb11eeb 100644 (file)
@@ -7,6 +7,7 @@
  *
  * Contributors:
  *     Matthew Khouzam - Initial API and implementation
+ *     Marc-Andre Laperle - Test in traces directory recursively
  *******************************************************************************/
 
 package org.eclipse.linuxtools.ctf.core.tests.trace;
@@ -43,8 +44,15 @@ import org.junit.Test;
  */
 public class CTFTraceTest {
 
+    private static final String TRACES_DIRECTORY = "../org.eclipse.linuxtools.ctf.core.tests/traces";
+
+    private static final String METADATA_FILENAME = "metadata";
+
     private static final int TRACE_INDEX = 0;
 
+    private static final String CTF_VERSION_NUMBER = "1.8";
+    private static final String CTF_SUITE_TEST_DIRECTORY = "ctf-testsuite/tests/" + CTF_VERSION_NUMBER;
+
     private CTFTrace fixture;
 
     /**
@@ -379,4 +387,68 @@ public class CTFTraceTest {
         assertNotNull(result);
     }
 
+    /**
+     * Open traces in specified directories and expect them to fail
+     *
+     * @throws CTFReaderException not expected
+     */
+    @Test
+    public void testFailedParse() throws CTFReaderException {
+        parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY + "/fail"), true);
+    }
+
+    /**
+     * Open traces in specified directories and expect them to succeed
+     *
+     * @throws CTFReaderException not expected
+     */
+    @Test
+    public void testSuccessfulParse() throws CTFReaderException {
+        parseTracesInDirectory(getTestTracesSubDirectory("kernel"), false);
+        parseTracesInDirectory(getTestTracesSubDirectory("trace2"), false);
+        parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY + "/pass"), false);
+    }
+
+    /**
+     * Get the File object for the subDir in the traces directory. If the sub directory doesn't exist, the test is skipped.
+     */
+    private static File getTestTracesSubDirectory(String subDir) {
+        File file = new File(TRACES_DIRECTORY + "/" + subDir);
+        assumeTrue(file.isDirectory());
+        return file;
+    }
+
+    /**
+     * Parse the traces in given directory recursively
+     *
+     * @param directory The directory to search in
+     * @param expectException Whether or not traces in this directory are expected to throw an exception when parsed
+     * @throws CTFReaderException
+     */
+    void parseTracesInDirectory(File directory, boolean expectException) throws CTFReaderException {
+        for (File file : directory.listFiles()) {
+            if (file.getName().equals(METADATA_FILENAME)) {
+                try {
+                    new CTFTrace(directory);
+                    if (expectException) {
+                        fail("Trace was expected to fail parsing: " + directory);
+                    }
+                } catch (RuntimeException e) {
+                    if (!expectException) {
+                        throw new CTFReaderException("Failed parsing " + directory, e);
+                    }
+                } catch (CTFReaderException e) {
+                    if (!expectException) {
+                        throw new CTFReaderException("Failed parsing " + directory, e);
+                    }
+                }
+                return;
+            }
+
+            if (file.isDirectory()) {
+                parseTracesInDirectory(file, expectException);
+            }
+        }
+    }
+
 }
This page took 0.025043 seconds and 5 git commands to generate.