1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.ctftestsuite
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.fail
;
18 import java
.io
.IOException
;
19 import java
.nio
.file
.DirectoryStream
;
20 import java
.nio
.file
.Files
;
21 import java
.nio
.file
.Path
;
22 import java
.nio
.file
.Paths
;
23 import java
.util
.LinkedList
;
24 import java
.util
.List
;
26 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
27 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
28 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTraceReader
;
29 import org
.junit
.Rule
;
30 import org
.junit
.Test
;
31 import org
.junit
.rules
.TestRule
;
32 import org
.junit
.rules
.Timeout
;
33 import org
.junit
.runner
.RunWith
;
34 import org
.junit
.runners
.Parameterized
;
35 import org
.junit
.runners
.Parameterized
.Parameters
;
38 * Parameterized test class running the CTF Test Suite
40 * (from https://github.com/efficios/ctf-testsuite).
42 * @author Alexandre Montplaisir
44 @RunWith(Parameterized
.class)
45 public class CtfTestSuiteTests
{
47 /** Time-out tests after 10 seconds. */
49 public TestRule globalTimeout
= new Timeout(10000);
51 private static final Path BASE_PATH
= Paths
.get("traces", "ctf-testsuite", "tests", "1.8");
54 * Test we know are currently failing. Ignore them so we can at least run
57 * TODO Actually fix them!
59 private static final Path
[] IGNORED_TESTS
= {
60 BASE_PATH
.resolve(Paths
.get("regression", "metadata", "pass", "sequence-typedef-length")),
61 BASE_PATH
.resolve(Paths
.get("regression", "metadata", "pass", "array-of-struct")),
62 BASE_PATH
.resolve(Paths
.get("regression", "stream", "pass", "integer-large-size")),
63 BASE_PATH
.resolve(Paths
.get("regression", "metadata", "fail", "metadata-packetized-endianness-mismatch"))
66 private final String fTracePath
;
67 private final boolean fExpectSuccess
;
69 // ------------------------------------------------------------------------
70 // Methods for the Parametrized runner
71 // ------------------------------------------------------------------------
74 * Get the existing trace paths in the CTF-Testsuite git tree.
76 * @return The list of CTF traces (directories) to test
78 @Parameters(name
= "{index}: {0}")
79 public static Iterable
<Object
[]> getTracePaths() {
80 final List
<Object
[]> dirs
= new LinkedList
<>();
82 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("fuzzing", "metadata", "fail")), false);
83 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("fuzzing", "metadata", "pass")), true);
84 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("fuzzing", "stream", "fail")), false);
85 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("fuzzing", "stream", "pass")), true);
87 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("regression", "metadata", "fail")), false);
88 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("regression", "metadata", "pass")), true);
89 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("regression", "stream", "fail")), false);
90 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("regression", "stream", "pass")), true);
92 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("stress", "metadata", "fail")), false);
93 addDirsOneLevelDeepFrom(dirs
, BASE_PATH
.resolve(Paths
.get("stress", "metadata", "pass")), true);
94 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("stress", "stream", "fail")), false);
95 addDirsOneLevelDeepFrom(dirs
, BASE_PATH
.resolve(Paths
.get("stress", "stream", "pass")), true);
100 private static void addDirsFrom(List
<Object
[]> dirs
, Path path
, boolean expectSuccess
) {
101 if (!Files
.exists(path
)) {
102 /* Some planned directories may not exist yet in the test suite */
105 try (DirectoryStream
<Path
> ds
= Files
.newDirectoryStream(path
, DIR_FILTER
);) {
107 /* Add this test case to the list of tests to run */
108 Object array
[] = new Object
[] { p
.toString(), expectSuccess
};
111 } catch (IOException e
) {
112 /* Something is wrong with the layout of the test suite? */
118 * Some test traces are not in pass/trace1, pass/trace2, etc. but rather
119 * pass/test1/trace1, pass/test1/trace2, etc.
121 * This methods adds the directories one level "down" instead of the very
124 private static void addDirsOneLevelDeepFrom(List
<Object
[]> dirs
, Path path
,
125 boolean expectSuccess
) {
126 if (!Files
.exists(path
)) {
129 try (DirectoryStream
<Path
> ds
= Files
.newDirectoryStream(path
, DIR_FILTER
);) {
131 addDirsFrom(dirs
, p
, expectSuccess
);
133 } catch (IOException e
) {
138 private static final DirectoryStream
.Filter
<Path
> DIR_FILTER
=
139 new DirectoryStream
.Filter
<Path
>() {
141 public boolean accept(Path entry
) {
142 /* Only accept directories and non-blacklisted tests */
143 if (!Files
.isDirectory(entry
)) {
146 for (Path ignoredTestPath
: IGNORED_TESTS
) {
147 if (entry
.equals(ignoredTestPath
)) {
148 System
.err
.println("Skipping test " + entry
.toString() + " as requested.");
156 // ------------------------------------------------------------------------
158 // ------------------------------------------------------------------------
161 * Constructor for the parametrized tests
164 * The complete path to the trace to test
165 * @param expectSuccess
166 * Should this trace parse successfully, or not.
168 public CtfTestSuiteTests(String tracePath
, boolean expectSuccess
) {
169 fTracePath
= tracePath
;
170 fExpectSuccess
= expectSuccess
;
173 // ------------------------------------------------------------------------
175 // ------------------------------------------------------------------------
178 * Test opening and reading the trace
181 public void testTrace() {
183 /* Instantiate the trace (which implies parsing the metadata) */
184 CTFTrace trace
= new CTFTrace(fTracePath
);
185 /* Read the trace until the end */
186 try (CTFTraceReader reader
= new CTFTraceReader(trace
);) {
188 reader
.getCurrentEventDef();
189 while (reader
.advance()) {
190 assertNotNull(reader
.getCurrentEventDef());
193 checkIfWeShoudlSucceed();
195 } catch (CTFException e
) {
196 checkIfWeShouldFail(e
);
197 } catch (OutOfMemoryError e
) {
198 checkIfWeShouldFail(e
);
202 private void checkIfWeShoudlSucceed() {
203 if (!fExpectSuccess
) {
204 fail("Trace was expected to fail parsing: " + fTracePath
);
208 private void checkIfWeShouldFail(Throwable e
) {
209 if (fExpectSuccess
) {
210 fail("Trace was expected to succeed, but failed parsing: " +
211 fTracePath
+ " (" + e
.getMessage() + ")");
This page took 0.052448 seconds and 5 git commands to generate.