1 /*******************************************************************************
2 * Copyright (c) 2013 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 * Parametrized test class running the CTF Test Suite
35 * (from https://github.com/efficios/ctf-testsuite).
37 * @author Alexandre Montplaisir
39 @RunWith(Parameterized
.class)
40 public class CtfTestSuiteTests
{
42 /** Time-out tests after 10 seconds. */
44 public TestRule globalTimeout
= new Timeout(10000);
46 private static final String basePath
= "traces/ctf-testsuite/tests/1.8/";
48 private final String fTracePath
;
49 private final boolean fExpectSuccess
;
51 // ------------------------------------------------------------------------
52 // Methods for the Parametrized runner
53 // ------------------------------------------------------------------------
56 * Get the existing trace paths in the CTF-Testsuite git tree.
58 * @return The list of CTF traces (directories) to test
60 @Parameters(name
= "{index}: {0}")
61 public static Iterable
<Object
[]> getTracePaths() {
62 final List
<Object
[]> dirs
= new LinkedList
<Object
[]>();
64 addDirsFrom(dirs
, basePath
+ "fuzzing/metadata/fail", false);
65 addDirsFrom(dirs
, basePath
+ "fuzzing/metadata/pass", true);
66 addDirsFrom(dirs
, basePath
+ "fuzzing/stream/fail", false);
67 addDirsFrom(dirs
, basePath
+ "fuzzing/stream/pass", true);
69 addDirsFrom(dirs
, basePath
+ "regression/metadata/fail", false);
70 addDirsFrom(dirs
, basePath
+ "regression/metadata/pass", true);
71 addDirsFrom(dirs
, basePath
+ "regression/stream/fail", false);
72 addDirsFrom(dirs
, basePath
+ "regression/stream/pass", true);
74 addDirsFrom(dirs
, basePath
+ "stress/metadata/fail", false);
75 addDirsFrom(dirs
, basePath
+ "stress/metadata/pass", true);
76 addDirsFrom(dirs
, basePath
+ "stress/stream/fail", false);
77 addDirsFrom(dirs
, basePath
+ "stress/stream/pass", true);
82 private static void addDirsFrom(List
<Object
[]> dirs
, String path
, boolean expectSuccess
) {
83 File
[] traceDirs
= (new File(path
)).listFiles();
84 if (traceDirs
== null) {
87 for (File traceDir
: traceDirs
) {
88 Object array
[] = new Object
[] { traceDir
.getPath(), expectSuccess
};
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 * Constructor for the parametrized tests
101 * The complete path to the trace to test
102 * @param expectSuccess
103 * Should this trace parse successfully, or not.
105 public CtfTestSuiteTests(String tracePath
, boolean expectSuccess
) {
106 fTracePath
= tracePath
;
107 fExpectSuccess
= expectSuccess
;
110 // ------------------------------------------------------------------------
112 // ------------------------------------------------------------------------
115 * Test opening and reading the trace
118 public void testTrace() {
119 CTFTrace trace
= null;
120 CTFTraceReader reader
= null;
122 /* Instantiate the trace object (which implies parsing the metadata) */
123 trace
= new CTFTrace(fTracePath
);
125 /* Read the trace until the end */
126 reader
= new CTFTraceReader(trace
);
127 reader
.getCurrentEventDef();
128 while (reader
.advance()) {
129 assertNotNull(reader
.getCurrentEventDef());
132 if (!fExpectSuccess
) {
133 fail("Trace was expected to fail parsing: " + fTracePath
);
135 } catch (CTFReaderException e
) {
136 if (fExpectSuccess
) {
137 fail("Trace was expected to succeed, but failed parsing: " + fTracePath
);
140 if (reader
!= null) {
This page took 0.034485 seconds and 5 git commands to generate.