ctf: Update paths in the CTF-Testsuite tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / ctftestsuite / CtfTestSuiteTests.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.ctf.core.tests.ctftestsuite;
14
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.fail;
17
18 import java.io.File;
19 import java.util.LinkedList;
20 import java.util.List;
21
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;
32
33 /**
34 * Parametrized test class running the CTF Test Suite
35 * (from https://github.com/efficios/ctf-testsuite).
36 *
37 * @author Alexandre Montplaisir
38 */
39 @RunWith(Parameterized.class)
40 public class CtfTestSuiteTests {
41
42 /** Time-out tests after 10 seconds. */
43 @Rule
44 public TestRule globalTimeout= new Timeout(10000);
45
46 private static final String basePath = "traces/ctf-testsuite/tests/1.8/";
47
48 private final String fTracePath;
49 private final boolean fExpectSuccess;
50
51 // ------------------------------------------------------------------------
52 // Methods for the Parametrized runner
53 // ------------------------------------------------------------------------
54
55 /**
56 * Get the existing trace paths in the CTF-Testsuite git tree.
57 *
58 * @return The list of CTF traces (directories) to test
59 */
60 @Parameters(name = "{index}: {0}")
61 public static Iterable<Object[]> getTracePaths() {
62 final List<Object[]> dirs = new LinkedList<Object[]>();
63
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);
68
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);
73
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);
78
79 return dirs;
80 }
81
82 private static void addDirsFrom(List<Object[]> dirs, String path, boolean expectSuccess) {
83 File[] traceDirs = (new File(path)).listFiles();
84 if (traceDirs == null) {
85 return;
86 }
87 for (File traceDir : traceDirs) {
88 Object array[] = new Object[] { traceDir.getPath(), expectSuccess };
89 dirs.add(array);
90 }
91 }
92
93 // ------------------------------------------------------------------------
94 // Test constructor
95 // ------------------------------------------------------------------------
96
97 /**
98 * Constructor for the parametrized tests
99 *
100 * @param tracePath
101 * The complete path to the trace to test
102 * @param expectSuccess
103 * Should this trace parse successfully, or not.
104 */
105 public CtfTestSuiteTests(String tracePath, boolean expectSuccess) {
106 fTracePath = tracePath;
107 fExpectSuccess = expectSuccess;
108 }
109
110 // ------------------------------------------------------------------------
111 // Test methods
112 // ------------------------------------------------------------------------
113
114 /**
115 * Test opening and reading the trace
116 */
117 @Test
118 public void testTrace() {
119 CTFTrace trace = null;
120 CTFTraceReader reader = null;
121 try {
122 /* Instantiate the trace object (which implies parsing the metadata) */
123 trace = new CTFTrace(fTracePath);
124
125 /* Read the trace until the end */
126 reader = new CTFTraceReader(trace);
127 reader.getCurrentEventDef();
128 while (reader.advance()) {
129 assertNotNull(reader.getCurrentEventDef());
130 }
131
132 if (!fExpectSuccess) {
133 fail("Trace was expected to fail parsing: " + fTracePath);
134 }
135 } catch (CTFReaderException e) {
136 if (fExpectSuccess) {
137 fail("Trace was expected to succeed, but failed parsing: " + fTracePath);
138 }
139 } finally {
140 if (reader != null) {
141 reader.dispose();
142 }
143 if (trace != null) {
144 trace.dispose();
145 }
146
147 }
148 }
149 }
This page took 0.034485 seconds and 5 git commands to generate.