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 - Moved out of CTFTestTrace
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.ctftestsuite
;
15 import static org
.junit
.Assert
.fail
;
16 import static org
.junit
.Assume
.assumeTrue
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
22 import org
.junit
.Test
;
25 * Test class running the CTF Test Suite
26 * (from https://github.com/efficios/ctf-testsuite).
28 * @author Matthew Khouzam
30 public class CtfTestSuiteTest
{
32 private static final String TRACES_DIRECTORY
= "../org.eclipse.linuxtools.ctf.core.tests/traces";
33 private static final String METADATA_FILENAME
= "metadata";
35 private static final String CTF_VERSION_NUMBER
= "1.8";
36 private static final String CTF_SUITE_TEST_DIRECTORY
= "ctf-testsuite/tests/" + CTF_VERSION_NUMBER
;
39 * Open traces in specified directories and expect them to fail
41 * @throws CTFReaderException not expected
44 public void testFailedParse() throws CTFReaderException
{
45 parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY
+ "/fail"), true);
49 * Open traces in specified directories and expect them to succeed
51 * @throws CTFReaderException not expected
54 public void testSuccessfulParse() throws CTFReaderException
{
55 parseTracesInDirectory(getTestTracesSubDirectory("kernel"), false);
56 parseTracesInDirectory(getTestTracesSubDirectory("trace2"), false);
57 parseTracesInDirectory(getTestTracesSubDirectory(CTF_SUITE_TEST_DIRECTORY
+ "/pass"), false);
62 * Get the File object for the subDir in the traces directory. If the sub directory doesn't exist, the test is skipped.
64 private static File
getTestTracesSubDirectory(String subDir
) {
65 File file
= new File(TRACES_DIRECTORY
+ "/" + subDir
);
66 assumeTrue(file
.isDirectory());
71 * Parse the traces in given directory recursively
73 * @param directory The directory to search in
74 * @param expectException Whether or not traces in this directory are expected to throw an exception when parsed
75 * @throws CTFReaderException
77 void parseTracesInDirectory(File directory
, boolean expectException
) throws CTFReaderException
{
78 for (File file
: directory
.listFiles()) {
79 if (file
.getName().equals(METADATA_FILENAME
)) {
81 new CTFTrace(directory
);
82 if (expectException
) {
83 fail("Trace was expected to fail parsing: " + directory
);
85 } catch (RuntimeException e
) {
86 if (!expectException
) {
87 throw new CTFReaderException("Failed parsing " + directory
, e
);
89 } catch (CTFReaderException e
) {
90 if (!expectException
) {
91 throw new CTFReaderException("Failed parsing " + directory
, e
);
97 if (file
.isDirectory()) {
98 parseTracesInDirectory(file
, expectException
);