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
.linuxtools
.ctf
.core
.tests
.ctftestsuite
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.fail
;
19 import java
.util
.LinkedList
;
20 import java
.util
.List
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTraceReader
;
25 import org
.junit
.Rule
;
26 import org
.junit
.Test
;
27 import org
.junit
.rules
.TestRule
;
28 import org
.junit
.rules
.Timeout
;
29 import org
.junit
.runner
.RunWith
;
30 import org
.junit
.runners
.Parameterized
;
31 import org
.junit
.runners
.Parameterized
.Parameters
;
34 * Parameterized test class running the CTF Test Suite
36 * (from https://github.com/efficios/ctf-testsuite).
38 * @author Alexandre Montplaisir
40 @RunWith(Parameterized
.class)
41 public class CtfTestSuiteTests
{
43 /** Time-out tests after 10 seconds. */
45 public TestRule globalTimeout
= new Timeout(10000);
47 private static final String BASE_PATH
= "traces/ctf-testsuite/tests/1.8/";
50 * Test we know are currently failing. Ignore them so we can at least run
53 * TODO Actually fix them!
55 private static final String
[] IGNORED_TESTS
= {
56 "regression/metadata/pass/sequence-typedef-length",
57 "regression/metadata/pass/array-of-struct"
60 private final String fTracePath
;
61 private final boolean fExpectSuccess
;
63 // ------------------------------------------------------------------------
64 // Methods for the Parametrized runner
65 // ------------------------------------------------------------------------
68 * Get the existing trace paths in the CTF-Testsuite git tree.
70 * @return The list of CTF traces (directories) to test
72 @Parameters(name
= "{index}: {0}")
73 public static Iterable
<Object
[]> getTracePaths() {
74 final List
<Object
[]> dirs
= new LinkedList
<>();
76 addDirsFrom(dirs
, BASE_PATH
+ "fuzzing/metadata/fail", false);
77 addDirsFrom(dirs
, BASE_PATH
+ "fuzzing/metadata/pass", true);
78 addDirsFrom(dirs
, BASE_PATH
+ "fuzzing/stream/fail", false);
79 addDirsFrom(dirs
, BASE_PATH
+ "fuzzing/stream/pass", true);
81 addDirsFrom(dirs
, BASE_PATH
+ "regression/metadata/fail", false);
82 addDirsFrom(dirs
, BASE_PATH
+ "regression/metadata/pass", true);
83 addDirsFrom(dirs
, BASE_PATH
+ "regression/stream/fail", false);
84 addDirsFrom(dirs
, BASE_PATH
+ "regression/stream/pass", true);
86 addDirsFrom(dirs
, BASE_PATH
+ "stress/metadata/fail", false);
87 addDirsFrom(dirs
, BASE_PATH
+ "stress/metadata/pass", true);
88 addDirsFrom(dirs
, BASE_PATH
+ "stress/stream/fail", false);
89 addDirsFrom(dirs
, BASE_PATH
+ "stress/stream/pass", true);
94 private static void addDirsFrom(List
<Object
[]> dirs
, String path
, boolean expectSuccess
) {
95 File
[] traceDirs
= (new File(path
)).listFiles();
96 if (traceDirs
== null) {
99 for (File traceDir
: traceDirs
) {
100 /* Skip the "run.sh" files and blacklisted tests */
101 if (!traceDir
.isDirectory() || testIsBlacklisted(traceDir
.getPath())) {
105 /* Add this test case to the list of tests to run */
106 Object array
[] = new Object
[] { traceDir
.getPath(), expectSuccess
};
111 private static boolean testIsBlacklisted(String fullPath
) {
112 for (String ignoredTest
: IGNORED_TESTS
) {
113 if (fullPath
.contains(new File(ignoredTest
).getPath())) {
120 // ------------------------------------------------------------------------
122 // ------------------------------------------------------------------------
125 * Constructor for the parametrized tests
128 * The complete path to the trace to test
129 * @param expectSuccess
130 * Should this trace parse successfully, or not.
132 public CtfTestSuiteTests(String tracePath
, boolean expectSuccess
) {
133 fTracePath
= tracePath
;
134 fExpectSuccess
= expectSuccess
;
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
142 * Test opening and reading the trace
145 public void testTrace() {
146 try (/* Instantiate the trace (which implies parsing the metadata) */
147 CTFTrace trace
= new CTFTrace(fTracePath
);
148 /* Read the trace until the end */
149 CTFTraceReader reader
= new CTFTraceReader(trace
);) {
151 reader
.getCurrentEventDef();
152 while (reader
.advance()) {
153 assertNotNull(reader
.getCurrentEventDef());
156 checkIfWeShoudlSucceed();
157 } catch (CTFReaderException e
) {
158 checkIfWeShouldFail(e
);
159 } catch (OutOfMemoryError e
) {
160 checkIfWeShouldFail(e
);
164 private void checkIfWeShoudlSucceed() {
165 if (!fExpectSuccess
) {
166 fail("Trace was expected to fail parsing: " + fTracePath
);
170 private void checkIfWeShouldFail(Throwable e
) {
171 if (fExpectSuccess
) {
172 fail("Trace was expected to succeed, but failed parsing: " +
173 fTracePath
+ " (" + e
.getMessage() + ")");
This page took 0.047172 seconds and 5 git commands to generate.